DECLARE
   v_sal emp.sal%TYPE;
BEGIN
   SELECT sal
   INTO v_sal
   FROM emp
   WHERE empno = 7369;
  :salary    := v_sal;
END;

解决方案 »

  1.   


    C:\Users\thinkpad-zph>sqlplus scott/tigerSQL*Plus: Release 10.2.0.1.0 - Production on 星期四 11月 17 14:39:43 2011Copyright (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>