--创建存储过程
CREATE OR REPLACE PROCEDURE sp_test1
IS
--变量定义
Begin
--sql语句
commit;
End;
--游标
CREATE OR REPLACE PROCEDURE sp_test1
as
cursor c is select * from test;--游标赋值
Begin
for sc in c--遍历游标
loop
dbms_output.put_line(sc.t_name);--对游标当前指向的值进行依次处理。这里是显示t_name
end loop;
End;
--case的使用
case sc.num2
when '1' then
dbms_output.put_line(sc.name2||sc.num2||'case1');
when '2' then
dbms_output.put_line(sc.name2||sc.num2||'case2');
when '3' then
dbms_output.put_line(sc.name2||sc.num2||'case3');
when '4' then
dbms_output.put_line(sc.name2||sc.num2||'case4');
else
dbms_output.put_line('大于4');
end case;
循环:
--loop的使用
loop
exit 循环结束条件;
end loop;
--where loop的使用
while 条件 loop
end loop;
--带输入参数的存储过程,结果直接打印
create or replace procedure pro_test(e_id in number) --输入id, 输出name
is
spname varchar2(10); --定义一个varchar2的变量 也可以 spname test.name%type 直接使用test.name的数据类型
begin
select name into spname from test where id = e_id; --把输入的e_id用来作为查询条件,把结果赋值给用于输出的spname
dbms_output.put_line(spname );
END;
--带输入和输出参数的存储过程,结果用e_name返回。
create or replace procedure pro_test(e_id in number, e_name out carchar2) --输入id, 输出name
is
begin
select name into e_name from test where id = e_id; --把输入的e_id用来作为查询条件,把结果赋值给用于输出的e_name
dbms_output.put_line(e_name );
END;
--plsql存储过程调用 ()
DECLARE --声明变量
sp_id number;
sp_name varchar2(10);
BEGIN
sp_id:= 1; --给sp_id 直接赋值
sp_pro10 (sp_id, sp_name); --也可以sp_pro10 (1, sp_name);
dbms_output.put_line(sp_name);
END;