存储过程参数设定

J2EE 码拜 8年前 (2016-06-06) 1261次浏览
create or replace procedure pro_js_inter_temp_money(v_orderno varchar2 ) as
/*
创建 : by yugh  08-11
功能:不是全额付款即取消订单
*/
realMoney            number(10);
orderMoney           number(10);
begin
select tt.real_money into realMoney
from t_sale_order_ty_temp tt where tt.order_id=v_orderno and tt.datasource=”JSYD”;
select ttt.order_money into orderMoney
from t_sale_order_ty_temp ttt where ttt.order_id=v_orderno and ttt.datasource=”JSYD”;
if realMoney < orderMoney then
update t_sale_order_ty_temp aa set aa.audit_status=”已处理”,aa.audit_type=”已取消”,aa.auditor_id=”1″,aa.auditor_name=”管理员”,aa.audit_date=sysdate,
aa.audit_result=”不是全额付款,订单已取消”,aa.modi_date=sysdate,aa.modifier_id=”1″,aa.modifier_name=”管理员” where aa.datasource=”JSYD”
and aa.order_time>sysdate-255 and aa.order_id=v_orderno ;
commit;
end if;
exception
when others then
rollback;
end pro_js_inter_temp_money;
做的一个新功能,以前没弄过存储过程,测试都好了,不知道咋部署。
现在带了一个参数就是orderno ,测试就是把一个确定的订单号来测,功能没问题,问一下本人怎么用成无参,怎么找到满足的订单号呢。感谢!
解决方案

5

引用:
Quote: 引用:

怎么用成无参?是什么意思没有明白, 假如是另一个功能的话可以再写一个过程的. 一个功能一个过程. 或将一组功能集成一个package.

假如本人把create or replace procedure pro_js_inter_temp_money(v_orderno varchar2 ) as
(v_orderno varchar2 ) 去掉,就没有参数了,那本人得在下面定义一个订单号的变量,不知道怎么写出来。

create or replace procedure Pro_test is
v_orderno varchar2(100);
begin
  v_orderno := "bree06";
  --TODO
end Pro_test;

35

引用:
Quote: 引用:
Quote: 引用:
Quote: 引用:

怎么用成无参?是什么意思没有明白, 假如是另一个功能的话可以再写一个过程的. 一个功能一个过程. 或将一组功能集成一个package.

假如本人把create or replace procedure pro_js_inter_temp_money(v_orderno varchar2 ) as
(v_orderno varchar2 ) 去掉,就没有参数了,那本人得在下面定义一个订单号的变量,不知道怎么写出来。

定义个变量。select xxx  into  变量  where…   就完成变量赋值了~  前提是你这个订单号你知道怎么查出来~
不过一般都是需要这个变量的   是通过程序调用存储过程时传进来~

照你给的变量赋值语句可以了,但是一次查出来的只能更新一条啊,这个存储过程不是用程序调的,计划用oracle的job来定时去更新值,查询满足的数据都是已经存在表里了,本人怎么能一次更新多条呀。

 select em.order_id into order_no from  t_sale_order_ty_temp em where em.pay_flag="3" and em.datasource="JSYD" ;

多条的话就是用游标和for循环啊,把你满足条件的数据写成一个cursor,然后遍历这个cursor做你的操作就行了,大致这样:
Cursor cursor1 is select,,,..,,,,,;
for everyrow1 in cursor1 loop
// 循环体 做你的更新就可以了
end loop;


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明存储过程参数设定
喜欢 (0)
[1034331897@qq.com]
分享 (0)