日期:2014-05-16  浏览次数:20719 次

下面这段代码的:salary是不是在这个块外面也是有效的?
DECLARE
  v_sal emp.sal%TYPE;
BEGIN
  SELECT sal
  INTO v_sal
  FROM emp
  WHERE empno = 7369;
  :salary := v_sal;
END;

------解决方案--------------------
SQL code

C:\Users\thinkpad-zph>sqlplus scott/tiger

SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 11月 17 14:39:43 2011

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

[SCOTT@myoracle] SQL>var salary number;
[SCOTT@myoracle] SQL>DECLARE
  2    v_sal emp.sal%TYPE;
  3  BEGIN
  4    SELECT sal
  5    INTO v_sal
  6    FROM emp
  7    WHERE empno = 7369;
  8    :salary := v_sal;
  9  END;
 10  /

PL/SQL 过程已成功完成。

[SCOTT@myoracle] SQL>print salary

    SALARY
----------
       800

[SCOTT@myoracle] SQL>