You can use the scott password triger, an existing Oracle account, to log in and use the existing table to perform the test.
- Create or replace procedure lpmtest2
- As
- Para1 varchar2 (10);
- Cursor youbiao is select ename from test where sal>1300;
- Begin
- Open youbiao;
- Loop
- Fetch youbiao into para1;
- Exit when youbiao % notfound;
- Dbms_output.put_line ('++ :'| Para1 );
- End loop;
- Close youbiao;
- End;
Code
- Create or replace procedure lpmtest2
- As
- Cursor youbiao is select ename, sal, job from test where sal>1300;
- C_row youbiao % rowtype; -- defines a cursor variable c_row, which is the data type of a row in youbiao.
- Begin
- Open youbiao;
- Loop
- Fetch youbiao into c_row;
- Exit when youbiao % notfound;
- Dbms_output.put_line ('++ :'| C_row.ename |':'| C_row.sal |':'| C_row.job );
- End loop;
- Close youbiao;
- End;
Code
- Create or replace procedure lpmtest3
- As
- Cursor c_dept is select * from dept order by deptno;
- Cursor c_emp (p_dept varchar2) is select ename, sal from emp where deptno = p_dept order by ename;
- R_dept c_dept % rowtype;
- V_ename emp. ename % type;
- V_sal emp. sal % type;
- V_totalsal emp. sal % type; -- used to save the total salary of all employees in each department
- Begin
- Open c_dept;
- Loop
- Fetch c_dept into r_dept;
- Exit when c_dept % notfound;
- Dbms_output.put_line (r_dept.deptno |':'| R_dept.dname |'++');
- V_totalsal: =0;
- Open c_emp (r_dept.deptno );
- Loop
- Fetch c_emp into v_ename, v_sal;
- Exit when c_emp % notfound;
- Dbms_output.put_line ('V _ ename :'| V_ename |';'|'V _ sal :'| V_sal );
- V_totalsal: = v_totalsal + v_sal;
- End loop;
- Close c_emp;
- Dbms_output.put_line ('Depsaltotal :'| V_totalsal );
- End loop;
- Close c_dept;
- End;
Print the result:
- 10: ACCOUNTING ++
- V_ename: CLARK; v_sal:2450
- V_ename: KING; v_sal:5000
- V_ename: MILLER; v_sal:1300
- Deptsaltotal:8750
- 20: RESEARCH ++
- V_ename: ADAMS; v_sal:1100
- V_ename: FORD; v_sal:3000
- V_ename: JONES; v_sal:2975
- V_ename: SCOTT; v_sal:3000
- V_ename: SMITH; v_sal:800
- Deptsaltotal:10875
- 30: SALES ++
- V_ename: ALLEN; v_sal:1600
- V_ename: BLAKE; v_sal:2850
- V_ename: JAMES; v_sal:950
- V_ename: MARTIN; v_sal:1250
- V_ename: TURNER; v_sal:1500
- V_ename: WARD; v_sal:1250
- Deptsaltotal:9400
- 40: OPERATIONS ++
- Deptsaltotal:0
For more information about Oracle, see Oracle topics page http://www.bkjia.com/topicnews.aspx? Tid = 12