Combine select and update into single statement,without bind-variable

I have a problem, that I think is not possible to solve the way I want to, but I just wanted to check before leaving the idea...
I am looking for a way to combine the select and the update statement into one single statement. This is what I wan't to achive: select some data, and update the data selected before returning them.
On this site http://www.psoug.org/reference/update.html I see that the following are possible:
var bnd1 NUMBER
var bnd2 VARCHAR2(30)
var bnd3 NUMBER
UPDATE employees
SET job_id ='SA_MAN', salary = salary + 1000,
department_id = 140
WHERE last_name = 'Jones'
RETURNING salary*0.25, last_name, department_id
INTO :bnd1, :bnd2, :bnd3;
I need to have this as a single statement, and cannot use bind-variables. So I was hoping that something like this could be possible:
UPDATE customer c
SET c.HAS_CREDIT ='1'
WHERE c.HAS_CREDIT = '0'
RETURNING c.CUSTOMER_NO, c.FIRSTNAME, c.LASTNAME
where c.HAS_CREDIT = '1'
But this doesn't compile, complaining of missing into (ORA-00925: missing INTO keyword). And even though I would like this to be possible because this would solve my current problem, I think it would be very confusing. For instance; would the where clause of the returning part be operating after the update or before?
Any comments or suggestions on how to get it work in a single statement, or should I just leave this path straight away?

Hi,
RETURNING only works with bind variables, see
http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14261/returninginto_clause.htm#sthref3006
The real problem is that the form of RETURNING clause with bind variables is only valid for single row update or insert statements.
To update (or insert) multiple rows and return the data, you will need to use
RETURNING BULK COLLECT INTO clause. See
http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14261/tuning.htm#sthref2236
Cheers,
Colin

