Home > database >  How to return after the Oracle database UPDATE statement execution change record's primary key
How to return after the Oracle database UPDATE statement execution change record's primary key

Time:09-30

RT
Eg: has the following form
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Id name status
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Test1 1
2 test2 1
3 test2 1
4 test2 1
5 test2 1
6 test2 1
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - line -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
The following for the SQL statement
The UPDATE TABNAME SET name='zhangsan' WHERE the status=1
Affect the number of lines after the above statement is executed for six lines, now want to ask you a great god, how can you get this 6 lines of the primary key ID (6)
Thanked everybody first

CodePudding user response:

By the way, in the case of not use stored procedures, SQL statements can be fulfilled only??

CodePudding user response:

Select the id from TABNAME WHERE status=1 and name<> 'zhangsan' this is the need to change the record

CodePudding user response:

refer to the second floor www1990xxx response:
select id from TABNAME WHERE status=1 and name<> "Zhangsan" this is the need to change the record

So not is have to only have to execute a query SQL update, if high concurrency, use the value of the modified in such as query condition will be out of the question

CodePudding user response:

Top it..

CodePudding user response:

Do you want an update performed can also return the records, to display the record or have to select, and query first, then update, or after the query result set is inserted into the table, then the update operation

CodePudding user response:

Query out to update the data inserted into a table to store, this process can be put into the trigger

CodePudding user response:

The top 666666

CodePudding user response:

 
SQL>
SQL> Create table test (int id, name varchar (10));
The Table created
SQL> The begin
2 insert into the test values (1, "aaa");
3 the insert into the test values (2, "BBB");
4 the insert into the test values (3, "CCC");
5 the insert into the test values (4, "DDD");
6 the end;
7/
PL/SQL procedure successfully completed
SQL> The set serverout on;
SQL> Declare
2 type tlist is table of integer index by pls_integer;
3 l tlist;
4 v_id varchar (10);
5 the begin
6, update the test set name=name | | 'XXX' returning id bulk collect into l;
7 for x in 1.. L.c mount loop
8 dbms_output. Put_line (l (x));
9 end loop;
10 the end;
11/
1
2
3
4
PL/SQL procedure successfully completed
SQL> Drop table test purge;
Table dropped

SQL>
  • Related