Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating a table with record type object

Tags:

oracle

plsql

I have a table say EMPLOYER with EMPLOYER_ID as the primary key. I write the following script to update a row in the table:

declare
    emp_row EMPLOYER%ROWTYPE;
begin
    select * into emp_row from EMPLOYER where rownum <= 1;
    emp_row.NAME := 'ABC';
    emp_row.AGE  := 99;
    -- Can I write something like below?
    update EMPLOYER set ??? = emp_row where EMPLOYER_ID = emp_row.EMPLOYER_ID;
end;

Can I update a row with a record type object in a single statement? Just as shown in the example above.

like image 958
Dicky Ho Avatar asked Aug 30 '16 07:08

Dicky Ho


1 Answers

Please try something like this

update EMPLOYER set ROW = emp_row where EMPLOYER_ID = emp_row.EMPLOYER_ID;

Remember: this UPDATE sets the value of every column in the table, including your primary key, so you should use the SET ROW syntax with great care.

like image 166
Sarath Vemuri Avatar answered Sep 30 '22 20:09

Sarath Vemuri