If you want to define a variable that has a type that is consistent with the data type of a variable or a column in a database table, you can use%type to implement it.
If you want to define a variable of a record type that is consistent with a table structure in the database, you can use%rowtype.
Example of a table under the default test user Scott
Note: If the installation is not unlocked, you can log in with SYS and execute the UNLOCK statement: Alter user Scott account unlock;
1 DECLARE2V_ename Emp.ename%TYPE;3V_emp EMP%ROWTYPE;4 BEGIN5 SELECTEname intoV_ename fromEmpWHEREEmpno= 7369;6 SELECT * intoV_emp fromEmpWHEREEmpno= 7499;7 Dbms_output.put_line (v_ename);8Dbms_output.put_line (v_emp.empno||' '||V_emp.ename||' '||v_emp.job);9 END;
Output Result:
SMITH
7499 ALLEN Salesman
Note: Using the Oracle-brought SQL Developer tool using Dbms_output.put_line may have no output, execute SET serveroutput on; Re-run the anonymous block above.
ORACLE%type and%rowtype