Search notes:

Oracle SQL: UPDATE … RETURNING INTO …

create table tq84_returning_into (
   a   number,
   b   varchar2(10)
);

insert into tq84_returning_into values (null, null);
insert into tq84_returning_into values (   1,'one');
insert into tq84_returning_into values (null,'two');
insert into tq84_returning_into values (   3, null);

declare
  aa    number;
begin

  update tq84_returning_into
     set a = coalesce(a, 5)  --   a = 1, so
   where b = 'one'           --   aa gets the value 1
  RETURNING a INTO aa;       --

  dbms_output.put_line(aa);

  update tq84_returning_into
     set a = coalesce(a, 7)  --   a is null, so
   where b = 'two'           --   aa get the value 7
  RETURNING a INTO aa;

  dbms_output.put_line(aa);


end;
/


drop table tq84_returning_into purge;
Github repository Oracle-Patterns, path: /SQL/update/returning_into.sql

See also

Oracle PL/SQL: RETURNING INTO clause

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1759430679, '216.73.216.42', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/SQL/DML/update/returning-into/index(71): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78