工作上也没什么事情,一天都琐碎的事,空闲时间比较多,自己可以随意安排。
分析目前的形式,发现自己要学的东西真是太多了,都不知道要学什么好,例如:数据库、开发技术、管理……这些技术东西,一天一天都在更新,要想跟得上脚步,估计要把自己累趴下,还是要把自己善于的方面做好,做精也就差不多了。
好久都没有写过Oracle存储过程了,一般写查询语句比较多,自己就试着写了一下插入、删除、修改记录的存储过程。
插入:
代码
1
CREATE
OR
REPLACE
Procedure
p_insert_t_stu
--
存储过程名称
2 (
3 p_stuid in Number ,
4 p_stuname in Nvarchar2,
5 p_stusex in Nvarchar2,
6 p_stuadd in Nvarchar2
7 )
8 as
9 BEGIN
10 insert into t_stu
11 values
12 (p_stuid,p_stuname,p_stusex,p_stuadd);
13 commit ;
14 end ;
2 (
3 p_stuid in Number ,
4 p_stuname in Nvarchar2,
5 p_stusex in Nvarchar2,
6 p_stuadd in Nvarchar2
7 )
8 as
9 BEGIN
10 insert into t_stu
11 values
12 (p_stuid,p_stuname,p_stusex,p_stuadd);
13 commit ;
14 end ;
删除:
代码
1
CREATE
OR
REPLACE
Procedure
p_delete_t_stu
--
存储过程名称
2 (
3 p_stuid in Number ,
4 p_msg Out Nvarchar2
5 )
6 Is
7 flag Integer : = 1 ;
8 v_stuid Number ;
9 Begin
10 Select flag Into v_stuid From t_stu Where stuid = p_stuid;
11 Delete t_stu
12 Where
13 stuid = p_stuid;
14 commit ;
15 If flag = 1 Then
16 Begin
17 p_msg: = ' 删除成功 ' ;
18 End ;
19 End If ;
20 Exception
21 When Others Then
22 p_msg: = Sqlerrm || ' , ' || ' 删除失败 ' ;
23 END ;
2 (
3 p_stuid in Number ,
4 p_msg Out Nvarchar2
5 )
6 Is
7 flag Integer : = 1 ;
8 v_stuid Number ;
9 Begin
10 Select flag Into v_stuid From t_stu Where stuid = p_stuid;
11 Delete t_stu
12 Where
13 stuid = p_stuid;
14 commit ;
15 If flag = 1 Then
16 Begin
17 p_msg: = ' 删除成功 ' ;
18 End ;
19 End If ;
20 Exception
21 When Others Then
22 p_msg: = Sqlerrm || ' , ' || ' 删除失败 ' ;
23 END ;
修改:
代码
1
CREATE
OR
REPLACE
Procedure
p_update_t_stu
--
存储过程名称
2 (
3 p_stuid in Number ,
4 p_stuname in Nvarchar2,
5 p_stusex in Nvarchar2,
6 p_stuadd in Nvarchar2
7 )
8 as
9 BEGIN
10 Update t_stu Set stuname = p_stuname,stusex = p_stusex,stuadd = p_stuadd
11 Where
12 stuid = p_stuid;
13 commit ;
14 end ;
2 (
3 p_stuid in Number ,
4 p_stuname in Nvarchar2,
5 p_stusex in Nvarchar2,
6 p_stuadd in Nvarchar2
7 )
8 as
9 BEGIN
10 Update t_stu Set stuname = p_stuname,stusex = p_stusex,stuadd = p_stuadd
11 Where
12 stuid = p_stuid;
13 commit ;
14 end ;
如有问题,请指出! 欢迎大家提出宝贵意见~