读书人

Oracle中对一个表中的数据跟输入的参数

发布时间: 2013-03-26 21:10:04 作者: rapoo

Oracle中对一个表中的数据和输入的参数对比,做出对应的操作(存储过程)

Oracle一个表中对应输入的数据对比做出想对应的操作 出自

http://topic.csdn.net/u/20120712/14/7ff39445-a8bc-46fd-a984-64114b2c8e90.html?94669

表table有一个number字段的a
存储过程test有一个变量x。\

如果table表a字段有大于x的纪录y个,那么向A表插入y条a字段等于x的纪录
如果a字段没有大于x的纪录,则a字段全部加100。

好了直接上测试数据

SQL> select * from t;         A----------    1382.4      1920      1500      2975      1500      2850      2940      5000      1800      1320      1368      1560已选择12行。SQL>  create or replace procedure emp_test  2  (  3  x number  4  )  5  is  6   v_a employee.salary%type;  7   v_count number;  8   i number;  9   begin 10  i:=0; 11  select count(a) into v_count from t where a>x; 12  if v_count >0 then 13   for i in 1..v_count loop 14  insert into t (a) values (x); 15  end loop ; 16   else 17   update t set a=a+100 ; 18   end if; 19   end; 20   /过程已创建。SQL> exec emp_test(9000)PL/SQL 过程已成功完成。SQL> select * from t;         A----------    1482.4      2020      1600      3075      1600      2950      3040      5100      1900      1420      1468      1660已选择12行。SQL> exec emp_test(3000)PL/SQL 过程已成功完成。SQL> select * from t;         A----------    1482.4      2020      1600      3075      1600      2950      3040      5100      1900      1420      1468      1660      3000      3000      3000已选择15行。



我的异常网推荐解决方案:oracle存储过程,http://www.myexception.cn/oracle-develop/177537.html

读书人网 >其他数据库

热点推荐