简体   繁体   中英

Change the value of a column in previous row and the current row whenever a new row is inserted in PLSQL

lets say the table name is abc and **columns are name varchar(20) and status varchar(1) ,** status can be either 'y' or 'n' on insertion of each new row the status value of the new row must be set to 'y' and the status value of previous row has to be set to 'n'. Please guide me with a solution for this problem

Since you are using pl/sql, you can fire a pre update statement. So before loading into the table, issue this

sql_stmnt= 'UPDATE table SET status=''n'' WHERE status =''y''';
EXECUTE IMMEDIATE sql_stmnt;
commit;
EXECUTE IMMEDIATE 'INSERT INTO...'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM