Thursday, June 28, 2012

%ROWTYPE


This was tested on Oracle 11.2. You can use %ROWTYPE to declare a record with the same structure as a row from a database table:

SQL> DECLARE
  2   OBJECT_DETAIL DBA_OBJECTS%ROWTYPE;
  3  BEGIN
  4   SELECT *
  5    INTO OBJECT_DETAIL
  6    FROM DBA_OBJECTS
  7    WHERE OBJECT_ID =
  8    (SELECT MIN(OBJECT_ID) FROM DBA_OBJECTS);
  9   DBMS_OUTPUT.PUT_LINE
10   ('OWNER = '||OBJECT_DETAIL.OWNER);
11   DBMS_OUTPUT.PUT_LINE
12   ('OBJECT_NAME = '||OBJECT_DETAIL.OBJECT_NAME);
13   DBMS_OUTPUT.PUT_LINE
14   ('OBJECT_ID = '||OBJECT_DETAIL.OBJECT_ID);
15  END;
16  /
OWNER = SYS
OBJECT_NAME = C_OBJ#
OBJECT_ID = 2

PL/SQL procedure successfully completed.

SQL>

No comments:

Post a Comment