1

Topic: Insert same ID in both tables simultaneously

Help please, there are 2 tables table1 and table2.
Columns in 1st table Employeer_ID
Columns in 2nd table ID, Employeer_ID
It is necessary  one and too sequence in both tables

[url =]
DECLARE
v_table1_sequence NUMBER;
BEGIN
FOR elem in 1. 50
v_sequence: = SEQUENCE_NAME.NEXTVAL
INSERT INTO table1 values (v_table1_sequence);
END;
FOR elem in 1. 50
v_sequence: = SEQUENCE_NAME.NEXTVAL
INSERT INTO table2 values (TABLE2.SEQUENCE.NEXTVAL, v_table1_sequence);
END;
[/url]

In 1st table of value  norms that is 1,2,3,4,5 counter works, and in 2nd table the same counter  one and too value, that is in all 50 lines only value 1.
It is to volume-that the counter it is twisted in 1st cycle, and to 2nd does not react. Tried to deduce a variable v_table1_sequence for unit repartition produces an error.
Help  one and too value sequence in both tables.
In advance thanks

2

Re: Insert same ID in both tables simultaneously

Not absolutely correctly registered, here so:
DECLARE
v_table1_sequence NUMBER;
BEGIN
FOR elem in 1. 50
LOOP
v_sequence: = SEQUENCE_NAME.NEXTVAL
INSERT INTO table1 values (v_table1_sequence);
END LOOP;
END;
FOR elem in 1. 50
LOOP
INSERT INTO table2 values (TABLE2.SEQUENCE.NEXTVAL, v_table1_sequence);
END LOOP;
END;

3

Re: Insert same ID in both tables simultaneously

Goofy122;
- Where an error?
- In DNA.
it is fast me here block sad

4

Re: Insert same ID in both tables simultaneously

Goofy122;
Smoke Sequence Pseudocolumns
SY.

5

Re: Insert same ID in both tables simultaneously

What for?
He needs to smoke "two operators in one cycle" if, of course, I correctly understood that he wants...

6

Re: Insert same ID in both tables simultaneously

by... wrote:

What for? He needs to smoke "two operators in one cycle" if, of course, I correctly understood that he wants...

And it too:

SQL> BEGIN
2 FOR v_i in 1. 3 LOOP
3 INSERT
4 INTO TABLE1
5 VALUES (SEQ1.NEXTVAL);
6 FOR v_j in 1. 3 LOOP
7 INSERT
8 INTO TABLE2
9 VALUES (SEQ2.NEXTVAL, SEQ1.CURRVAL);
10 END LOOP;
11 END LOOP;
12 END;
13 /
PL/SQL procedure successfully completed.
SQL> SELECT *
2 FROM TABLE1
3 /
ID
----------
1
2
3
SQL> SELECT *
2 FROM TABLE2
3 /
ID PARENT_ID
---------- ----------
1 1
2 1
3 1
4 2
5 2
6 2
7 3
8 3
9 3
9 rows selected.
SQL>

SY.

7

Re: Insert same ID in both tables simultaneously

SY;
At Goofy122 independent cycles (not enclosed)
Not clearly that is necessary
1) to save  in the table
2) to interpose in one cycle
.....
stax

8

Re: Insert same ID in both tables simultaneously

Goofy122;
Show on an example that is necessary to you

BEGIN
FOR elem in 1. 50 LOOP
INSERT INTO table1 values (SEQUENCE_NAME.NEXTVAL);
INSERT INTO table2 values (SEQUENCE_NAME2.NEXTVAL, SEQUENCE_NAME.CURRVAL);
END LOOP;
END;

.....
stax

9

Re: Insert same ID in both tables simultaneously

Stax wrote:

Goofy122;
Show on an example that is necessary to you

you are eternal all intrigue will spoil smile

10

Re: Insert same ID in both tables simultaneously

Somehow so

CREATE TABLE T1 (
ID NUMBER
);
CREATE TABLE T2 (
ID NUMBER,
T1_ID NUMBER
);
CREATE SEQUENCE seq_t1;
CREATE SEQUENCE seq_t2;
INSERT ALL
INTO T1 (ID) VALUES (seq_t1.nextval)
INTO T2 (ID, T1_ID) VALUES (seq_t2.nextval, seq_t1.currval)
SELECT *
FROM DUAL
CONNECT BY LEVEL <= 10;

11

Re: Insert same ID in both tables simultaneously

Stax wrote:

Goofy122;
Show on an example that is necessary to you

BEGIN
FOR elem in 1. 50 LOOP
INSERT INTO table1 values (SEQUENCE_NAME.NEXTVAL);
INSERT INTO table2 values (SEQUENCE_NAME2.NEXTVAL, SEQUENCE_NAME.CURRVAL);
END LOOP;
END;

.....
stax

In multiflows there can be not that that is expected

12

Re: Insert same ID in both tables simultaneously

Thanks big everything, liked a variant with INSERT ALL

13

Re: Insert same ID in both tables simultaneously

artas wrote:

it is passed...
In multiflows there can be not that that is expected

Did not understand, what is available in in view of under a multiflow?

Not that that is expected can be and because of  the trigger
.....
stax