Oracle PL/SQL - Assigning values in a record


To assign values to a record, fetch data from the cursor.

A second method is to use a RETURNING INTO clause.


SQL> drop table emp;

Table dropped.-- from   www . jav a2  s.c  om

SQL> create table emp(
  2    empno    number(4,0),
  3    ename    varchar2(10),
  4    job      varchar2(9),
  5    mgr      number(4,0),
  6    hiredate date,
  7    sal      number(7,2),
  8    comm     number(7,2),
  9    deptno   number(2,0)
 10  );

Table created.
SQL> insert into emp values(7369, 'KING', 'PRESIDENT', null, to_date('17-11-1981','dd-mm-yyyy'), 5000, null, 10);
SQL> insert into emp values(7698, 'BLAKE', 'MANAGER', 7839,to_date('1-5-1981','dd-mm-yyyy'), 2850, null, 30);
SQL> declare
  2       type emp_ty is record (emp_tx VARCHAR2(256),deptNo emp.deptno%TYPE);
  3       v_emp_rty emp_ty;
  4  begin
  5       update emp set eName=eName||'*'
  6       where empNo=7369
  7       returning empNo||' '||eName, deptNo
  8       into v_emp_rty;
  9       DBMS_OUTPUT.put_line('Updated: '||v_emp_rty.emp_tx||' ('||v_emp_rty.deptNo||')');
 10  end;
 11  /
Updated: 7369 KING* (10)

PL/SQL procedure successfully completed.

Related Topic