Re: UPDATE and SELECT in one statement



BMA wrote:
Hello,

I'm a bit brainwashed by the SQL Server Programming dialect...

I'm trying to update a column in a table, and immediatly do a select of
that column in one statement.

So, as I'm used to in SQL Server, i'd do :

UPDATE myTable SET col=(select col+1 from otherTable) where recordnr=2
SELECT col from myTable where recordnr=2

This is a statement I send in one command to the database server, and
is used to increment a sequence number for calculating unique invoice
numbers. THis way, there cannot be any multi-user interference, so nobody
generates the same invoice number.

This works for SQL Server 2000/2005, but when testing on Oracle I get : ORA-00933 : SQL-command is not ended correct (roughly translated from
dutch right now).

I'm sending this statement from Omnis Studio on a windows XP SP 2 to an
Oracle 9i Personnal Edition.

Is it possible to send an update and a select in one statement?

Thanks for any help (and sorry for my bad English ...)

Bram

Completely unnecessary in Oracle ... it is easily done in a single statement. There is a demo in Morgan's Library (www.psoug.org) under
UPDATE. Search for "RETURNING CLAUSE."

Here's a simple example that returns multiple columns:

conn hr/hr

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;

print bnd1
print bnd2
print bnd3

bnd1, 2, and 3, in PL/SQL, are variables.

The RETURNING CLAUSE can also be used with INSERTs and DELETEs.
--
Daniel A. Morgan
University of Washington
damorgan@xxxxxxxxxxxxxxxx (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org
.



Relevant Pages

  • Re: IOT, memory and transaction time
    ... easily generate it with DBMS_METADATA.GET_DDL if your verison of Oracle ... were pretty consistent no matter how big the table (this transaction ... FOREIGN KEY (versionNo) REFERENCES T_TRANSACTIONS, ... Oracle provides read consistency and SQL Server ...
    (comp.databases.oracle.misc)
  • Re: Database or store to handle 30 Mb/sec and 40,000 inserts/sec
    ... "Writers block readers and readers block writers in SQLServer. ... getting around this fundamental issue and because of it SQL Server ... admitted they can happen in Oracle, I guess Oracle should never been used ... isolation level but you will always disagree because you follow doctorine ...
    (comp.databases.oracle.server)
  • Re: IOT, memory and transaction time
    ... easily generate it with DBMS_METADATA.GET_DDL if your verison of Oracle ... If it was the update statement that references ... FOREIGN KEY (versionNo) REFERENCES T_TRANSACTIONS, ... There are however differences how both products deal with concurrency; in Oracle readers don't get blocked while this may happen in SQL Server. ...
    (comp.databases.oracle.misc)
  • Re: Import problems on Windows Server
    ... XP is fine, so is Vista, like you I use them day in day out, around 12 hours ... a day myself too - laptops and the desktop i'm writing this on. ... I use SQL Server on XP and Vista for writing and demo'ing stuff, ... those are the same problems in the Oracle world. ...
    (comp.databases.oracle.server)
  • Re: command line vs grid control
    ... have Oracle on-site for their line-of-business applications. ... customers that Oracle(all of its products not just the RDBMS) run on ... SQL Server where appropriate. ... Written any shell scripts in Windows to ...
    (comp.databases.oracle.server)