How to return the newly generated sequence id for an INSERT statement
A record is to be inserted into a table with a sequence for the primary key. The newly inserted sequence value is to returned on successful insertion. Is it possible to do all this in a single statement (say executeUpdate or any other) using java.sql.* ?
E.g.: - A student record is to be inserted into the STUDENT table. There is a sequence (by name Student_ID_SEQ) on the primary key Student_ID. Student_ID_SEQ.nextval will generate the new sequence id which will be provided as input to the SQL statement (say statement.executeUpdate) along with other student attribute values. On insertion the created sequence id should be returned. And all this should happen in a single statement (single call to database). Stored Procedures can accomplish this. But is this feasible without the use of Stored Procedures?
Thanks.
a better aproach is to generate the auto key on the
database side, not on the application side.That's his problem - since the database is supplying the key for the new record his application which executed the SQL has no way to identify the record that was just added. I just create the key on the app server and accept the likelihood of overlap (which is extremely small).
Here is a more technical explanation:
Table Person
ID,
Name,
Phone Number,
Age
}The field ID is an autonumber, and all other fields are not unique.
Now, when this code executes:
PreparedStatement pst = conn.prepareStatement("Insert Into Person (Name, Phone Number, Age) Values ?, ?, ?");
pst.setString(1, "John");
pst.setString(2, "405-444-5555");
pst.setInt(3, 44);
pst.executeUpdate();How can the app determine the ID of the person just added since no query is possible which is guaranteed to select just the record that was inserted?
Since I am generally against Stored Procedures I would develop a way to insure that your keys were unique and generate them inside the app server.
Similar Messages
-
How to use the program "Generate test data for BAI bank statement" ?
Hi all,
I use the program RFEBKAT5 to create an Electronic Bank Statement file in BAI format ,but it doesn't generate the file .
I don't know how to generate the file.
Please help me !
Thanks all !You need to suitably adjust your GL accounts for "Posting Offset Account" (Whisch is defaulted as ++++++++19" and Checkout/Funds Out/Funds IN GL accounts to your configuration.
Once you do this try generating the file again. -
How to change the auto generated thumbnail images for a clip?
When iMovie created all the thumbnails for my clips it got most of them right, but on some of them it has choosen a frame that doens't really represent that clip.
Is there any way to change the poster frame for each clip?Hi,
Afte uploaded record it create internal number (Personal ID), and it get stored in table MESSTAB. And that internal number is stored in field MESSTAB-MSGV1. Use this MESSTAB-MSGV1 field for the further use.
Hope, it will help you.
Thanks & Regads,
Poonam. -
How to increment the date using sequence?
how to increment the date using sequence?
01-jan-10
02-jan-10
30-jan-10794244 wrote:
how to increment the date using sequence?
01-jan-10
02-jan-10
30-jan-10This doesn't look like a task where a sequence is usefull.
A sequence is a number generator that guarantees that multiple sessions will all get a different number.
Even if the sequence is fetched for differnent users (=sessions) that the same time.
This in turn means that the value returned by the sequence will depend on actions done in other sessions.
Typical task: create a new unique primary key number. The number MUST be different in all sessions.
In your case I guess that the same logic should work regardless of the session that executes it. So you need a "number generator" that works indepented from other session values. There are several ways to create such a numbered list.
The basic idea is to create a select statement that simply returns as many rows as you need. And then use ROWNUM as the number generator. Examples how to do this have already been given. LEVEL works also in hierarchical queries.
if my interpretation of your requirement is right, then all answers that really used a sequence seem to be wrong. Even if the output looks ok. At best they are just slow. To create new sequence values is a complex task and the database needs a little time for all the synchonization issues that come with it. At worst it will have gaps in the sequence because other sessions used the same value while the numbers were created.
Edited by: Sven W. on Sep 20, 2010 2:08 PM -
How to get the Newly added fileds from Oracle to BW
Hi ,
We have created the view in the DB side and extracted the data to BW side. After that in the DB side they have added new filed. I want to extract the data for that filed also. But that filed is not displaying in the data source itself. We have deleted the sources system assignment to that particular info source and generated the data source in the source system side, and then also I an unable to get the newly added filed in the data source. We are extracting the data from the ORACLE data base. Please let me know the steps how to get the newly added filed in the data source.
Thanks,
VisuHi Yadav,
yes i have alreday created the info objects in the BW side. In the Oracle DB i can see the fileds in the data sources. Newly added filed is not displaying where as previous all fileds are displaying in the oracle DBside.
Thanks,
Visu -
How to get the Newly Created Material
Hi all,
Iam creating Materials using BDC sessions method,My Problem is to update the Newly Created Material in a Ztable.
so iam getting the Newly created Matnr by the following peice of code
SELECT matnr FROM mara INTO TABLE v_matnr
WHERE ersda = sy-datum
ORDER BY matnr DESCENDING.
But the thing is,we are getting Previously created material.i.e the new material will be created only after the sessions are processed,but when i write the above code in the program we are getting previous material.
so how to update the newly created material.
I think we can't do that through program because we can get new material only after processing the session..so what is the solution for this.should we use userexits for getting the newly created material.
thanks in advance
balajiHello,
Use the <b>BAPI_MATERIAL_SAVEDATA</b> to create the materials.
The BAPI will return the Material number which is created at that instance by which u can update the ZTABLE.
Vasanth -
How to return the correct row of data using diffferent conditions?
I am having some problems with an sql query and I hope someone can help please?
The data I am using is customers with multiple transactions. If a customer contains one transaction where the transaction type = 'W' then I need to set the output value to be transaction.ValueA. If the customer does not contain any transactions where the transaction type is 'W' then I need to set the output value to be
the most recent transaction.ValueB where transaction.transaction_date <= customer.cust_mod_date.
Here is an example of the data. For each test customer 10 and 20 I have put a star against the value I want to return
CUSTOMER_ID CUST_MOD_DATE TX_DATE TX_TYPE TX_VALUEA TX_VALUEB
10 15/07/2009 16/07/2009 A 110 95
10 15/07/2009 14/07/2009 A 100 90(*)
10 15/07/2009 13/07/2009 A 90 10
10 15/07/2009 12/07/2009 A 80 5
20 15/07/2009 15/07/2009 A 60 10
20 15/07/2009 14/07/2009 W 50(*) 20
20 15/07/2009 13/07/2009 A 40 30
ie
CREATE TABLE
TMP_CUSTOMER (CUSTOMER_ID NUMBER, CUST_MOD_DATE DATE);
insert into tmp_customer
values(10, to_date('15/07/2009','dd/mm/yyyy'));
insert into tmp_customer
values(20, to_date('15/07/2009','dd/mm/yyyy'));
CREATE TABLE
TMP_TRANSACTION (TX_ID NUMBER, CUSTOMER_ID NUMBER, TX_DATE DATE, TX_TYPE VARCHAR2(1), TX_VALUEA NUMBER, TX_VALUEB NUMBER);
INSERT INTO TMP_TRANSACTION
VALUES (1,10, to_date('16/07/2009','dd/mm/yyyy'),'A',110,95);
INSERT INTO TMP_TRANSACTION
VALUES (2,10, to_date('14/07/2009','dd/mm/yyyy'),'A',100,90);
INSERT INTO TMP_TRANSACTION
VALUES (3,10, to_date('13/07/2009','dd/mm/yyyy'),'A',90,10);
INSERT INTO TMP_TRANSACTION
VALUES (4,10, to_date('12/07/2009','dd/mm/yyyy'),'A',80,5);
INSERT INTO TMP_TRANSACTION
VALUES (5,20, to_date('15/07/2009','dd/mm/yyyy'),'A',60,10);
INSERT INTO TMP_TRANSACTION
VALUES (6,20, to_date('14/07/2009','dd/mm/yyyy'),'W',50,20);
INSERT INTO TMP_TRANSACTION
VALUES (7,20, to_date('13/07/2009','dd/mm/yyyy'),'A',40,30);
The query I have so far is
(SELECT CUSTOMER_ID, CUST_MOD_DATE, TX_DATE, TYPE_FLAG, TX_VALUEA, TX_VALUEB, RN
FROM (SELECT CUST.CUSTOMER_ID, CUST.CUST_MOD_DATE,TRANS.TX_DATE, TRANS.TYPE_FLAG, TRANS.TX_VALUEA,TRANS.TX_VALUEB,
ROW_NUMBER() OVER (partition BY TRANS.CUSTOMER_ID ORDER BY TRANS.TX_DATE DESC) RN
FROM TMP_CUSTOMER CUST,
--- Return all transactions creating a type_flag field where Y = type W, else N ---
SELECT CUST.CUSTOMER_ID, TX.TX_DATE, TX.TX_VALUEA, TX.TX_VALUEB, CUST.CUST_MOD_DATE, TX.TX_TYPE,
CASE WHEN NVL(TX.TX_TYPE,'0') <> 'W' THEN 'N'
WHEN NVL(TX.TX_TYPE,'0') = 'W' THEN 'Y'
ELSE 'N'
END AS TYPE_FLAG
FROM TMP_TRANSACTION TX, TMP_CUSTOMER CUST
WHERE TX.CUSTOMER_ID = CUST.CUSTOMER_ID
AND CUST.CUSTOMER_ID in
'10','20'
) TRANS
WHERE CUST.CUSTOMER_ID = TRANS.CUSTOMER_ID
--AND TRANS.TX_DATE <= CUST.CUST_MOD_DATE
AND CUST.CUSTOMER_ID in
('10','20'
Can anyone please help with how I extract the record I am looking for
ie customer 10 has amount 90
customer 20 has amount 50.
Thanks :-)
GBSQL> select c_id
2 , cust_mod_date
3 , tx_date
4 , tx_type
5 , tx_valuea
6 , tx_valueb
7 from ( select c.customer_id c_id
8 , c.cust_mod_date
9 , t.tx_date
10 , t.tx_type
11 , t.tx_valuea
12 , t.tx_valueb
13 , row_number() over (partition by c.customer_id order by t.customer_id, t.tx_date desc) rn
14 from tmp_customer c
15 , tmp_transaction t
16 where t.customer_id = c.customer_id
17 and t.tx_date <= c.cust_mod_date
18 )
19 where case
20 when tx_type = 'W' then 1
21 when rn = 1
22 and not exists ( select null
23 from tmp_transaction t2
24 where t2.customer_id = c_id
25 and t2.tx_type = 'W'
26 )
27 then 1
28 end = 1;
C_ID CUST_MOD_ TX_DATE T TX_VALUEA TX_VALUEB
10 15-JUL-09 14-JUL-09 A 100 90
20 15-JUL-09 14-JUL-09 W 50 20
2 rows selected. -
With a Custom Search portlet how to Sort the Result By Sequence. i.e. by respecting arrangements of the items in the page of contents?
Actually the Results Options "Order By" are : Create Date, Author, Creator, Date Updated, Display Name, Last Update by, Publish Date, Score.
Is there an action to add the "Sequence" Order By result Option?
Great thanks for your kind help.
Best regardsNo, I agree that it is functionality that should be added to the product, but it
is not a bug because it was not written to do this.
It is a short coming of the product.
Cheers,
Ersan -
How to return the name (or ID) of the Task FLow in Script
Sitaution; two task flows created which can be accessed via Tools > TaskFlows within FDQM
Task Flow "1.1 Multi Load - Import" --> Should run Batch Process Up to Import (enmBatchProcessLevel: 2)
Task Flow "2.1 Multi Load - Import Up To Validate" --> Should run Batch Process Up to Validate (enmBatchProcessLevel: 4)
I have developed one generic script which I would like to use for each task flow.
Only the enmBatchProcessLevel differs between the task flows and therefore I would like to parse this enmBatchProcessLevel as a parameter my generic script.
To be able to do this, the script needs to know on which task flow a user has clicked. So, I am looking for a function or statement which returns the name (or ID) of the task flow. Based on this name (or ID) a conditional statement can be performed in which a variable is dynamically filled. This variable can then be parsed as a parameter to my generic script.
For instance:
Sub GenericRoutine
Dim strTaskFlow
Dim intBatchProcessLevel
'--Get the Task Flow Name
strTaskFlow = ......<How to return the TaskFlow name or ID?>
'--Validate the task flow and fill variable intBatchProcessLevel dynamically
Select Case strTaskFlow
Case "1.1 Multi Load - Import"
intBatchProcessLevel = 2
Case "2.1 Multi Load - Import Up To Validate"
intBatchProcessLevel = 4
End Select
'--Execute generic script
'--Call Batch script and parse intBatchProcessLevel as a parameter:
Call sBatchProcess(intBatchProcessLevel)
'--Execute generic script
End Sub
Sub sBatchProcess(Byval intBatchProcessLevel)
Dim lngProcessLevel
Dim strDelimiter
Dim blnAutoMapCorrect
'--Use intBatchProcessLevel to fill lngProcessLevel
lngProcessLevel = intBatchProcessLevel
strDelimiter = "_"
blnAutoMapCorrect = 0
Set BATCHENG.PcolFiles = BATCHENG.fFileCollectionCreate(CStr(strDelimiter))
BATCHENG.mFileCollectionProcess BATCHENG.PcolFiles, CLng(lngProcessLevel), , CBool(blnAutoMapCorrect)
End Sub
Edited by: user13642656 on Jul 21, 2011 4:55 AMHi, thanks for your reply.
The Generic script contains 600+ records, which I would like to maintain once, when having multiple Task Flows for Import, UpToValidate, ValidateOnly, UpToExport, ExportOnly etc.
Is there a central storage in FDQM workbench for script, like a "Module" in Excel VisualBasic environment? Thanks! -
Need HELP (Project Issue) : Having 3 individual VIs, datalogger.vi, start vi, amksms.vi done.
(How to run the VIs in sequence order - datalogger > start > amksms combine into 1 VIs? )VIs in icon.
how would it able to run in the sequence order:
data first, follow by start and lastly amk sms.
Attachments:
dsa.jpg 10 KB -
How to check the Statistics generated for a table through DBMS_STATS.
Hi,
How to check the statistics generated for a Table through DBMS_STATS.GATHER_TABLE_STATS procedure ?
Please let me know.
Thanks !
Regards,
RajasekharRajasekhar wrote:
Hi,
How to check the statistics generated for a Table through DBMS_STATS.GATHER_TABLE_STATS procedure ?
Please let me know.
Thanks !
Regards,
Rajasekharquery ALL_TABLES -
Customer request: With a Custom Search portlet how to Sort the Result By Sequence. i.e. by respecting arrangements of the items in the page of contents?
(Like it's possible in MyOracle)
Actually the Results Options "Order By" are : Create Date, Author, Creator, Date Updated, Display Name, Last Update by, Publish Date, Score.
Is there an action to add the "Sequence" Order By result Option?
Great thanks for your kind help.
Best regardsNo, I agree that it is functionality that should be added to the product, but it
is not a bug because it was not written to do this.
It is a short coming of the product.
Cheers,
Ersan -
As a newcomer to the iPad, can you please tell me how to return the font size to standard. Somehow I've enlarged the font size until it's unreadable and it applies to the icons as well! Many thanks in anticipation.
Try this:
Settings>General>Accessibility>Zoom>Off -
How to find out newly generated Task Id in Sequential WorkFlow
I have following scenario...
Have a replicator activity to create multiple tasks
However I dont want to send OOB notifications. So I have added Sedmail.
Challange is to know the newly generated task Id after the create task execution. Note that Replicator exectutes create task number of times of count in InitData object.
Also I can not use OnTaskCreated activity as it has issues working with replicator...
Any Solutions?Got the solution. Here is it...
In CreateTask go to Properties.
Click TaskItemId and click bind.
Bind it to a new property.
In this property setter, value will give you task Id.
This property setter is called every time a new task is created.
Generate Edit Task Link here and send email if you want. -
I urgently need to know how to run the code generator using creator. Can anyone assist? I cant find any tips in the forums.
I am following the procedure to create a new custom component (or extend an existing component) available at http://developers.sun.com/prodtech/javatools/jscreator/reference/techart/2/writing_custom_components.html.
Part of the procedure says: you need to use the JSC to run the code generator based on sun-faces-config.xml metadata.
Maybe you are looking for
-
Hello I am a MM Consultant and would like to post basic quey for FI people. We give the reconcillation acoount in The Vendor Master data.This account is same for every Vendor.This account is credited when we post Invoice via MIRO. So while taking a
-
I just reformatted the hard drive to FAT 32 re-installed it. Put in the mac os disc and the mac goes to a black screen and does nothing after a few minutes. Please help me!
-
Need step by step directions for moving itunes library to external HD
About to crash my PC...recently purchased apple tv and kids have bought many movies and tv shows. They are filling my hard drive - between movies, tv and music I have 756 GB. Searching the problem on this board, i think eternal HD is solution. Can so
-
401 Unauthorized & 489 Bad Event - 'Malformed/Unsupported Event'
Good Morning All, I am getting these two errors and I am trying to figure what is the issue. Seeing if someone has ran into this issue.
-
How to make call reject?
I have CallManager 4.2 and I want to make call reject functionality when the phone is on-hook and ringing. There is only answear and iDivert softkeys in this mode. It is possible to make iDivert to invalid number but I'm looking for more elegant solu