Similar Messages

  • Can I use a select and update statement in a single jsp file?

    I want to update the BUY table everytime I would add a SELL transaction.....I want to minus the stocks that I sold to those that Ive bought before.....
    note: I used a seperate table in BUY and SELL transaction
    After I Have added a transaction, I want to update the buy table. This is my problem, can I used both SELECT and UPDATE statement at the same time in a single jsp file for example like this:
    select * from test, test1;
    update test
    set total_shares=total_shares-Stotal;
    where stock_code=Scode AND name_broker=Sbroker;
    Can i have both of these statements in the same jsp file in oder to update the buy table?
    Or can anyone suggest how can process that update?THANKS!
    --------------------

    Can i have both of these statements in the same jsp file in oder to update the buy table?Yes. But wouldn't it have been easier just to try it?

  • Select and update in same instruction

    Can i select and update a column in table by one query only
    I donot want to execute two queries one for updation and one for retrieval
    e.g. instead of UPDATE t1 set val=val+1 and then SELECT val from t1;
    i wanna have a single query (compliant to mysql and ORACLE)
    because when i passa query UPDATE t1 set val=val+1; SELECT val from t1; on the command prompt is is fine but when i do so through jdbc it gives me errror
    please help

    Why would a stored procedure change anything?
    The stored procedure would have the UPDATE ... ; SELECT sequence in it.
    Which results in the same "work" the database has to do, compared to sending the two statements via JDBC.
    The only thing that a stored procedure would save, is the second JDBC call, but I doubt that this makes a big difference (provided this is not done in a loop. Then I'd retrieve the new values in one statement after all the updates have been committed)
    So I would simply do Statement statement = connection.createStatement();
    int rows = statement.executeUpdate("UPDATE ....");
    ResultSet rs = statement.executeQuery("SELECT ... ");
    String val = null;
    if (rs.next()) val = rs.getString(1);
    rs.close();The code for the stored procedure would look very similar to this with the disadvantage that that you have to maintain it for every DBMS that has to be supported.

  • JDBC Sender - Different number of records selected and updated.

    Hi people,
    We have a JDBC -> Abap proxy scenario. The JDBC sender is pooling an Oracle database to retrieve data from a table X, each 30 minutes. The select and update statements in jdbc sender are below
    SELECT FIELD1, FIELD2, FIELD3 FROM MY_TABLE WHERE STATUS = 1
    UPDATE MY_TABLE SET STATUS = 2 WHERE STATUS = 1
    Sometimes the message sent to Abap proxy has, for example, 400 records. Looking at runtime workbench, message monitoring, for the same message there is a log like this
    Channel SENDER_JDBC_CHANNEL: Query executed successfully. Start update
    Channel SENDER_JDBC_CHANNEL: 510 row(s) updated successfully
    Someone has already experienced something like this? How can I handle this to guarantee to update only those read records?
    regards.
    roberti

    Hi All,
    Even we are facing the same problem.
    In our scenario, receiver is SAPR3. (IDOC)
    Will this parameter serialization work in our case?
    1. SELECT XBLNR, WERKS, MATNR, MDV01, BACKFLQUANT, STATUS, SAPTIMESTAMP, PITSTIMESTAMP, PMTIMESTAMP, BATCH FROM PMBPITS.PITS_UNITY WHERE STATUS = '01' and rownum<200 . 
    2. UPDATE PMBPITS.PITS_UNITY SET STATUS = '02' , SAPTIMESTAMP = sysdate WHERE STATUS = '01' and rownum<200  ( currently the value is rownum < 5 )
    Thanks!!
    Regards
    Gouri

  • How to convert select-options table into single field internal table

    Hi,
    My requirement is to convert select-options table into single internal table which has one field.
    e.g. select-options: s_matnr for mara-matnr.
           select-options table can have options  'BT',"EQ", "NE", "GE", "GT", "LE", "LT", "CP" etc. select-options table
           have   Sign:I ,Option:BT, Low: 1, High.10.The new internal table records should be 1,2,3,4,5,6,7,8,9,10.
    Please suggest any function module available for this scenario in SAP.
    Thanks,
    Somi.
    Edited by: somi reddy satti on Sep 15, 2009 3:18 PM

    Hi Sowmya,
    Here is the answer if I understand well of your question.
    Data: begin of gt_mon OCCURS 0,
                  mon(2)             TYPE n,
             end of gt_mon.
    Data: begin of gt_year OCCURS 0,
                  year(4)             TYPE n,
             end of gt_year.
    Select-options: s_period       FOR ptdw_pws_db-kmonth NO-EXTENSION
                                                                                    DEFAULT sy-datum(6)
                                                                                    TO sy-datum(6).
    For example according to above statement period is 201110 is 201201.
    Period field does n't exists in SAP for selection. If your selection is on date based on period which is given on the selection-screen then you need to convert the period to date by concatenating ( or using FM to convert )01 at the end of each period . You need to declare one range table for date to select the data from table.
    loop at s_period.
    gr_date-sign   = s_period-sign.
    gr_date-option = s_period-option.
    COncatenate s_period-low
                          '01'
    into gr_date-high.
    COncatenate s_period-high                   
                           '01'
    into gr_date-low
    append gr_date.                      
    ENDloop.
    Thanks,
    Satheesh

  • HT1414 How do i restore and update my iphone 4S without losing all of my photos and videos and contacts?

    how do i restore and update my iphone 4S without losing my contacts photos and videos??

    Use the device as designed.
    Pictures and videos taken with the device are designed to be regularly copied off the device to a computer.
    Contacts are designed to be synced to a supported application on the computer or a cloud service.
    Media should exist in iTunes on the computer.
    If the device has been used as designed then at most, only a miniscule amount of data is at risk.  That data being pics/vids taken since the last time they were copied off the device.  Also at risk is app data created since the last backup to iTunes or iCloud.
    If the device is in recovery mode and it has not been used as designed, it is too late to salvage the data.
    How to update iDevices

  • Hi, I have got three ipad minis which I would like to use in a business environment whereby the users can see and update a single calender.  Is this possible? Would they have to be run form one account?

    Hi, I have got three ipad minis which I would like to use in a business environment whereby the users can see and update a single calender.  Is this possible? Would they have to be run form one account?

    Drrhythm2 wrote:
    What's the best solution for this? I
    Copy the entire /Music/iTunes/ folder from her old compouter to /Music/ in her account on this new computer.

  • Is there an easy way to delete complete albums instead of selecting and deleting each single foto?

    I am using an ipad 4 with IOS 8.0.2
    I am using the Standard "Photo" app
    Is there an easy way to delete complete albums instead of selecting and deleting each single photo? I want to reorganize the structure of my Pictures and delete lots of the photos and download new Pictures via iTunes Synchronisation.

    Go to Albums. Tap edit in the upper right corner. Tap the x. Tap done.

  • How to run a sql statement with bind variable in a test environment

    Hello,
    I have a sql statement in prod that I like to run in test. I got the sql statement from statspack, but the statement has bind variables. How do I get this statement to run in test? Thank you.

    Hi,
    If you have the SQL statement and all the referenced objects are available in your test env then what is the problem to run it?
    If I am not wront to get your reqmnt...
    i.e
    SQL> select * from emp
    where emp_no = &empno
    and dept_code = &deptcode;
    Thanks

  • Combine and simplify SELECT and UPDATE sql query

    foreach (BidList t in bidList)
    query = "SELECT operator_id, plot_id, status FROM booking " +
    "WHERE status='open' AND postcode='" + _plot + "' AND operator_id='0'" +
    "ORDER BY datetime ASC;" +
    "UPDATE booking SET operator_id='" + t.OperatorId + "', status='allocated' " +
    "WHERE (plot_id=" + t.PlotId + " AND operator_id='0' AND status='open') LIMIT 1;";
    dbObject.InsertBooking(query);
    I am cleaning up my code, and came across the above SQL query. Before I make use of SQL parameters, I wanted to ask if it is possible to combine them, and if so, how?

    Consider making a single long query using ‘;’ as a separator:
        query = "";
        foreach (BidList t in bidList)
            query += "UPDATE . . . ; ";
        dbObject.InsertBooking(query);
    Use StringBuilder for more improvements.

  • How to combine Submit and Commit into a single operation?

    JDev 11.1.1.6
    Is there a simple way to combine Submit and Commit or Create and Commit or Delete and Commit into a single operation without creating a custom Operation class?
    Thanks,
    PeeVee

    Have a button and in the action listener event..you should drag and drop both create & commit onto your page so that it will have the required bindings in the pagedef.
    OperationBinding createOperationBinding = ADFUtils.getOperationBindingForMethod("Create");
    createOperationBinding.execute();
    OperationBinding commitOperationBinding = ADFUtils.getOperationBindingForMethod("Commit");
    commitOperationBinding.execute();

  • Select and update with lock exclusive

    Hello Everybody
    In our application we have a table autonum     to handle unique keys for all other tables.
    In Autonum we have a column "SUCHBEGRIFF" char(40) unique KEY and a column "WERT" fixed(10,0).
    Suchbegriff has values like Rechnungsnr,Auftragsnr,Bestellnr ...
    Example:
    Befor inserting a record into table rechnungen we do:
    Select wert from autonun where suchbegriff = "Rechnungsnr" with lock exclusive.
    l_rechnrneu = wert + 1 
    update autonum set wert = ?l_rechnrneu where suchbegriff = "Rechnungsnr"
    commit
    (then l_rechnrneu is used for an insert into rechnungen command)
    This technic works for all tables (250) in our application.
    We have about 400 concurrent users working with maxdb 7.6 via odbc 7.6
    No problems since 2 years!
    Now we start some backgroundjobs from an xp-workstation.
    We have scheduled 5 jobs, starting every 5 minutes, same time.(Same user,same odbc-connection)
    Each job inserts records into a table joblogs and therefore needs a unique JOBLOGNR from autonum.
    Now we run into problems 2 or 3 times a day?
    <Sometimes the backgound jobs are running (waiting?) without inserting a record into joblogs (deadlock?)
    And more worse:
    Sometimes the insert into joblogs failes with "duplicate key" ??
    We don't know where to begin? Maxdb Problem ? Workstation problem?
    Any help welcomed
    Best regards
    Albert

    > >Gosh - that's information overloading at it's best...
    > We call this needed information.
    > What does our SAP-System? We have 1 mandt,60 accounting areas and about 200 werks!
    > Of course SAP uses internal unique keys for all tables, but we configured different "number intervals" for each werks.
    With "information overloading" I was referring to the multiple meanings you encode in just one column (your "rechnungs-no").
    SAP tables do not have this.
    As you wrote, there is "MANDT", "BUKRS", "WERKS" ... and the primary key is defined over all relevant columns.
    There is no primary key column where all the different meanings are concatenated together.
    So there aren't any surrogate keys here (a.k.a. AUTOID) used here - (ok except the infamous DDLOG sequence...).
    > >What do you do, when the value of an invoice has to be changed? Update the primary key of the table?
    > Update rechnungen set amount = xyz,...... where rechnungnr = nnn
    > We never change rechnungsnr,if the invoice was wrong we produce a credit for it and then write a new invoice
    So, you could use a sequence here instead as well.
    > > We don't use rollback when fetching logids from autonum.
    > >So what do you do, when connection fails, the database crashes or the client application hits an error?
    > >You use rollback. There is no way to avoid it.
    > >Your application gets a "duplicate key" error - the database performs a rollback of your last action. What does your application do then? Commit?
    > Sorry, i meant that we do not do rollbacks over  2 or 3 inserts or updates in different tables.
    > SQL-Command,On error = messagebox,errorlog,quit
    You don't handle the fetching of the new number in the same transaction as the actual insert of your application data in the same transaction?
    > >What isolation level do you use?
    > We use DATABASE ISOLATION LEVEL 0
    Hmm... did you read the documentation on SQL Locks?
    [Internals Course - SQL Locks|http://maxdb.sap.com/training/internals_7.6/locking_EN_76.pdf] :
    "Isolation level 0 does not offer any protection against access anomalies."
    Basically it might have happened that the same number is read twice.
    Perhaps the application is not always requiring locks when reading data from this table?
    > After connecting to the database via odbc we do
    > =SQLSETPROP(verbindungsnr,"Transactions",2)
    > 2 = Transaction processing is handled manually through SQLCOMMIT( ) and SQLROLLBACK( ). Read/write.
    > =SQLSETPROP(verbindungsnr,"DisconnectRollback",.T.)
    >
    >
    > So normal select commands are fired without a following commit.
    > Insert and update commands are fired with a following commit command.
    > Selects from autonum are fired with "look exclusive"
    Please be more detailed here.
    What is the exact sequence of actions here?
    1. Fetch number from number table and update number table.
    2. COMMIT
    3. Insert new application data with the just fetched number.
    4. COMMIT
    or
    1. Fetch number from number table and update number table.
    2. Insert new application data with the just fetched number.
    3. COMMIT
    And what does your application do with its data when a rollback occurs?
    Is it guaranteed that all variables are reset?
    > Nevertheless you dislike our design, do you think it would be better (quicker,safer...) to use an internal databases procedure to get
    > the next speaking number for a given "suchbegriff" from our autonum table? (no translation of the sql-command every time)
    No, currently we don't know what is causing the problem, so we cannot tell whether such a change would help. In fact, right now it would make things more complicated because we would less understand, what's happening here.
    Concerning your design: it's not about "liking" or "not liking it".
    I just pointed out some problems that result from the design as it is.
    > select   wert into :neuerwert FROM "BWPROGI"."AUTONUM"  WHERE upper(suchbegriff)     = upper(:suchkey) WITH LOCK EXCLUSIVE;
    > update  "BWPROGI"."AUTONUM" set wert = wert + 1 WHERE upper(suchbegriff)     = upper(:suchkey) ;
    > SET neuerwert = neuerwert + 1;
    > end;
    1. The WHERE clause UPPER(suchbegriff) = UPPER(...) is the best way to disable the efficient use of any index structure. Better make sure that your data is in the right format in the table when you enter it and then look it up without the UPPER() conversion. 
    2. I wouldn't perform the increment two times.
    Get the current value into your variable, increment this variable, set the current value in the table to the variable.
    > A char(10) return value would be nice and i don't know wether this would be the quicker way.
    Why should it? You would have to convert it first - that's additional work.
    Anyhow, to move ahead with your duplicate keys problem, you may perform a vtrace with the "stop on error" option.
    As your error is a duplicate key on a primary key constraint you should set "stop on error" to the error code "200".
    The next time your application hits the error, the vtrace automatically stops and we could examine what happened before.
    See [MaxDB database trace|https://wiki.sdn.sap.com/wiki/x/2yg] for details on how to activate the trace.
    When the error occurs next time and you caught it in the vtrace we can take a look at it.
    regards,
    Lars

  • Drag and Drop into Photoshop layer without resizing the source image

    Hello,
    I am using Photoshop CS5, 64bit, in Windows 7.
    I went through following steps and getting result that I do not want:
    1. Open an existing photopshop file.
    2. From the explorer window of my folder, select 100 png files and drag into the graphics area of the open photoshop image.
    Result: Photoshop resizes the png file and place it as a layer. It also asks me to commit the resizing for each individual file that I dragged and drop. Sometimes, it takes it as 100% scale, sometimes, 98%, sometimes 102%. If I change it to 100%, then it is not the original size. The image become larger and blurry.
    Expected Result: Place 200 png files as separate layer of the open photopshop without resizing it.
    My png files are icons that don't need resizing. I cannot tweak 200 images just to get this to the original dimension!
    Other things I tried:
    I turned off the "Preference->General->Resize Image During Place". I also turned off "Place or Drag Raster Images as Smart Objects".
    I still get the same result. I need nothing smart here. Just let me place images without any smart stuff!
    I also went to help and googled. I could not find what I need.
    Thank you!

    That works!!
    Thank you!

  • Select and update leave request data - oracle !!

    Dears,
    We have a very important presentation here to one of our stakeholders and he is interested to see how to submit and update leave requests using Adobe LiveCycle Workspace.
    I have a simple PDF form where the user can choose to submit new leave or update an existing one, if the user choses to update an existing leave he will enter the leave start date and press on a button to retrieve this leave information form the database ( select * from leaves where leave_date=’the entered date’ and requestor=’requestor name’) as requestor name and entered date are variables in the PDF, And then he can update the start date or leave duration and submit his request after updating this record in the database.
    Will you please help me how to do that knowing my PDF contains a digital signature and the data saved in a document variable?
    The connection with oracle created by updating the adobe-ds.xml file in “C:\Adobe\Adobe LiveCycle ES2\jboss\server\lc_turnkey\deploy” and deploying the ojdbc14.jar in “C:\Adobe\Adobe LiveCycle ES2\jboss\server\lc_turnkey\lib”.
    Database is oracle10.2.0.1.0
    Adobe LiveCycle Workbench ES2
    Version: 9.5.0.0.20100908.1.247189
    Many thanks in advanced,
    Mohammed Al-Mosleh

    I solved updating single row issue and retrieving single row from data base issue too ...
    I need an example, that shows us how to retrieve multiple records from a database, we did this, and DISPLAY, we couldn't, the results in a table within a pdf.
    the data stored in XML after using Query Multi Rows in XML Activity in Workbench...
    Can any one Help me how to Disply this XML in a table ??

  • Doing an insert and update in one statement.

    Hypothetical Situation:
    I have a table, this table has let say five rows and several thousand records. I want to take all the records where I take two of those rows with certain values in them, then duplicate those records that match the criteria and reinsert them onto the table. Afterwards, I want to change the same two values that I originally used to search for those records on the newly made duplicates and update the table to reflect the new changes.
    To Illistrate:
    Table Test:
    Rows:
    First Name
    Last Name
    Earnings
    Employment Date
    Rating
    Say I am looking for all records with earnings of 30,000 and a rating of B....duplicate those records and readd them to the table, then change the earnings of the duplicates to 40,000 and the rating to A.
    Any suggestions on how to approach this in as few of statements as possible (preferrably one statement)?
    Thanks In Advance.

    yep I ment columns, sorry for the confusion.
    Slightly straying now on this topic....After evaluation of what I needed, I'd come to the conclusion that my work would actually need something along the lines of an INSERT ALL or INSERT FIRST (TY Eric for putting me on the right track btw).
    Basically I'm going to need to do multiple value inserts into one statement, thus why this looks to be the right direction. So I typed it up, made sure it was fine and tried it....
    .....only one problem, ALL and FIRST are new to 9i....and I'm using 8.1.....doh >_<
    So, is there something simular to an INSERT ALL or INSERT FIRST that predates it that I can use in 8.1 and get the same effect (i.e. multiple insert changes in one statement)?
    Thanks again.

Maybe you are looking for