This shows you the differences between two versions of the page.
rowtype-attribute [2015/09/23 20:27] |
rowtype-attribute [2015/09/23 20:27] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== %ROWTYPE Attribute ====== | ||
+ | %ROWTYPE attribute lets you declare a record variable that has the same columns and data types as the specified database table. | ||
+ | |||
+ | **Syntax**: | ||
+ | |||
+ | <code language=sql> | ||
+ | var_name [schema.]table_name%ROWTYPE | ||
+ | </code> | ||
+ | |||
+ | **Examples:** | ||
+ | |||
+ | <code language=sql> | ||
+ | DECLARE | ||
+ | v orders%ROWTYPE; | ||
+ | BEGIN | ||
+ | SELECT * INTO v FROM orders LIMIT 1; | ||
+ | DBMS_OUTPUT.PUT_LINE('Item: ' || v.name || ' - ' || v.description); | ||
+ | END; | ||
+ | </code> | ||
+ | |||
+ | <code language=sql> | ||
+ | DECLARE | ||
+ | v orders%ROWTYPE; | ||
+ | CURSOR c IS SELECT * FROM orders; | ||
+ | BEGIN | ||
+ | OPEN c1; | ||
+ | FETCH c1 INTO v1; | ||
+ | DBMS_OUTPUT.PUT_LINE('Item: ' || v.name || ' - ' || v.description); | ||
+ | CLOSE c1; | ||
+ | END; | ||
+ | </code> | ||
+ | |||
+ | <code language=sql> | ||
+ | BEGIN | ||
+ | FOR v IN (SELECT * FROM orders) | ||
+ | LOOP | ||
+ | DBMS_OUTPUT.PUT_LINE('Item: ' || v.name || ' - ' || v.description); | ||
+ | END LOOP; | ||
+ | END; | ||
+ | </code> | ||
+ | |||
+ | <code language=sql> | ||
+ | DECLARE | ||
+ | v orders%ROWTYPE; | ||
+ | BEGIN | ||
+ | EXECUTE IMMEDIATE 'SELECT * FROM orders LIMIT 1' INTO v; | ||
+ | DBMS_OUTPUT.PUT_LINE('Item: ' || v.name || ' - ' || v.description); | ||
+ | END; | ||
+ | </code> | ||
+ | |||
+ | **Compatibility:** Oracle | ||
+ | |||
+ | **Version:** HPL/SQL 0.3.13 |