日期:2014-05-17 浏览次数:22294 次
--select * into A from B --*代表b表中的所有行的记录,即多条记录 --如果你要获取统计记录(单条记录),可以如下写: SQL> set serveroutput on; SQL> declare 2 x number(2); 3 begin 4 select count(*) into x 5 from emp 6 where deptno=30; 7 8 dbms_output.put_line('The number of department 30 employees are :'||x); 9 end; 10 / The number of department 30 employees are :6 PL/SQL procedure successfully completed ----------------- --如果你想获得多条记录,可以用游标返回多条记录: SQL> declare 2 cursor x is 3 select ename,deptno,job,sal 4 from emp; 5 begin 6 for v_emp in x 7 loop 8 dbms_output.put_line( 9 'ename= '||v_emp.ename|| 10 ', deptno= '||v_emp.deptno|| 11 ', job= '||v_emp.job|| 12 ', sal= '||v_emp.sal 13 ); 14 end loop; 15 end; 16 / ename= SMITH, deptno= 20, job= CLERK, sal= 800 ename= ALLEN, deptno= 30, job= SALESMAN, sal= 1600 ename= WARD, deptno= 30, job= SALESMAN, sal= 1250 ename= JONES, deptno= 20, job= MANAGER, sal= 2975 ename= MARTIN, deptno= 30, job= SALESMAN, sal= 1250 ename= BLAKE, deptno= 30, job= MANAGER, sal= 2850 ename= CLARK, deptno= 10, job= MANAGER, sal= 2450 ename= SCOTT, deptno= 20, job= ANALYST, sal= 3100 ename= KING, deptno= 10, job= PRESIDENT, sal= 5000 ename= TURNER, deptno= 30, job= SALESMAN, sal= 1500 ename= ADAMS, deptno= 20, job= CLERK, sal= 1100 ename= JAMES, deptno= 30, job= CLERK, sal= 950 ename= FORD, deptno= 20, job= ANALYST, sal= 3000 ename= MILLER, deptno= 10, job= CLERK, sal= 1300