最近在使用存储过程,所以在此记录一下。
基本语法
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;