简单的存储过程

最近在使用存储过程,所以在此记录一下。
 
基本语法
create or replace procedure test is
begin
end;

第一行代码为:创建一个名字为test的存储过程,如果存在改名称的存储过程则替换。
 is 和 begin中间可以用来定义变量。
begin和end中间则为代码块。

一个if判断的例子
create or replace procedure test is
 testvaule varchar2(100);
begin
  dbms_output.put_line('我的第一个存储过程!');
  select username into testvaule from userinfo where username='fcjd';
  dbms_output.put_line(testvaule);
  --if语句
      if testvaule = 'admin' then
         
         dbms_output.put_line('是等于admin呢');
        else
           dbms_output.put_line('阿勒,没有找到呢。。。');
    end if;
end test;

一个循环的例子
create or replace procedure test2 as
Cursor my_cursor is select username from userinfo;
 my_username varchar2(100);
begin
  for my_username in my_cursor LOOP
   
     dbms_output.put_line(my_username.username);
   
    end Loop;
end test2;

如果在PLSQL中的SQL Windows中调用存储过程则需要
begin
    XXXX存储过程名;
end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值