Oracle PL/SQL reference variable

a grammar

my_name emp.ename%type;
Indicates that the data type of my_name is consistent with the data type of the ename field in the emp table.
 
two code
  1. --引用型变量
  2. set serverout on
  3. declare
  4. --定义引用型变量:查询并打印7839的姓名和薪水
  5. --pname varchar2(20);
  6. --psal number;
  7. pname emp.ename%type;
  8. psal emp.sal%type;
  9. begin
  10. --得到7839的姓名和薪水
  11. select ename,sal into pname,psal from emp where EMPNO =7839;
  12. --打印姓名和薪水
  13. DBMS_OUTPUT.put_line(pname||'的薪水是'||psal);
  14. end;
  15. /
 
Three running results
King's salary is 5000
 
PL/SQL procedure completed successfully.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326193135&siteId=291194637