暂无图片
暂无图片
5
暂无图片
暂无图片
2
暂无图片

oracle部分存储过程

原创 游湖 2022-12-08
271

1.create user IT337008 identified by 'Anqi';#15058803,name:passwd:

学生证

2:

create procedure test(birthday in date) as

bi number;

begin

select TRUNC(months_between(sysdate, birthday)/12) into bi from dual;

if (bi<13) then

DBMS_OUTPUT.PUT_LINE('xiao13');

elsif (bi<20) then

DBMS_OUTPUT.PUT_LINE('xiao20');

elsif (bi<65) then

DBMS_OUTPUT.PUT_LINE('xiao65');

else

DBMS_OUTPUT.PUT_LINE('da65');

end if;

end test;

drop procedure test;

call test(to_date('2000-12-12','yyyy-mm-dd'));

SQL> set serveroutput on;

SQL> exec test(to_date('2000-12-12','yyyy-mm-dd'));

da20

PL/SQL procedure successfully completed

CREATE GLOBAL TEMPORARY TABLE REPROTTEST(

ID NUMBER,

ANAME VARCHAR2(20)

) ON COMMIT DELETE ROWS;

create or replace procedure report_month_responsibility(

o_cur out sys_refcursor)

as

begin

insert into reprottest(id,aname) values(1,'1');

open o_cur for select * from reprottest;

end report_month_responsibility;

declare

v_id number;

v_aname varchar2(20);

o_cur sys_refcursor;

begin

report_month_responsibility(o_cur);

fetch o_cur into v_id,v_aname;

while o_cur%found loop

dbms_output.put_line('输出结果:'||v_id||','||v_aname);

fetch o_cur into v_id,v_aname;

end loop;

commit;

end;

/

VARIABLE x REFCURSOR

DECLARE

V_Sqlstatement Varchar2(2000);

BEGIN

V_Sqlstatement := 'SELECT * FROM t';

OPEN :x for v_Sqlstatement;

End;

/

print :x;

create or replace procedure testb

is

begin

for i in (select * from test11) loop

dbms_output.put_line(i.id);

end loop;

end;

/

------插入一个表的同时插入另外一个表

Create or replace trigger tri_A

after insert on ODATA_DELIVER_M

For each row

declare

pragma autonomous_transaction;

dno integer;

begin

select count(1) into dno from HXMY_DESALE_D t where

t.deliver_no=:new.deliver_no;

if dno=1 then

insert into ODATA_BDSALE_M(deliver_no,id) values( :new.deliver_no,:new.id) ; --

in (select deliver_no from HXMY_DESALE_D);

commit;

end if;

end;

/

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

手机用户5704
暂无图片
2年前
评论
暂无图片 0
2年前
暂无图片 点赞
评论
L
lelepapa
暂无图片
2年前
评论
暂无图片 0
2年前
暂无图片 点赞
评论