Home » Developer & Programmer » Forms » how to insert data in two table same time? (database10g)
how to insert data in two table same time? [message #542106] Sat, 04 February 2012 08:53 Go to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
can anyone tell me how to insert data in two tables in same time

table1 --master table
table2 --transaction table


thanks

[Updated on: Sat, 04 February 2012 08:56]

Report message to a moderator

Re: how to insert data in two table same time? [message #542127 is a reply to message #542106] Sat, 04 February 2012 11:48 Go to previous messageGo to next message
Littlefoot
Messages: 21813
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
One option is to create a database trigger which will insert data into TABLE2 upon insertion into TABLE1.

Another one is to create an ON-INSERT form trigger which suppresses default Forms processing; in there, you'd INSERT INTO TABLE1 and INSERT INTO TABLE2.

Or, create form on a view and use INSTEAD OF database trigger which would do the same as previous suggestion (two INSERT INTO statements).

[Updated on: Sat, 04 February 2012 11:50]

Report message to a moderator

Re: how to insert data in two table same time? [message #542479 is a reply to message #542127] Tue, 07 February 2012 07:50 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
Thanks for reply sir can you tell me how to insert data in two tables in same time on command prompt

SQL>insert into table names values---------


THANKS
Re: how to insert data in two table same time? [message #542480 is a reply to message #542479] Tue, 07 February 2012 07:52 Go to previous messageGo to next message
Littlefoot
Messages: 21813
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
You can not, not directly (as I already told you).

Did you research what I said?

[Updated on: Tue, 07 February 2012 07:53]

Report message to a moderator

Re: how to insert data in two table same time? [message #542489 is a reply to message #542480] Tue, 07 February 2012 08:30 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
yes sir i studied actually i had a question in my mind which i wanted to ask from you thanks for helping me a lot actually sir i was trying to do something like this.

$qry = "INSERT INTO table (one, two, three) VALUES('$one','$two','$three')";


Thanks
Re: how to insert data in two table same time? [message #542527 is a reply to message #542489] Tue, 07 February 2012 13:43 Go to previous messageGo to next message
Littlefoot
Messages: 21813
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
I'm not familiar with this syntax. What is it? Looks like a dynamic SQL attempt, but I can't tell for sure. Where did you find it? Could you post a link?

And still, I didn't change my mind. Why do you insist on such an impossible thing? Oracle said that its INSERT statement inserts into one and ONLY ONE TABLE. Until Oracle says different, that's how it works and that's what you have.
Re: how to insert data in two table same time? [message #542536 is a reply to message #542527] Tue, 07 February 2012 17:11 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
Thanks Sir for your quick reply sir. I think this query belongs to MYSQL i dont know the exact link of this query i saw these things somewhere in website but i am sure this query belongs to mysql. actually i wanted to do exactly the same thing in sql or sqlplus anywaz thanks for your precious information. Sir i am really thankful to you and looking forward for the future answers from this forum or from LittleFoot kind of geniuses, Sir if i made a mistake somewhere while writing a english i am sorry for that because my mother tongue is not a english.

i have few things which is related to same query which i had downloaded from net as below.
--------------------------------------------------
$qry = "INSERT INTO table (one, two, three) VALUES('$one','$two','$three')";$result = @mysql_query($qry);$qry2 = "INSERT INTO table2 (one,two, three) VVALUES('$one','$two','$three')";$result = @mysql_query($qry2);

------------------------------------------------------------

Thanks & Best regards

[Updated on: Tue, 07 February 2012 17:13]

Report message to a moderator

Re: how to insert data in two table same time? [message #542561 is a reply to message #542536] Wed, 08 February 2012 01:37 Go to previous messageGo to next message
Littlefoot
Messages: 21813
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
I don't know MySQL, but code you posted doesn't seem to be what you are saying. These are 4 commands (separated by a semi-colon), written in the same line.

As far as I can tell, Oracle doesn't support it in SQL; here are a few examples:
SQL> create table mug (col1 number, col2 varchar2(5));

Table created.

SQL> insert into mug (col1, col2) values (1, 'Abc'); insert into mug (col1, col2) values (2, 'Bde');
insert into mug (col1, col2) values (1, 'Abc'); insert into mug (col1, col2) values (2, 'Bde')
                                              *
ERROR at line 1:
ORA-00911: invalid character


SQL> insert into mug (col1, col2) values (1, 'Abc')/ insert into mug (col1, col2) values (2, 'Bde')/
  2  /
insert into mug (col1, col2) values (1, 'Abc')/ insert into mug (col1, col2) values (2, 'Bde')/
                                              *
ERROR at line 1:
ORA-00933: SQL command not properly ended


SQL> insert into mug (col1, col2) values (1, 'Abc');/ insert into mug (col1, col2) values (2, 'Bde');/
  2  /
insert into mug (col1, col2) values (1, 'Abc');/ insert into mug (col1, col2) values (2, 'Bde');/
                                              *
ERROR at line 1:
ORA-00911: invalid character


SQL> drop table mug;

Table dropped.


On the other hand, you can put several statements into the same line in PL/SQL:
SQL> create table mug (col1 number, col2 varchar2(5));

Table created.

SQL> create table mug_2 (col1 number, col2 varchar2(5));

Table created.

SQL> begin
  2    insert into mug (col1, col2) values (1, 'Abc'); insert into mug_2 (col1, col2) values (2, 'Bde');
  3  end;
  4  /

PL/SQL procedure successfully completed.

SQL> select * from mug;

      COL1 COL2
---------- -----
         1 Abc

SQL> select * from mug_2;

      COL1 COL2
---------- -----
         2 Bde

SQL>


Obviously, this works and it inserted values into two different tables from the same line, but - as I said - it is NOT a single statement, these are TWO separate INSERT statements.
Re: how to insert data in two table same time? [message #542652 is a reply to message #542561] Wed, 08 February 2012 06:13 Go to previous messageGo to next message
x-oracle
Messages: 380
Registered: April 2011
Location: gujarat
Senior Member
if you want to multi insert into two table you can use this
here we have two table dept_test and dept

INSERT ALL
  INTO dept_test (no, name)
VALUES (1, 'parthiv')
  INTO dept_test (no, name)
VALUES (1, 'parthiv')
  INTO dept_test (no, name)
VALUES (1, 'parthiv')
  INTO dept
VALUES (10, 'abc', 'test')
   SELECT * FROM DUAL;


and if you want to multiple insert into one table you can use this syntax

INSERT ALL
  INTO dept_test (no, name)
VALUES (1, 'parthiv')
  INTO dept_test (no, name)
VALUES (1, 'parthiv')
  INTO dept_test (no, name)
VALUES (1, 'parthiv')
   SELECT * FROM DUAL;

[Updated on: Wed, 08 February 2012 06:29]

Report message to a moderator

Re: how to insert data in two table same time? [message #542653 is a reply to message #542652] Wed, 08 February 2012 06:26 Go to previous messageGo to next message
Littlefoot
Messages: 21813
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
/forum/fa/450/0/

Whoa, right! I could have written a whole book about stuff being impossible to do. Unfortunately, nobody would read it as I'm so very wrong.

Thank you, Shaan121, for opening my eyes. I'd better give up on Oracle /forum/fa/7176/0/, I'm not good at it.

My apologies to you, @mughals_king, I hope you read another opinion.
Re: how to insert data in two table same time? [message #542693 is a reply to message #542653] Thu, 09 February 2012 14:02 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
Thanks for precious information senior/seniorina "shaan121" and also to Mr.Littlefoot i was very delighted to have this code & glad to hear this that we can do this and i think also we can do accomplish this task like this

create table Test(No varchar2(64),name varchar2(25));

SQL> insert into test
select '001', 'Bob' from dual
union all
select '002', 'James' from dual
union all
select '003', 'Dave' from dual

thanks again to both & kindly consider which i have created a new topic which is related to Tree menu & call_form
i shall be very thankful to you

best regards

[Updated on: Thu, 09 February 2012 14:03] by Moderator

Report message to a moderator

Re: how to insert data in two table same time? [message #542695 is a reply to message #542693] Thu, 09 February 2012 14:04 Go to previous messageGo to next message
Michel Cadot
Messages: 68666
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.

Regards
Michel
Re: how to insert data in two table same time? [message #542702 is a reply to message #542695] Thu, 09 February 2012 14:51 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
Thanks Mr.Michel Cadot for this thread just. we were simply tried to insert record in two tables which we have acomplished with the help of some experts as u saw in the forum anyways thanks again for taking this much interest to solve our problems specially for those who r new commers in this forum @ next time we will formatted the code.


best regards

[Updated on: Thu, 09 February 2012 14:56]

Report message to a moderator

Re: how to insert data in two table same time? [message #542729 is a reply to message #542702] Thu, 09 February 2012 23:45 Go to previous message
x-oracle
Messages: 380
Registered: April 2011
Location: gujarat
Senior Member
ITs Ok

you are always well come littlefoot and mughals_king
Previous Topic: I Need help ?
Next Topic: download & install developer suite 6i
Goto Forum:
  


Current Time: Sat Jul 13 12:56:19 CDT 2024