oracle存储过程学习笔记
建一个不带任何参数存储过程(输出系统日期)
create or replace procedure output_date isbegindbms_output.put_line(sysdate);end output_date;
运行这个存储过程
beginoutput_date;end;
建一张表,后面会用到
-- Create tablecreate table TEST_USER( USERID NUMBER not null, USERNAME VARCHAR2(20), PASSWORD VARCHAR2(20), REALNAME VARCHAR2(20), SEX CHAR(1), TYPE CHAR(2), STATUS CHAR(2))
建主键
-- Create/Recreate primary, unique and foreign key constraints alter table TEST_USER add constraint TEST_USER_PK primary key (USERID) using index pctfree 10 initrans 2 maxtrans 255 storage ( initial 64K minextents 1 maxextents unlimited );
插入一条数据
insert into test_user (USERID, USERNAME, PASSWORD, REALNAME, SEX, TYPE, STATUS)values (1, 'tomcat', 'hahaha', 'da', '1', '01', '01');
建一个带传入、传出参数的存储过程
create or replace procedure get_username(param_userid in number,param_username out varchar2)asbegin select username into param_username from test_user where userid = param_userid; --变量赋值exceptionwhen no_data_found then raise_application_error(-1,'该用户不存在!');end get_username;
调用这个存储过程
declare username varchar2(20);begin get_username(1,username); dbms_output.put_line(username);end;
未完待续。。。
我的异常网推荐解决方案:oracle存储过程,http://www.myexception.cn/oracle-develop/177537.html