1、基本语法
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20CREATE OR REPLACE PROCEDURE 存储过程名(param1 in type,param2 out type) /** AS和IS没区别 **/ IS 变量1 类型(值范围); 变量2 类型(值范围); BEGIN select count(*) into 变量1 from 表名 where 列名=param1; if (判断条件) then select 列名 into 变量2 from 表名 where 列名=param1; DBMS_OUTPUT.put_line('打印信息'); Elseif (判断条件) then dbms_output.put_line('打印信息'); Else Raise 异常名 (NO_DATA_FOUND); End if; Exception When others then Rollback; END;
2、基本使用
2.1、没有参数的过程
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16create or replace procedure test_count is v_total int; v_date varchar(20); begin select count(*) into v_total from dual; select to_char(sysdate,'yyyy-mm-dd') into v_date from dual; DBMS_OUTPUT.put_line('总人数:'||v_total); DBMS_OUTPUT.put_line('当前时间:'||v_date); end;
调用方法
复制代码
1
2
3
4begin test_count; end;
2.2、仅带传入参数的过程
复制代码
1
2
3
4
5
6
7
8
9
10create or replace procedure test_count1(v_id in varchar2) as v_name varchar(100); begin select c_name into v_name from tb_store where c_stono=v_id; DBMS_OUTPUT.put_line(v_id||'店的名称为:'||v_name); exception when no_data_found then dbms_output.put_line('no_data_found'); end;
调用方法
复制代码
1
2
3
4begin test_count1(11910); end;
2.3、仅带输出参数的过程
复制代码
1
2
3
4
5
6
7
8
9create or replace procedure test_count2(v_name out varchar2) is begin select c_name into v_name from tb_store where c_stono='1101'; exception when no_data_found then dbms_output.put_line('no_data_found'); end;
调用方法
复制代码
1
2
3
4
5
6
7declare v_name varchar(200); begin test_count2(v_name); dbms_output.put_line(v_name); end;
2.4、带输入参数和输出参数的存储过程
复制代码
1
2
3
4
5
6
7
8
9
10create or replace procedure test_count3(v_id in int,v_name out varchar2) as begin select c_name into v_name from tb_store where c_stono=v_id; dbms_output.put_line(v_name); exception when no_data_found then dbms_output.put_line('no_data_found'); end;
调用方法
复制代码
1
2
3
4
5
6declare v_name varchar(200); begin test_count3('1101',v_name); end;
最后
以上就是清新哈密瓜最近收集整理的关于【Oracle】存储过程基本语法1、基本语法2、基本使用的全部内容,更多相关【Oracle】存储过程基本语法1、基本语法2、基本使用内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复