Script error - Inserting multiple rows in one SQL statement.
Hi,
Tried using INSERT ALL INTO command inside Script. But getting below error.
Oracle <> error message for operation <OCIStmExecute>: <ORA-00928: missing SELECT keyword>.
Same query with single insert statement runs fine without any issues.
Oracle eg:
INSERT ALL
INTO item (title) VALUES ('title5')
INTO item (title) VALUES ('title6')
INTO item (title) VALUES ('title7')
SELECT * FROM dual;
Appreciate your suggestions.
Thx
Hi,
Actual syntax is as below:
INSERT ALL
INTO suppliers (supplier_id, supplier_name) VALUES (1000, 'IBM')
INTO suppliers (supplier_id, supplier_name) VALUES (2000, 'Microsoft')
INTO suppliers (supplier_id, supplier_name) VALUES (3000, 'Google')
SELECT * FROM dual;
Now in your non working query, you have applied comma after first INTO statement.
Please remove it.
Thanks,
Swapnil
Similar Messages
-
Insert multiple rows with one sql statement in access
Hi,
I'm trying to copy a table into another. What I want to do is to use "Insert into table1 select * from table2 where field > val". Something like that. I know a lot of databases support it. I was wondering if ms access ODBC driver also supports it. I searched quite a bit and haven't found a definitive answer on this.
Thank youYes, M$ Access 2000 supports it. This is from their help:
INSERT INTO Statement
Adds a record or multiple records to a table. This is referred to as an append query.
Syntax
Multiple-record append query:
INSERT INTO target [(field1[, field2[, ...]])] [IN externaldatabase]
SELECT [source.]field1[, field2[, ...]
FROM tableexpression
Single-record append query:
INSERT INTO target [(field1[, field2[, ...]])]
VALUES (value1[, value2[, ...])
The way you've written the INSERT, table1 and table2 have to have the same # of columns and the same types, of course. -
Inserting multiple rows on one "Add Button"!
I have an appliation that tracks family members (address book type app).
form page that tracks "family relationships"
(http://apex.oracle.com/pls/otn/f?p=55283:2)
Page 2/3 are Master Details, where the detail reports are "relationships"
From page three, if I select "Create" it takes me to the Form page
(http://apex.oracle.com/pls/otn/f?p=55283:4) where I can create a relationship and hit "create" and the new record is now visible on page 3.
What I'm trying to do, is create the inverse tie record at the same time. For example.
If I say
record 1 is related to record 2 as "value 3"
I then want to at the same time, create an inverse record:
record 2 is related to record 1 as "value 4".
After researching the forum, I put my best effort into creating a button on page 4 called "Add New" (Thanks Andy for the idea!!) and a page process to run when this button is selected.
There is a PK for the table in questions, that uses a sequence. I'm just learning SQL AND APEX, so I may have totally missed the boat...either way, this errors out on my instance i have on a closed network.
(Unfortunately, my local firewall is not allowing me to post my SQL for the
Here's my page process that fails:
-- Take values from the three page items to create the first row:
INSERT INTO FAMILY_ASSOC
(FAMILY_ASSOC_ID, FAMILY_ID_1, FAMILY_ASSOC, FAMILY_ID_2) VALUES (
FAMILY_ASSOC_SEQ.nextval,
P4_FAMILY_ID_1,
P4_FAMILY_ASSOC,
P4_FAMILY_ID_2)
-- Now reverse the ID_1 and ID_2 to create the Inverse record
-- For example if the row input above is "X" is child of "Y"
-- Need to create record "Y" is parent of "X"
UNION (
FAMILY_ASSOC_SEQ.nextval,
P4_FAMILY_ID_1,
DECODE(P4_FAMILY_ASSOC,
'1','1',
'2','2',
'3','4',
'4','3',
'5','5',
'6','6',
'7','8',
'8','7',
'9','10',
'10','9'),
P4_FAMILY_ID_2)
I've included some reports on page 4 to show what the table looks like:
One report shows all the associations for the individual, and replaces the values with lookup values.
The next report is exactly the same, but without the lookups.
The last report is the same thing, but shows the inverse relationships for the same individual.
Appreciate any ideas!!!Heck! And there was me trying to keep things simple :D
In order for the reports to show data before it is written into the actual records, you would need to have a staging table or, at least, store the values on the page in session BEFORE the insert process runs. To do that, you would have to have a two-step process - one to create the temporary data or store the values and the second to actually write the records. The SQL statements that underlie the reports can easily be updated to refer to either the staging table or the session values. Of course, you would have to create at least one additional button on the page - to create/store the data temporarily - this would have to be conditional - and, the existing button would also have to be conditional, so that only one of the two buttons is displayed at any one time.
Andy -
How to insert 22.5K rows in one sql statement in Oracle
Hi Gurus,
I have a one table with one column. I require to input 22.5k numbers example "08323459" in that table. Can anyone tell me how to insert those 22.5K numbers with one sql command.
I am using PL/SQL client. And oracle version is 11G.If you have an Excel file, the simplest approach is generally to save the file as a CSV, copy it to the database server, create an external table that exposes the file as a table, and then write your INSERT by selecting the data from the external table.
INSERT INTO permanent_table( column_name )
SELECT column_name
FROM external_tableAssuming you have SQL*Loader installed on your client machine, you could also use SQL*Loader to read the data in the file and load it into the database table.
Justin -
Insert multiple rows in one step
please i need to create an input form where i can insert more than one row at one step using jsp/struts/bc4j,i noticed that this is a repeated question on the form but no one answer
If you are using JSF then you can use an ADF Faces multi row edit table.
In 10.1.2 with JSP and Struts there was this how-to that might help:
http://www.oracle.com/technology/products/jdev/tips/mills/JSP_Multi_Row_Edits.html -
Handling error with multiple row insert/update
Hi,
I need to insert multiple rows into a table, and I understand that i need to use executeArrayUpdate().
My problem is this :
1. How do I know in case some of the rows in the array failed during the INSERT?
2. When I do know that, how do I find those particular rows?
ThanksODAFEONIHOWO wrote:
Please i need help on how to enter multiple row into mysql with one insert
statement and jsp it's not possible - you'll need to do a batch insert
i have been trying this for weeks without sucess e.g how much experience do you have with Java? -
How do I insert multiple rows from a single form ...
How do I insert multiple rows from a single form?
This form is organised by a table. (just as in an excel format)
I have 20 items on a form each row item has five field
+++++++++++ FORM AREA+++++++++++++++++++++++++++++++++++++++++++++++++++++
+Product| qty In | Qty Out | Balance | Date +
+------------------------------------------------------------------------+
+Item1 | textbox1 | textbox2 | textbox3 | date +
+ |value = $qty_in1|value= &qty_out1|value=$balance1|value=$date1 +
+------------------------------------------------------------------------+
+Item 2 | textbox1 | textbox2 | textbox4 | date +
+ |value = $qty_in2|value= $qty_out1|value=$balance2|value=$date2 +
+------------------------------------------------------------------------+
+ Item3 | textbox1 | textbox2 | textbox3 | date +
+------------------------------------------------------------------------+
+ contd | | | +
+------------------------------------------------------------------------+
+ item20| | | | +
+------------------------------------------------------------------------+
+ + + SUBMIT + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Database Structure
+++++++++++++++++
+ Stock_tabe +
+---------------+
+ refid +
+---------------+
+ item +
+---------------+
+ Qty In +
+---------------+
+ Qty Out +
+---------------+
+ Balance +
+---------------+
+ Date +
+++++++++++++++++
Let's say for example user have to the use the form to enter all 10 items or few like 5 on their stock form into 4 different textbox field each lines of your form, however these items go into a "Stock_table" under Single insert transaction query when submit button is pressed.
Please anyone help me out, on how to get this concept started.Hello,
I have a way to do this, but it would take some hand coding on your part. If you feel comfortable hand writing php code and doing manual database calls, specificaly database INSERT calls you should be fine.
Create a custom form using the ADDT Custom Form Wizard that has all the rows and fields you need. This may take a bit if you are adding the ability for up to 20 rows, as per your diagram of the form area. The nice thing about using ADDT to create the form is that you can setup the form validation at the same time. Leave the last step in the Custom Form Wizard blank. You can add a custom database call here, but I would leave it blank.
Next, under ADDT's Forms Server Behaviors, select Custom Trigger. At the Basic tab, you enter your custom php code that will be executed. Here you are going to want to put your code that will check if a value has been entered in the form and then do a database INSERT operation on the Stock_table with that row. The advanced tab lets you set the order of operations and the name of the Custom Trigger. By default, it is set to AFTER. This means that the Custom Trigger will get executed AFTER the form data is processed by the Custom Form Transaction.
I usually just enter TEST into the "Basic" tab of the Custom Trigger. Then set my order of operations in the "Advanced" tab and close the Custom Trigger. Then I go to the code view for that page in Dreamweaver and find the Custom Trigger function and edit the code manually. It's much easier this way because the Custom Trigger wizard does not show you formatting on the code, and you don't have to keep opening the Wizard to edit and test your code.
Your going to have to have the Custom Trigger fuction do a test on the submitted form data. If data is present, then INSERT into database. Here's a basic example of what you need to do:
In your code view, the Custom Trigger will look something like this:
function Trigger_Custom(&$tNG) {
if($tNG->getColumnValue("Item_1")) {
$item1 = $tNG->getColumnValue("Item_1");
$textbox1_1 = $tNG->getColumnValue("Textbox_1");
$textbox1_2 = $tNG->getColumnValue("Textbox_2");
$textbox1_3 = $tNG->getColumnValue("Textbox_3");
$date1 = $tNG->getColumnValue("Textbox_3");
$queryAdd = "INSERT INTO Stock_table
(item, Qty_In, Qty_Out, Balance, Date) VALUES($item1, $textbox1_1, $textbox1_2, $textbox1_3, $date1)"
$result = mysql_query($queryAdd) or die(mysql_error());
This code checks to see if the form input field named Item_1 is set. If so, then get the rest of the values for the first item and insert them into the database. You would need to do this for each row in your form. So the if you let the customer add 20 rows, you would need to check 20 times to see if the data is there or write the code so that it stops once it encounters an empty Item field. To exit a Custom Trigger, you can return NULL; and it will jump out of the function. You can also throw custom error message out of triggers, but this post is already way to long to get into that.
$tNG->getColumnValue("Item_1") is used to retrieve the value that was set by the form input field named Item_1. This field is named by the Custom Form Wizard when you create your form. You can see what all the input filed names are by looking in the code view for something like:
// Add columns
$customTransaction->addColumn("Item_1", "STRING_TYPE", "POST", "Item_1");
There will be one for each field you created with the Custom Form Wizard.
Unfortunately, I don't have an easy way to do what you need. Maybe there is a way, but since none of the experts have responded, I thought I would point you in a direction. You should read all you can about Custom Triggers in the ADDT documentation/help pdf to give you more detailed information about how Custom Triggers work.
Hope this helps.
Shane -
How to insert multiple rows in a single shot using insert command?
Hi,
If we insert one row, we can use "insert into" command. I want to insert multiple rows into the table in a single shot. Is there any SQL command for insert multiple rows into the table?
Plese give the solution.
Thanks,
chelladuraiIf you would like to do it with SQL, this would be one of the ways to achive it:
SQL*Plus: Release 10.2.0.4.0 - Production on Fri Sep 25 10:12:59 2009
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, Data Mining and Real Application Testing options
SQL>
SQL> desc leap
Name Null? Type
FIRST_PRICE NUMBER(16,6)
NEXT_PRICE NUMBER(16,6)
SQL>
SQL> select * from leap;
no rows selected
SQL>
SQL>
SQL> !vi multirow_insert.sql
SQL> !cat multirow_insert.sql
insert into leap(first_price, next_price) values (1,2);
insert into leap(first_price, next_price) values (3,4);
insert into leap(first_price, next_price) values (5,6);
SQL>
SQL> @multirow_insert.sql
1 row created.
1 row created.
1 row created.
SQL> commit;
Commit complete.
SQL>
SQL>
SQL> select * from leap;
FIRST_PRICE NEXT_PRICE
1 2
3 4
5 6
SQL> -
Inserting multiple rows using a single Insert statement without using dual
Hi all,
i am trying to insert multiple rows using a single insert statement like the below one.
The below one works fine..
But is there any other change that can be done in the below one without using dual...
insert all
into ps_hd_samp (num1,num2) values (1,1)
into ps_hd_samp (num1,num2) values (2,2)
into ps_hd_samp (num1,num2) values (3,3)
select 1 from dual;NiranjanSe wrote:
Hi all,
i am trying to insert multiple rows using a single insert statement like the below one.
The below one works fine..
But is there any other change that can be done in the below one without using dual...
insert all
into ps_hd_samp (num1,num2) values (1,1)
into ps_hd_samp (num1,num2) values (2,2)
into ps_hd_samp (num1,num2) values (3,3)
select 1 from dual;
SQL> create table ps_hd_samp (num1 number,num2 number);
Table created.
SQL> insert all
2 into ps_hd_samp (num1,num2) values (1,1)
3 into ps_hd_samp (num1,num2) values (2,2)
4 into ps_hd_samp (num1,num2) values (3,3)
5 select count(*)
6 from ps_hd_samp;
3 rows created.
SQL> select * from ps_hd_samp;
NUM1 NUM2
1 1
2 2
3 3 -
Generating multiple rows from one physical row
I was wondering if anyone has done or knows how to generate multiple rows for one physical row. In my query "SELECT Cust_No, Amount from Balances" if the amount is > 99,999.99 I want 2 rows returned, one with an amount of 90,000.00 and the other with an amount of 9,999.99. I'm thinking I need to use a view or function to return a result set but I'm not sure how.
Thanks in advance,
Allen Davis
[email protected]James,
Well your right in that you need a function, but also 3 views to accomplish that. I just wrote up the sql below and tested it. Basically you want the first view to return all records less than your cap of 99,999, thoes that exceed that will always return as 90,000 (see example on record PK 774177177). The second view returns money that remains AFTER the cap (in your case 9,999). The second view though also has to excude the ones less than the CAP.
DATA and TABLE layout
1) Table is called T1, columns are PK : primary key value, and N2 : some number column holding the MONEY amount
2) data is below fromtable called t1 (10 records) ...
select pk,n2 from t1 order by pk
PK N2
117165529 100
274000876 200000
350682010 9999
737652242 90000
774177177 99999
1369893126 1000
1663704428 100000
1720465556 8888
1793125955 0
1972069382 1000000
Now see the records with money at 99,999 (just like in your example). You want 2 records, so the VIEWS now come into play. The view itself CALLS the function, this occurs when you select from the view. The function will either return 90,000 (your defined cap) or the remained after subtracting the money from 90,000. The 3 views are defined below (the FUNCTION which is shown after will have to be compiled first) ...
--[VIEWS START]
CREATE OR REPLACE VIEW VIEW1
(PK,SHOW_MONEY)
AS SELECT PK,FN_TRIM_MONEY(N2,1) FROM T1;
CREATE OR REPLACE VIEW VIEW2
(PK,SHOW_MONEY)
AS SELECT PK,FN_TRIM_MONEY(N2,2) FROM T1 WHERE N2 >= 99999;
CREATE OR REPLACE VIEW VIEW_ALL
(PK,SHOW_MONEY)
AS
SELECT * FROM VIEW1
UNION ALL
SELECT * FROM VIEW2;
--[VIEWS END]
OK now for the actual function ...
--[FUNCTION START]
CREATE OR REPLACE FUNCTION
FN_TRIM_MONEY
PI_MONEY NUMBER,
PI_VIEW_ID NUMBER
RETURN NUMBER AS
LS_TEMP VARCHAR2(2000);
LI_TEMP NUMBER;
LD_TEMP DATE;
LI_CON_MONEY_MAX CONSTANT NUMBER := 90000;
LS_RETURN VARCHAR2(2000);
BEGIN
IF (PI_MONEY > LI_CON_MONEY_MAX) THEN
IF PI_VIEW_ID = 1 THEN
LI_TEMP := LI_CON_MONEY_MAX;
ELSIF PI_VIEW_ID = 2 THEN
LI_TEMP := (PI_MONEY - LI_CON_MONEY_MAX);
END IF;
ELSE
LI_TEMP := PI_MONEY;
END IF;
IF LI_TEMP < 0 THEN
LI_TEMP := 0;
END IF;
LS_RETURN := LI_TEMP;
RETURN LS_RETURN;
END;
SHOW ERRORS;
--[FUNCTION END]
I compiled the function and views with no errors. This is what I get when I query the 3 views ...
--[VIEW 1]
PK SHOW_MONEY
117165529 100
274000876 90000
350682010 9999
737652242 90000
774177177 90000
1369893126 1000
1663704428 90000
1720465556 8888
1793125955 0
1972069382 90000
--[VIEW 2]
PK SHOW_MONEY
274000876 110000
774177177 9999
1663704428 10000
1972069382 910000
--[VIEW ALL]
PK SHOW_MONEY
117165529 100
274000876 90000
274000876 110000
350682010 9999
737652242 90000
774177177 90000
774177177 9999
1369893126 1000
1663704428 90000
1663704428 10000
1720465556 8888
1793125955 0
1972069382 90000
1972069382 910000
So notice the PK entry 774177177 listed twice, once with 90,000 and other with 9,999. Also notice we now have 14 records from the original 10, meaning 4 records qualified for the split (all data from VIEW 2).
This is why Oracle kicks ass, views and functions are very powerful when used together and can return pretty much anything.
Thanks,
Tyler D.
[email protected] -
One script to make multiple cells call one function or vice versa
Please help.
I need one script to make multiple cells reference one function or one cell reference multiple functions.
Goal: On the enter event of cell c1, I want to make cells (this, Header.c1, Example.c1, rLabel) highlighted, and this would be for every other cell that is entered into, their corresponding column header and row header will be highlighted.
I've tried combining cells: eg
colourControls.hdfieldLoseFocus(this, HeaderRow.c1, Example.c1, rLabel);
and I've also tried combining some scripts in the function:
fieldObj.ui.oneOfChild.border.fill.color.value = "255,255,200";
HeaderRow.fieldObj.ui.oneOfChild.border.fill.color.value = "255,255,200";
ExampleRow.fieldObj.ui.oneOfChild.border.fill.color.value = "255,255,200";
But they dont work. See the link to my form.
http://www.winstonanddavid.com/example.com
I tried testing the function with the cell 'c1' but it doesnt work.
Also, I want to get rid of the multiple lines of script in every other cell.
How can I do this?I played around with the ExtendScript Toolkit and cutted and pasted the previous script from here until I managed to get a script that actually works like I was thinking. I then added a code from the CS4 Reference Manual to move Layer1 to the top (just to see if it worked).
I have no idea yet if the the code includes something that does not belong, but at least I get no errors. The current code is like this now:
//Apply to myDoc the active document
var layerName = LayerOrderType;
var myDoc = app.activeDocument;
//define first character and how many layers do you need
var layerName
var numberOfLayers=0;
//Create the layers
for(var i=0; i<=numberOfLayers; i++)
{ var layerName = "Background"; var myLayer = myDoc.layers.add(); myLayer.name = layerName; }
{ var layerName = "Picture"; var myLayer = myDoc.layers.add(); myLayer.name = layerName; }
{ var layerName = "Text"; var myLayer = myDoc.layers.add(); myLayer.name = layerName; }
{ var layerName = "Guides"; var myLayer = myDoc.layers.add(); myLayer.name = layerName; }
// Moves the bottom layer to become the topmost layer
if (documents.length > 0) {
countOfLayers = activeDocument.layers.length;
if (countOfLayers > 1) {
bottomLayer = activeDocument.layers[countOfLayers-1];
bottomLayer.zOrder(ZOrderMethod.BRINGTOFRONT);
else {
alert("The active document only has only 1 layer") -
Want to insert multiple rows in table using EO
Hi,
I have one requirement where I need to insert multiple rows at once in table lets say Previous Employers.
What I am trying to do is I have created few textinputboxes and getting there values and putting in HashMap.
And manually inserting the rows to EO. I am not getting any error but the data is not populating in Table.
here is the code snap ...please suggest!!
public void updateKoelHrPreEmpVO(HashMap map)
OADBTransaction txn = getOADBTransaction();
//HashMap map = new HashMap();
KoelHrPreEmpVOImpl empVO = getKoelHrPreEmpVO1();
KoelHrPreEmpVORowImpl fetchedRow = null;
int fetchedRowCount = empVO.getFetchedRowCount();
RowSetIterator deleteIter = empVO.createRowSetIterator("deleteIter");
if (fetchedRowCount > 0)
if(txn.isLoggingEnabled(2))
txn.writeDiagnostics(this,"Removing rows from KoelHrPreEmpVO :: Current count :: " + fetchedRowCount ,2);
//System.out.println("Removing rows from KoelHrPreEmpVO :: Current count :: " +fetchedRowCount);
deleteIter.setRangeStart(0);
deleteIter.setRangeSize(fetchedRowCount-1);
for (int i = 0; i < fetchedRowCount; i++)
//System.out.println("Removing Row :: "+i);
if(txn.isLoggingEnabled(2))
txn.writeDiagnostics(this,"Removing row :: " + i ,2);
fetchedRow = (KoelHrPreEmpVORowImpl)deleteIter.getRowAtRangeIndex(i);
fetchedRow.remove();
getTransaction().commit();
deleteIter.closeRowSetIterator();
if(empVO.getRowCount() == 0) {
Row row = null;
KoelHrPreEmpVORowImpl insertRow = null;
empVO.first();
if(txn.isLoggingEnabled(2))
txn.writeDiagnostics(this,"Inserting rows to KoelHrPreEmpVO :: " ,2);
try
for(int i=1; i<=4; i++) {
insertRow = (KoelHrPreEmpVORowImpl)empVO.createRow();
insertRow.setEmployeeNumber(map.get("EmployeeNumber").toString());
insertRow.setPersonId(new Number(map.get("PersonId").toString()));
insertRow.setEmployer(map.get("Employer"+i+"").toString());
insertRow.setStartDate(Date.toDate(map.get("StartDate"+i+"").toString()));
insertRow.setEndDate(Date.toDate(map.get("EndDate"+i+"").toString()));
insertRow.setEmployer(map.get("Designation"+i+"").toString());
empVO.insertRow(insertRow);
insertRow.setNewRowState(Row.STATUS_INITIALIZED);
getTransaction().commit();
catch(SQLException ex)
ex.printStackTrace();
Regards,
Mukesh1. Pls check if the create() methos in EOImpl is in place, setting the primary key.
2. Even though we insert values in this fashion , it only gets inserted if user performs any action, like manipulates some column. Pls check if there is any mechansm to make the row dirty ( as if done by user).
Srikanth -
To insert multiple rows by getting the values from the user
Hi
I want to insert multiple rows into a table using user given values dynamically.
I am a beginner to PL/SQL. Below code is part of my big code. A_row_insert is 2 and A_count is 1 (initially). While i execute , it asks for input only once and insert the same data 2 times. I want to enter two different rows. Please guide/advise me on this.
while (A_count<=A_row_insert) loop
dbms_output.put_line('Enter the value for the row#'||A_count||' of the table '||v_req_tab_name||':');
begin
INSERT INTO customers (
customer# ,
lastname ,
firstname ,
address ,
city ,
state ,
referred ,
region
+)+
VALUES
+(+
+&customer,+
+'&lastname' ,+
+'&firstname' ,+
+'&address' ,+
+'&city' ,+
+'&state' ,+
+&referred ,+
+'®ion'+
+);+
end;
A_count := A_count 1;+
end loop;
regards
Sakthivelhi,
You need to write a procedure and call it from front end for n number of time..... check the parameters you need to pass to execute the procedure.... try given sample....
CREATE OR REPLACE PROCEDURE InsertData(i_code IN VARCHAR2,i_code_desc IN VARCHAR2,i_code_type IN VARCHAR2)
AS
BEGIN
INSERT INTO CODE_MASTER (code,code_desc,code_type)
VALUES(i_code,i_code_desc,i_code_type);
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE ( 'Error during Insert code - '||i_code );
END;
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
exec InsertData('code1','desc1','type1');
Thnx MB -
Insert multiple rows with autoincrement id
I need to insert multiple rows to a table which has an autoincrement PK (unique), e.g:
Entity:
public Class Entity{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
Private Long id;
Facade:
@PersistenceContext(unitName = "xx-enterprise-ejbPU")
protected EntityManager em;
public void create(Entity entity) {
em.persist(entity);
Service Class:
public Class Service implements ServiceLocal{
@EJB
private XxxFacadeLocal xxxFacade;
public void saveEntity(Entity entity){
xxxFacade.create(entity)
ManageBean:
public Class ManageBean
@EJB
private ServiceLocal service;
public void doSave(ActionEvent event)
service.saveEntity(entity1); //entity.id is set to null, suppose to be generated by DB auto_increment, i.e. insert 3 rows with 3 different ids
service.saveEntity(entity2);
service.saveEntity(entity3);
The result is: Key duplication error on inserting entity2, but entity1 is inserted into DB with id auto increased correctly.
If I insert only one row each time for test purpose, everything works as expected.
But what I need is to insert multiple rows. How to do it?
Thank you in advance.Like this (although the @Basic annotation is very much unnecessary). So if it isn't happening you must have made a mistake somewhere. Are you sure the ID column actually has auto_increment?
Also if you are using Hibernate as the persistence provider and you put it on the classpath, check the packages of the annotations you are using; Hibernate and JPA share some with the same name unfortunately. -
Insert multiple rows in on table and retreive sequence values
Hello,
I'm searching a way to insert several rows in a table that needs a sequence and retreive its.
For one row i use ExecuteScalar method with the following SQL is :
INSERT INTO MY_TABLE(MY_PK)
VALUES(SEQ_MY_TABLE.NEXTVAL) RETURNING MY_PK INTO :MY_PARAMETER
The aim is to insert several rows at one time. Currently I execute this SQL :
INSERT INTO MY_TABLE(MY_PK, MY_VALUE)
SELECT SEQ_MY_TABLE.NEXTVAL, MY_VALUE
FROM (
SELECT 0 MY_VALUE FROM DUAL UNION ALL
SELECT 1 MY_VALUE FROM DUAL
This query works well but i'm wondering how to retreive all sequence values generated by this query.
Is it possible and how ?
Thank you.
SebastienI tried this :
string sql = "INSERT INTO MY_TABLE(MY_PK, MY_VALUE) " +
"SELECT SEQ_MY_TABLE.NEXTVAL MY_PK, MY_VALUE FROM ( " +
"SELECT 0 MY_VALUE UNION ALL " +
"SELECT 1 MY_VALUE) " +
"RETURNING MY_PK BULL COLLECT INTO : RETURN_IDS";
using(var manager = myFactory.CreateDbManager()) // Initializes the connection and encapsulates ADO objects
manager.SetCommand(sql);
var cmd = (OracleCommand)manager.Command;
cmd.ArrayBindCount = 2;
var p = new OracleParameter();
p.DbType = DbType.Int64;
p.ParameterName = "RETURN_IDS";
p.Direction = ParameterDirection.Output;
p.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
p.Size = 2*sizeof (long);
cmd.Parameters.Add(p);
cmd.ExecuteNonQuery();
var result = (Oracle.DataAccess.Types.OracleDecimal[])p.Value;
But I have an error ORA-00933 that indicates that the query is wrong at "RETURNING MY_PK".
.......................................................................................................^
Edited by: CITnDev on 1 août 2012 13:00
Edited by: CITnDev on 1 août 2012 15:10
Maybe you are looking for
-
Arrows not showing up in slideshow, not able to control back and forth in slideshow
So I have a slideshow that is on one of my pages and the arrows on the two sides will not appear. Before the pictures all load I can see the arrows behind the pictures but once they the arrows end up behind the pictures. The pictures rotate normaly
-
Reduce brightness of Full Screen background
How can I do that please? It's rather too bright for me.
-
Why is Firefox for Android and Nook HD+ such garbage?
it's very annoying, u can't save pages, the menu system sucks, the top is stupidly designed to hide after a few seconds, the tab system is stupidly hidden and confusing and hard to use! make it the way it is in windows, not this simpleton trendy crap
-
%PLATFORM_ENV-1-PWR_RPS: Redundant power supply faulty or in standby mode
Hi All, We are getting the below error on our Cisco 3560 Switch and the device is running on the image ":c3560-ipservicesk9-mz.122-55.SE4.bin". 010790: Mar 2 00:19:35 PDT: %PLATFORM_ENV-1-PWR_RPS: Redundant power supply faulty or in standby mode 010
-
Specific Row disabling in a matrix
Is there away to disable only specific row in a matrix depending on a value? If so If you could provide a sample in VB or VB.net I would greatly appreciate it. Thank You Stephen Sjostrom