--Reference variable--open Oracle output--set serveroutput ondeclare -Define reference variable, query and print 1232 name and salary --pename varchar2 (20);-- These 2 sentences and the following 2 sentence effect consistent --psal number; Pename Emp.ename%type; Psal emp.sal%type;begin --get 1232 of the name and salary- -the way to assign the value is: = and into select Ename,sal to pename,psal from EMP where empno=122; --Print name and salary dbms_output.put_line (pename| | ' The salary is ' | | PSAL); end;/
Example of a record-type variable program:
--Record type variable: Take the type of a row in a table as the type of the variable--you can interpret the record variable as an array, and each element in the array represents each column--REC is the shorthand for the record, row is the row, type is the kind, and the row type--Emp_rec emp% rowtype;--the reference of the variable component of record type--emp_rec.ename:= ' ADAMS '; --Use record variables to query and print 123 of the name and salary--set Serveroutput on declare --Define the record type variable: note represents a row Emp_rec emp%rowtype; begin -- Get 1231 lines of information select * into Emp_rec from EMP where empno=123; --Print name and salary dbms_output.put_line (emp_rec.ename| | ' The salary is ' | | Emp_rec.sal); End; --/
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Examples of Oracle's reference and record-based variable programs