oracle创建trigger procedure function sequence plsql

本文介绍了SQL中触发器、函数、存储过程的创建及使用方法,并详细解释了序列、参数化函数和存储过程的实现步骤,同时展示了如何通过调用函数和存储过程来解决实际问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

--触发器 自动插入序列
create or replace trigger tr_upload
before insert on upload
referencing new as new old as old
for each row
begin
  select seq_upload.nextval into :new.upid from dual;

end;

--无参函数
create or replace function fun_up
return number is total number(9) := 0;
begin
  select count(*) into total from upload;
  return total;
  end;

--有参函数
create or replace function fun_upload(nm in varchar)
return number is total number(9) := 0;
begin 
  select count(*) into total from upload where upfolder like '%'||nm||'%';
  return total;
end;

--存储过程
create or replace procedure proc_upload(nm in varchar)
is
begin
declare 
 da number(9) :=0;
  begin
    da :=fun_upload(nm);
    dbms_output.put_line('da is :'||da);
    insert into upload(upfolder,upfilename) values(da,da);
end;
end;

--调用无参的函数
declare 
a number;
begin
  a := fun_up();
  dbms_output.put_line('not param function:'||a);
  end;

--调用有参函数
declare 
a varchar(10);
e number;
begin
  a := 'do';
  e :=fun_upload(a);
  dbms_output.put_line('param function is:'||e);
end;

--调用存储过程
declare 
a varchar(10);
begin 
  a:='d';
  proc_upload(a);
end;

--创建序列

create sequence seq_xxx
start with 1
increment by 1
maxvalue 999999999999; 

--for循环存储过程

create or replace procedure proc_insert is
  i number;
begin
  i := 0;
  for i in 1 .. 1000 loop
    insert /*+append*/
    into test
      (c1)
      select /*+parallel(t,4)*/
       c1
        from tmp_table t;
  end loop;
  commit;
end proc_insert;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值