db2存储过程return前可以commit吗
2个回答
展开全部
1、存储过程编写
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
DROP PROCEDURE "PLName"
@
CREATE PROCEDURE "PLName"(--<a href="https://www.baidu.com/s?wd=%E5%AD%98%E5%82%A8%E8%BF%87%E7%A8%8B&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9PymYrH7bPHbvnjTLPynv0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EP1RzPHmdPW04rjc4PWf4nHcY" target="_blank" class="baidu-highlight">存储过程</a>名字
IN IN_ID BIGINT , --以下全是输入参数
IN IN_ENTNAME VARCHAR(200) ,
IN IN_REGNO VARCHAR(50),
IN IN_PASSWORD VARCHAR(20),
IN IN_LEREP VARCHAR(300),
IN IN_CERTYPE CHARACTER(1),
IN IN_CERNO VARCHAR(50),
IN IN_LINKMAN VARCHAR(50),
IN IN_SEX CHARACTER(1),
IN IN_MOBTEL VARCHAR(30),
IN IN_REQDATE TIMESTAMP,
IN IN_REMITEM VARCHAR(300),
IN IN_STATE CHARACTER(1),
IN IN_TIMESTAMP TIMESTAMP
)
BEGIN
declare V_RESULT BIGINT; --声明变量
DELETE FROM TableNameA WHERE ID = IN_ID;
SET V_RESULT = NULL; --为变量赋值
--检查用户输入的信息是否合法
select b.id INTO V_RESULT from TableNameB b,TableNameC c where 正常的判断条件
if(V_RESULT IS NOT NULL) then ---如果合法,执行下面的insert语句
INSERT INTO TableNameA(ID,ENTNAME,REGNO,PASSWORD,LEREP,CERTYPE,CERNO,LINKMAN,SEX,MOBTEL,REQDATE,REMITEM,STATE,TIMESTAMP)
VALUES(IN_ID,IN_ENTNAME,IN_REGNO,IN_PASSWORD,IN_LEREP,IN_CERTYPE,IN_CERNO,IN_LINKMAN,IN_SEX,IN_MOBTEL,IN_REQDATE,IN_REMITEM,IN_STATE,IN_TIMESTAMP);
end if;
commit;
END
@
2、调用存储过程
1.拷贝到DB2客户端工具中直接执行
2.将上面的语句保存为test.db2文件放到任意目录下(比如D盘根目录),然后在cmd输入db2cmd 然后输入db2 -td@ -vf D:\test.db2即可
3.直接写sql:
call PLName(存储过程名字) (IN_ID,IN_ENTNAME,IN_REGNO,IN_PASSWORD,IN_LEREP,IN_CERTYPE,IN_CERNO,IN_LINKMAN,IN_SEX,IN_MOBTEL,IN_REQDATE,IN_REMITEM,IN_STATE,IN_TIMESTAMP对应的值)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
DROP PROCEDURE "PLName"
@
CREATE PROCEDURE "PLName"(--<a href="https://www.baidu.com/s?wd=%E5%AD%98%E5%82%A8%E8%BF%87%E7%A8%8B&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9PymYrH7bPHbvnjTLPynv0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EP1RzPHmdPW04rjc4PWf4nHcY" target="_blank" class="baidu-highlight">存储过程</a>名字
IN IN_ID BIGINT , --以下全是输入参数
IN IN_ENTNAME VARCHAR(200) ,
IN IN_REGNO VARCHAR(50),
IN IN_PASSWORD VARCHAR(20),
IN IN_LEREP VARCHAR(300),
IN IN_CERTYPE CHARACTER(1),
IN IN_CERNO VARCHAR(50),
IN IN_LINKMAN VARCHAR(50),
IN IN_SEX CHARACTER(1),
IN IN_MOBTEL VARCHAR(30),
IN IN_REQDATE TIMESTAMP,
IN IN_REMITEM VARCHAR(300),
IN IN_STATE CHARACTER(1),
IN IN_TIMESTAMP TIMESTAMP
)
BEGIN
declare V_RESULT BIGINT; --声明变量
DELETE FROM TableNameA WHERE ID = IN_ID;
SET V_RESULT = NULL; --为变量赋值
--检查用户输入的信息是否合法
select b.id INTO V_RESULT from TableNameB b,TableNameC c where 正常的判断条件
if(V_RESULT IS NOT NULL) then ---如果合法,执行下面的insert语句
INSERT INTO TableNameA(ID,ENTNAME,REGNO,PASSWORD,LEREP,CERTYPE,CERNO,LINKMAN,SEX,MOBTEL,REQDATE,REMITEM,STATE,TIMESTAMP)
VALUES(IN_ID,IN_ENTNAME,IN_REGNO,IN_PASSWORD,IN_LEREP,IN_CERTYPE,IN_CERNO,IN_LINKMAN,IN_SEX,IN_MOBTEL,IN_REQDATE,IN_REMITEM,IN_STATE,IN_TIMESTAMP);
end if;
commit;
END
@
2、调用存储过程
1.拷贝到DB2客户端工具中直接执行
2.将上面的语句保存为test.db2文件放到任意目录下(比如D盘根目录),然后在cmd输入db2cmd 然后输入db2 -td@ -vf D:\test.db2即可
3.直接写sql:
call PLName(存储过程名字) (IN_ID,IN_ENTNAME,IN_REGNO,IN_PASSWORD,IN_LEREP,IN_CERTYPE,IN_CERNO,IN_LINKMAN,IN_SEX,IN_MOBTEL,IN_REQDATE,IN_REMITEM,IN_STATE,IN_TIMESTAMP对应的值)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询