Oracle (og PostgreSQL) har:
- %TYPE
- %ROWTYPE
%TYPE
%TYPE
bruges til at erklære variable i forhold til datatypen for en kolonne i en eksisterende tabel:
DECLARE v_id ORDERS.ORDER_ID%TYPE
Fordelen her er, at hvis datatypen ændres, forbliver den variable datatype synkroniseret.
Reference:http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/fundamentals.htm#i6080
%ROWTYPE
Dette bruges i markører til at erklære en enkelt variabel til at indeholde en enkelt post fra resultatsættet af en markør eller tabel uden at skulle specificere individuelle variabler (og deres datatyper). Eks:
DECLARE
CURSOR c1 IS
SELECT last_name, salary, hire_date, job_id
FROM employees
WHERE employee_id = 120;
-- declare record variable that represents a row fetched from the employees table
employee_rec c1%ROWTYPE;
BEGIN
-- open the explicit cursor and use it to fetch data into employee_rec
OPEN c1;
FETCH c1 INTO employee_rec;
DBMS_OUTPUT.PUT_LINE('Employee name: ' || employee_rec.last_name);
END;
/