一、声明游标,循环打印
--第一种方式
declare
cursor imaa_tmp is
select imaa001,imaa004 from imaa_t where imaaent=100 and imaa001 like '5%';
begin
dbms_output.enable(buffer_size => NULL); --不限制打印的字符串限制
for imaa in imaa_tmp
loop
dbms_output.put_line('料件编号:'||imaa.imaa001);
dbms_output.put_line('料件属性:'||imaa.imaa004);
end loop;
end;
--第二方式 不用declare 声明游标
begin
dbms_output.enable(buffer_size => NULL);
for imaa in (select imaa001,imaa004 from imaa_t where imaaent=100 and imaa001 like '5%')
loop
dbms_output.put_line('料件编号:'||imaa.imaa001);
dbms_output.put_line('料件属性:'||imaa.imaa004);
end loop;
end;
二、带有变量的Demo,做一个比较简单的传值进行判断,然后对系统进行更新。
create or replace procedure sfaa123(
danhao varchar2,
xiangci in varchar2,
money in number,
g_site in varchar2 )
is
l_apbaud015 number(20,6);
l_danbie varchar2(40);
l_pmdtud015 number(20,6);
begin
--单别判断
select to_char(substr(danhao,0,4)) into l_danbie from dual;
case l_danbie
when to_char('7111') then
select nvl(apbaud015,0) into l_apbaud015 from apba_t where apbaent=100 and apbadocno=danhao and apbaseq=xiangci;
if l_apbaud015 = 0 then
update apba_t set apbaud015 = money where apbaent=100 and apbadocno=danhao and apbaseq=xiangci;
commit;
else
update apba_t set apbaud015 = nvl(apbaud015,0)+money where apbaent=100 and apbadocno=danhao and apbaseq=xiangci;
commit;
end if;
when to_char('7112') then
select nvl(apbaud015,0) into l_apbaud015 from apba_t where apbaent=100 and apbadocno=danhao and apbaseq=xiangci;
if l_apbaud015 = 0 then
update apba_t set apbaud015 = money where apbaent=100 and apbadocno=danhao and apbaseq=xiangci;
commit;
else
update apba_t set apbaud015 = nvl(apbaud015,0)+money where apbaent=100 and apbadocno=danhao and apbaseq=xiangci;
commit;
end if;
when to_char('7113') then
select nvl(apbaud015,0) into l_apbaud015 from apba_t where apbaent=100 and apbadocno=danhao and apbaseq=xiangci;
if l_apbaud015 = 0 then
update apba_t set apbaud015 = money where apbaent=100 and apbadocno=danhao and apbaseq=xiangci;
commit;
else
update apba_t set apbaud015 = nvl(apbaud015,0)+money where apbaent=100 and apbadocno=danhao and apbaseq=xiangci;
commit;
end if ;
when to_char('SPM2') then
select nvl(pmdtud015,0) into l_pmdtud015 from pmdt_t where pmdtent=100 and pmdtsite=g_site and pmdtdocno=danhao and pmdtseq=xiangci;
if l_pmdtud015 = 0 then
update pmdt_t set pmdtud015 = money where pmdtent=100 and pmdtsite=g_site and pmdtdocno=danhao and pmdtseq=xiangci;
commit;
else
update pmdt_t set pmdtud015 = nvl(pmdtud015,0)+money where pmdtent=100 and pmdtsite=g_site and pmdtdocno=danhao and pmdtseq=xiangci;
commit;
end if;
end case;
end;
三、存储过程
create or replace procedure insert_img is
V_sum integer;
begin
select count(*) into V_sum from imaa_t where imaaent=100;
--commit;
dbms_output.put_line('查询到的料件笔数:'||V_sum);
--return V_sum;
-- return 0;
end insert_img ;