inserting multiple rows of another table with incremented recordid
Hi allI HAVE TWO TABLES:
CREATE TABLE TEMP_TEST1)
NUMBER OF RECID,
TESTCHAR VARCHAR2 (500)
)
AND
CREATE TABLE TEMP_TEST2)
TESTCHAR VARCHAR2 (500)
)
Both the table contains data in it. I want to insert data from TEMP_TEST2 in TEMP_TEST1 with RECID incremented for each record, which must be greater than max (RECID) of TEMP_TEST1.
PS: I have to query insert only, I cannot make changes in the structure of table or RECID of TEMP_TEST1 is not automatically incremented.
Please suggest a query that selects the record of TEMP_TEST2 and TEMP_TEST1 insert with recid incremented for each record.
Thank you.
SQL> insert into TEMP_TEST2(TESTCHAR)
2 select 'Test'||level from dual connect by level < 10
3 /
9 rows created.
SQL>
SQL>
SQL> insert into TEMP_TEST1(RECID,TESTCHAR)
2 select (select nvl(max(RECID),0) from TEMP_TEST1) + rownum, t2.TESTCHAR
3 from TEMP_TEST2 t2
4 /
9 rows created.
SQL>
SQL> select * from TEMP_TEST1
2 /
RECID TESTCHAR
---------- ----------
1 Test1
2 Test2
3 Test3
4 Test4
5 Test5
6 Test6
7 Test7
8 Test8
9 Test9
9 rows selected.
SQL> insert into TEMP_TEST1(RECID,TESTCHAR)
2 select (select nvl(max(RECID),0) from TEMP_TEST1) + rownum, t2.TESTCHAR
3 from TEMP_TEST2 t2
4 /
9 rows created.
SQL>
SQL> select * from TEMP_TEST1
2 /
RECID TESTCHAR
---------- ----------
1 Test1
2 Test2
3 Test3
4 Test4
5 Test5
6 Test6
7 Test7
8 Test8
9 Test9
10 Test1
11 Test2
RECID TESTCHAR
---------- ----------
12 Test3
13 Test4
14 Test5
15 Test6
16 Test7
17 Test8
18 Test9
18 rows selected.
SQL>
Good bye
DPT
Tags: Database
Similar Questions
-
How to insert multiple rows in a table by the user (pl/sql)
Hello
I was trying to insert several rows in a table by a user by some pl/sql, but not every time entry. :/
What is happening is that the program requires each time ask the user for the new value but the loop
1 values inserts actually four times (the loop is run four times). can any point on what I am
doing wrong or solutions will be fun ;)
what I wrote here
---------------------------------
Set serveroutput on
set verify off
declare
EmpNo number;
EmpName varchar2 (20);
Start
because loop me in 1.4
EmpNo: = & empno;
EmpName: = '& empname';
insert into values(empno,empname) of the employee;
end loop;
end;
-------------------------------
do not laugh at my code, I'm new to this oracle :D
Thank you, prospects for the future for a responseuser13371438 wrote:
Thanks for the info, looks like a nice tool will ;) try
but I really want (my problem) in pl/sqlTake a quick re-read my post above.
PL/SQL is a process running on the database server. This process cannot interact with the client computer. He can't ask for user input, and it cannot display the output to the client. Client interface tools can only do. You are eager to get feedback from a user, if you need an interface tool to do. SQL * Plus can interface and application of entry, but only as variable substition, and it does not really provide a programming construct that allows you to run a program in a loop to do. Do this using SQL * Plus you must pair it with shell/dos scripting languages, but more ideally you should use an interface appropriate as Apex.
I was wondering if it all works in pl/sql to release cached data (as fflush (stdin) in c ++)
PL/SQL does not a customer entry, so there is no sense to have something to release the cached data. You pass the values of PL/SQL code using procedures or functions with parameters.
-
Update multiple rows in a table with one value of another multiple
Using SQL Server
How this can be done:
In all the lines in the upper table PS_CA_BILL_PLAN, we want to update the field LAST_XREF_SEQ_NUM with the MAX (XREF_SEQ_NUM) + 1 of the bottom table
Where the CONTRACT_NUM and the BILL_PLAN_ID are equal
This SQL below (in green) works for one line only
I think it's the SQL code you're looking for:
UPDATE PS_CA_BILL_PLAN SET LAST_XREF_SEQ_NUM =
(SELECT MAX (XREF_SEQ_NUM) + PS_CA_BP_XREF 1 B)
WHERE B.CONTRACT_NUM = A.CONTRACT_NUM AND B.BILL_PLAN_ID = A.BILL_PLAN_ID)
-
Need to create a trigger that generates multiple rows in another table
{size: 12} Hello
I use Oracle9i (9.2.0.4.0)
My problem is:
I need to create a trigger that create different in the other table lines when someone will introduce a new line in the first table.
For this, I use the table 4:
1. first one where you want the trigger.
2. a second just to take information.
3. a third to make a trip meter.
4. the fourth is the table where I want to create new lines. {size}
Here is a summary of these 4 tables:
{color: blue} Table 1
STOJOU
Number ¿Nulo? Tipo
STOFCY_0 NOT NULL VARCHAR2 (9)
ITMREF_0 NOT NULL VARCHAR2 (60)
LOT_0 NOT NULL VARCHAR2 (45)
VCRTYP_0 NOT NULL NUMBER (3)
VCRNUM_0 NOT NULL VARCHAR2 (45)
VCRLIN_0 NOT NULL NUMBER (10)
QTYSTU_0 NOT NULL NUMBER
NUMVCR_0 NOT NULL VARCHAR2 (45) {color}
{color: blue} Table 2
ITMMASTER
Number ¿Nulo? Tipo
ITMREF_0 NOT NULL VARCHAR2 (60)
ZCOEFI_0 NOT NULL NUMBER {color}
{color: blue} Table 3
ZCTUART;
Number ¿Nulo? Tipo
CTUART_0 NOT NULL NUMBER (10)
CTUDATE_0 NON NULL DATE {color}
{color: blue} Table 4
ZUART
Number ¿Nulo? Tipo
ZUARTDM_0 NOT NULL VARCHAR2 (102)
STOFCY_0 NOT NULL VARCHAR2 (9)
STOCOU_0 NOT NULL NUMBER
ITMREF_0 NOT NULL VARCHAR2 (60)
LOT_0 NOT NULL VARCHAR2 (45)
CREDAT_0 NOT NULL DATE
QTYSTU_0 NOT NULL NUMBER
STA_0 NOT NULL VARCHAR2 (3)
VCRLIN_0 NOT NULL NUMBER (10)
VCRNUM_0 NOT NULL VARCHAR2 (45)
VCRTYP_0 NOT NULL NUMBER (3) {color}
I do this trigger:
{size: 12} And the error message I get States is just:CREATE OR REPLACE TRIGGER CREA_REGISTROS_TRAZA AFTER INSERT ON STOJOU FOR EACH ROW DECLARE n INTEGER; ct NUMBER; fecha_actual VARCHAR2; fecha_old VARCHAR2; codigo_dm VARCHAR2; BEGIN fecha_actual := TO_CHAR(SYSDATE, 'DD/MM/YYYY'); -- SELECT TO_CHAR(sysdate, 'DD/MM/YYYY') INTO fecha_actual FROM DUAL; SELECT TRUNC((STOJOU.QTYSTU_0/ITMMASTER.ZCOEFI_0),0) INTO n FROM STOJOU INNER JOIN ITMMASTER ON STOJOU.ITMREF = ITMMASTER.ITMREF; FOR i IN 1 .. n LOOP SELECT CTUART_0,TO_CHAR(CTUDAT_0, 'DD/MM/YYYY') INTO ct,fecha_old FROM ZCTUART; IF fecha_old <> fecha_actual THEN ct := 0; END IF; ct := ct + 1; INSERT INTO ZCTUART (CTUART_0,CTUDAT_0) VALUES (ct,SYSDATE); codigo_dm := SUBSTR('000000000000000000000',1,20 - LENGHT(NEW.ITMREF_0)) || NEW.ITMREF_0 || SUBSTR('0000000000',1,10 - LENGHT(NEW.LOT)) || NEW.LOT || SUBSTR('0000',1,4 - LENGHT(ct)) || ct; INSERT INTO ZUART (ZUARTDM_0,ITMREF_0,CREDAT_0,STA_0,QTYSTU_0,LOT_0,STOFCY_0,VCRLIN_0,VCRNUM_0,VCRTYP_0) VALUES (codigo_dm,NEW.ITMREF_0,SYSDATE,0,NEW.QTYSTU_0,NEW.LOT_0,NEW.STOFCY_0,NEW.VCRLIN_0,NEW.VCRNUM_0,NEW.VCRTYP_0); END LOOP; END CREA_REGISTROS_TRAZA; /
"The trigger was created with compilation errors."
Thanks for the help {size}You must prefix your NEW "columns" with a colon, as in: NEW.
-
to insert multiple records in another table
Hi all;
How can I increase the number of records in the table?
SQL > insert into tab2 to select * From tab1;
Enter tab2 to select * From tab1
*
ERROR on line 1:
ORA-00926: lack of keyword VALUES
Hi try this...
Insert in tab2 select * from tab1
-
Inserting multiple rows - need help
Hi all
I need to insert several rows in the table with a single query, and the number of lines is 269470.
Here one of the columns is determined by another sub query that returns multilple lines and the other 2 columns remain same for all.
I came up with the following query, but need a loop to turn several times (269470 times).
insert into EMLUSRRECV
(user_id, storeent_id, receiveml)
values
(+ (select user_id from users including the user_id not in (select distinct user_id of EMLUSRRECV) and CURR = 'USD' and rownum = 1) +, 11154, 1);
Thanks in advance.And how did you think of sql developer can help you with that?
Why don't mark you this question ANSWER and post in the forum SQL and PL/SQL.
SQL and PL/SQL -
Not how to show a part of online data in a table in another table with even no column?
I need to display the data from certain rows in a table in another table with the same numbers of columns and main table must be disabled. Could someone advice how to do this? Data in the table are from the microprocessor and is intended the user can see and edit only some data.
If someone can show me some advice, it will be a great help.
Kind regards
Annemariehoeven
Disable a table: SetInputMode (panelHandle, controlID, 0); ('1' to re - activate).
Hide a table: SetCtrlAttribute (panelHandle, controlID, ATTR_VISIBLE, 0); ('1' to show it again).
These commands are valid for each type of control.
To extract values from the table, you can just use GetTableCellVal or GetTableCellRangeVals: If the range of cells has the same data type, you can use the second command which is faster; If the cells are different (for example digital and channels) you must solve each of them individually. The use of the Clipboard doesn't have this limitation.
-
Could not use DB function call to insert a row into a table OBIEE
Hello
At the prompt of the OBIEE report, I create a DB function in a variable column of the guest, so whenever I'm in the dropdown variable ob column call the function DB call.
The function call is insert a row into a table in the database. However, it seems impossible to insert the row into the table.
I have test the function in the sqlplus and it works, if the function has no problem. The problem is OBIEE failed to insert something in the datebase, it can only read from it.
Any ideas on how I could fix it?
Thank you!Hello
Use your Evaluate function and the variable correctly. In the case where u called this function evaluate in the report in a column, and he has 100 files it contains, it will call db 100 times.Kind regards
Anitha.B -
updated line and insert them into another table with trigger.
Hi guys I have a table that looks like this.
I'm going to insert the col1 and col2 values, but I need to get the value of column 3 of table 2 and then insert the complete record in table 3. I love doing that with a trigger. I get an error message and I can't for the life of me figuere out what im doing wrong.CREATE TABLE TEST ( "COL1" VARCHAR2(20 BYTE), "COL2" VARCHAR2(20 BYTE), "COL3" VARCHAR2(20 BYTE) )
So here is my nonfunctional trigger.
Here are the two table
HERE IS THE CODE OF THE TRIGGERCREATE TABLE TESTTABLE ( "COLUMN1" NUMBER(15,0), "COLUMN2" NUMBER(15,0) ) Insert into TESTTABLE (COLUMN1,COLUMN2) values (1,5);
I get an error of trigger mutation that I tried the other iterations of the above but I'm not getting anywhere. I have dumb down my problem at these 3 table.CREATE OR REPLACE TRIGGER TRIGGER1 AFTER INSERT ON TEST FOR EACH ROW BEGIN update TEST SET COL3 = (SELECT COLUMN2 FROM TEST, TESTTABLE WHERE COLUMN1 = :new.COL1); END
Can someone point me in the right direction.You'll have to do some reading, but it comes down to process the data on education instead of line level.
You may even be not at all a trigger.
See:
http://www.Oracle-base.com/articles/9i/mutating-table-exceptions.php
http://asktom.Oracle.com/pls/asktom/asktom.download_file?p_file=6551198119097816936 -
Inserting multiple rows programmatically received the unique key error
I'm developing an application using ADF BC (JDev 11.1.1.5) ADF.
I have a table with the attributes (id, tpId, trId) where tpId is in reference to the primary key of the table tp and trId is in reference to the primary key of the table tr. The combination of tpId and trId should be unique to table A.
I wrote the following codes in my bean to create multiple records (from selections on a page of the user interface that allows users to select tables tp and tr).
CCPC DCBindingContainer = getDCBindingContainer();
DCIteratorBinding iter = dcbc.findIteratorBinding("AVO1Iterator");
RowSetIterator rsi = iter.getRowSetIterator ();
for (int x = 0; x < selectedRowCount; x ++) {}
Line myRow = rsi.createRow ();
myRow.setAttribute ("Tpid", tpRowId [x]);
myRow.setAttribute ("Trid", trId);
myRow.setNewRowState (Row.STATUS_NEW);
rsi.closeRowSetIterator ();
try {}
System.out.println ("insert:" + myRow.getAttribute ("Tpid") + "," + myRow.getAttribute ("Trid"));
dcbc.getDataControl () .commitTransaction ();
created ++;
} catch (Exception e) {}
System.out.println ("insert:" + myRow.getAttribute ("Tpid") + "," + myRow.getAttribute ("Trid"));
System.out.println (e.getMessage ());
DUPS ++;
}
}
Unfortunately, I get the following error:
Insertion: 535, 48
Failed: 535, 48
Houston-26048: constraint 'A_UK1' is violated during the operation "Insert" post with SQL statement ' BEGIN INSERT INTO A(ID,TPID,TRID) VALUES (: 1,: 2:3) in RETURNING ID, TRID INTO: 15,: 16; END; ».
Insertion: 537, 48
Failed: 537, 48
and so on...
I check the database, there is no record at all thanks to the combination.
Did anyone here see the rub on my codes?The framework works as expected. If you try to insert a key duplicated at once, you must clear the error before you can continue. In your case, you can use a rollback on the transaction to clear the error.
Another thing that seems strange to me is that you do not set the id of the new line, which is without doubt the pharmacokinetics of the of the line.Timo
-
Update multiple rows in a table at a time
Hi all
I write a stored procedure that fills all columns in a table, that table with a query with the exception of a single column, say 'ABC' column in this table. I have to load this left on column using a different query that refers to some other tables. How can I update this column 'ABC' with all its rows of data from a different query?
Thank you very much!!If you post an update with a create table and insert statements, it would be useful... I think that you want to update a table with a select from another table using a join... is that correct?
c customer update
Set client_name =)
Select client_name
of another_customer_table one
where a.customer_id = c.customer_id_from_original_customer_table
)
where c.customer_id in (select customer_id from another_customer_table)Where clause is required only if you don't want to update missing customer_ids to null.
-
How to insert duplicate values in another table.
angle of attack!
I created two tables a and b
create table one
(key primary code number);
create table b
(code number,
DAT date);
insert into the table of a (code)
values (1234);
insert into the table of a (code)
values (1235);
commit;
Select * from a;
one
-----
1234
1235
-----
insert into the table of a (code)
values (1234);
commit;
ERROR on line 1:
ORA-00001: unique constraint (GMS. SYS_C0030897) violated
{color: #ff0000} * I need, when the user inserts duplicate data, must be inserted into another table b.* {color}
How can I do in forms 6i? Help, please. Thanks in advance.
Hello
What is the relationship with the forms?
Anyway, you can create a trigger on table A that intercepts the error in an exception block, and then create a new row in table B.
If the error comes from a forms based block, intercept the error in a trigger insert.François
-
How to get multiple rows in the table is displayed on the form
I am looking for a way to get more table rows that appear on the form. I created a table with a header and a line with the add-in and remove button option. I like how the sample purchase order form has it setup in the designer it shows one line and it appears on the form so the table has three rows to start with. How do I do that? I looked at the code on the sample and I couldn't find it anywhere. Please help, thanks.
Hello
I have an example here in the construction of a dynamic array markets.
http://www.assuredynamics.com/index.php/category/portfolio/building-dynamic-tables/
You must select the line and then go to object > Binding palette and set it to repeat. You can set the minimum and initial number to what you want.
The form should be saved in a dynamic form of XML in the Save as dialog box.
Also the page must be set to Flowed, so that as the table grows, push another object down. In addition, you need to configure the paging settings so that the flow of the page as the number of lines is superior to a single page.
Give a start and if you need more help,
Niall
-
Insert multiple records in a form with checkboxes
Hello
I need to insert multiple records in a database of a form using Coldfusion and am stuck - it works correctly when inserting one record at a time. Basically, the user will choose their name of the employee (EmployeeID) in a dynamic list, then several session (open) numbers that represent classes of training.
When I try and select several check boxes, I get this error:
"The number of query values and destination fields is not the same."
The boxes of the open field are not dynamic, as you can see-how use CFLOOP or any other method to allow several checkboxes be selected, and all open documents is entered into the database on a form?
I used server behaviors Dreamweaver 8 to create the form - which is limiting I know but I'm not a coder. I hope I can add code here to do things correctly function.
----APPLICATION CODE------------------------------------------------------------------
<!-get employee names->
< cfquery name = "rsDisplayEmployee" datasource = "FormationRH" >
SELECT *.
OF tblEmployees
ORDER BY LastName ASC < / cfquery >
<!-->-->
<! - insert Records - >
< cfset CurrentPage = GetFileFromPath (GetTemplatePath ()) >
< cfif IsDefined "(FORM. MM_InsertRecord") AND the FORM. MM_InsertRecord EQ 'form1' >
< cfquery datasource = "FormationRH" >
INSERT INTO tblEnrollments (open, EmployeeID)
VALUES)
< cfif IsDefined "(FORM. Open") AND #FORM. Open # NEQ "" > "".
#FORM. Open #.
< cfelse >
NULL VALUE
< / cfif >
,
< cfif IsDefined "(FORM. EmployeeID") AND #FORM. EmployeeID # NEQ "" > "".
#FORM. EmployeeID #.
< cfelse >
NULL VALUE
< / cfif >
) < / cfquery >
< cflocation url = "2.cfm" >
< / cfif >
<!-->-->
--------FORM CODE-----------------------------------------------------------------------
< form action = "" < cfoutput > #CurrentPage # < / cfoutput > "id = 'form' name ="form"method ="POST">"
< table width = "100%" border = "0" cellspacing = "0" cellpadding = "4" >
< b >
< td width = "100%" > < h2 > < strong > select an employee name < facilities > < / h2 > < table >
< /tr >
< b >
< td > < select name = "EmployeeID" >
< cfoutput query = "rsDisplayEmployee" >
< option value = "#rsDisplayEmployee.EmployeeID #" > #rsDisplayEmployee.LastName #, #rsDisplayEmployee.FirstName # < / option >
< / cfoutput >
< / select > < table >
< /tr >
< /table >
< h2 > < strong > select training class < facilities > < / h2 >
< table width = "600" border = "0" cellspacing = "0" cellpadding = "0" >
< b >
< td width = "227" valign = "top" > class < table >
< td width = "373" valign = "top" > < input name = "Open" type = "checkbox" value = "937" / >
Date < table >
< /tr >
< b >
< td valign = "top" > class < table >
< td valign = "top" > < label >
< input name = "Open" type = "checkbox" value = "936" / >
< / label >
Date < table >
< /tr >
< /table >
< br / >
< input type = "submit" name = "Submit" value = 'Sign Up!' / >
< input type = "hidden" name = "MM_InsertRecord" value = "form" >
< / make >
"Add a line" I want to say that, for each of the checkboxes selected in your form, the code will be to insert a new record in the database table. Sorry I probably didn't phrase it very well.
so, no, the code does not need to wrap around each element. Instead the code examines the form.fieldnames variable (form.fieldnames, which is a list separated by commas of all fields defined in the form, is automatically submitted to each form submission - you don't have to define yourself somehow) and for each selected checkbox will insert a new record in your table with the check box selected and selected value the value of the id of the employee.
-
Is it possible to insert a number of rows in a table based on a value entered in a textbox? For example (I'm a tech writer not a programmer/engineer, so please be patient with me.), if someone enters "4" in a textbox, can I insert a large number of number of lines?
Thank you!
-TomWho did jdeline. Thank you!
Maybe you are looking for
-
Tecra 8200 - what computer laptop model number should I?
All topCan someone tell me how do I know what model I have? I try to download the drivers for my computer, but am not sure which series / model it is. I have the following information on the basis of the machine: TOSIBA Tecra 8200Model No.: PT820E-05
-
Why is it not my music showing I did the update?
I did something to update this morning and now my music is not appear ios 9. When I click on music it just shows a young girl listening to the headphones. Help.
-
where can I enter the WEP for wireless connection?
When ddo enter the WEP key wo full information Wi - Fi?
-
Is it set somewhere that that the fields are in the rule before SNMP trap. When I separate data, I understand the data essentially looks like this for all the pitfalls: SNMPv2 - SMI:enterprises.7572.1.4.1 = STRING: "Global restorations were 6% on ser
-
BlackBerry Z10 that nothing turns
Turns nothing on my z10 I tried to disable the locking of rotation and restart the phone, but nothing happens, I've tilt it to the side and it does nothing, does anyone else have this problem? If so how do solve you this problem?