Oracle高级编程(存储过程)剖析.doc

Oracle高级编程(存储过程)剖析

Oracle高级编程SQL declare 2 v_ename varchar2(10); 3 v_rate_number number(7,2); 4 c_rate number(3,2):= 0.03; 5 v_sal number(7,2); 6 begin 7 select ename , sal into v_ename,v_sal from emp where empno = 员工号; 8 v_rate_number :=v_sal * c_rate; 9 dbms_output.put_line(姓名:||v_ename|| 工资:||v_sal||交税:||v_rate_number); 10 end; 11 / 姓名:SMITH工资:1400交税:42PL/SQL procedure successfully completed SQL declare 2 --创建一个游标类型 3 type demo_emp_cursor is ref cursor ; 4 --实例化一个demo_emp_cursor类型的对象 5 test_cursor demo_emp_cursor; 6 --定义变量 7 v_ename emp.ename%type; 8 v_sal emp.sal%type; 9 begin 10 --把游标加入SELECT语句中 11 open test_cursor for select ename , sal into v_ename,v_sal from emp; 12 --开始循环 13 Loop 14 --游标指向数据 15 fetch test_cursor into v_ename,v_sal; 16 exit when test_cursor%notfound ; 17 dbms_output.put_line(姓名:||v_ename|| 工资:||v_sal); 18 end loop; 19 close test_cursor; 20 end; 21 / 姓名:SMITH 工资:1400 姓名:ALLEN 工资:1600 姓名:WARD 工资:1250 姓名:JONES 工资:2975 姓名:MARTIN 工资:1250 姓名:BLAKE 工资:2850 姓名:CLARK 工资:2450 姓名:SCOTT 工资:3000 姓名:KING 工资:5000 姓名:TURNER 工资:1500 姓名:ADAMS 工资:1100 姓名:JAMES 工资:950 姓名:FORD 工资:3000 姓名:MILLER 工资:1300 Pl/sql提供了三种判断语句 1、if—then— 2、if—then—else 3、if—then--else If--else 编写一个存储过程输入员工号,如果该员工初始的工资小于1200,则给其增加10% SQL create or replace procedure if_test (v_empno varchar2) 2 is 3 v_sal emp.sal%type; 4 begin 5 select sal into v_sal from emp where empno = v_empno; 6 if 7 v_sal 1200 then 8 update emp set sal = sal * 1.1 where empno = v_empno; 9 end if; 10 end; 11 / Procedure created Java程序调用Procedure package com.test; import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DriverManager; public class testProcedure { /** * @param args * @author Xunaidong */ public static void main(String[] args) { try { Class.forName(oracle.jdbc.driver.OracleDriver); String url = jdbc:oracle:thin:@127.0.0.1:1521:ORCL; Connection conn =

文档评论(0)

1亿VIP精品文档

相关文档