PLSQL游标批量更新数据问题
declareC_YIBAOHAOABB.YIBAOHAO%TYPE;C_XINGMINGABB.XINGMING%TYPE;C_DIQUHAOABB.DIQUHAO%T...
declare
C_YIBAOHAO ABB.YIBAOHAO%TYPE;
C_XINGMING ABB.XINGMING%TYPE;
C_DIQUHAO ABB.DIQUHAO%TYPE;
cursor mycursor IS select YIBAOHAO,XINGMING,DIQUHAO from ABB where ID=(select ID from BBB);
BEGIN
OPEN mycursor;
LOOP
FETCH mycursor INTO C_YIBAOHAO,C_XINGMING,C_DIQUHAO;
EXIT WHEN mycursor%NOTFOUND;
IF BBB.YIBAOHAO=C_YIBAOHAO and BBB.XINGMING=C_XINGMING THEN
UPDATE BBB SET DIQUHAO=C_DIQUHAO;
ELSIF BBB.YIBAOHAO=C_YIBAOHAO and BBB.DIQUHAO=C_DIQUHAO THEN
UPDATE BBB SET XINGMING=C_XINGMING;
ELSIF BBB.XINGMING=C_XINGMING and BBB.DIQUHAO=C_DIQUHAO THEN
UPDATE BBB SET YIBAOHAO=C_YIBAOHAO;
END IF;
END LOOP;
close mycursor;
end;
/
目的是,2表ABB,BBB的YIBAOHAO,XINGMING,DIQUHAO字段各自对比,若任意2字段的值相同,剩余另一字段的表BBB的值更新为表ABB该字段的值
是oracle的,主要是2表 对比更新 展开
C_YIBAOHAO ABB.YIBAOHAO%TYPE;
C_XINGMING ABB.XINGMING%TYPE;
C_DIQUHAO ABB.DIQUHAO%TYPE;
cursor mycursor IS select YIBAOHAO,XINGMING,DIQUHAO from ABB where ID=(select ID from BBB);
BEGIN
OPEN mycursor;
LOOP
FETCH mycursor INTO C_YIBAOHAO,C_XINGMING,C_DIQUHAO;
EXIT WHEN mycursor%NOTFOUND;
IF BBB.YIBAOHAO=C_YIBAOHAO and BBB.XINGMING=C_XINGMING THEN
UPDATE BBB SET DIQUHAO=C_DIQUHAO;
ELSIF BBB.YIBAOHAO=C_YIBAOHAO and BBB.DIQUHAO=C_DIQUHAO THEN
UPDATE BBB SET XINGMING=C_XINGMING;
ELSIF BBB.XINGMING=C_XINGMING and BBB.DIQUHAO=C_DIQUHAO THEN
UPDATE BBB SET YIBAOHAO=C_YIBAOHAO;
END IF;
END LOOP;
close mycursor;
end;
/
目的是,2表ABB,BBB的YIBAOHAO,XINGMING,DIQUHAO字段各自对比,若任意2字段的值相同,剩余另一字段的表BBB的值更新为表ABB该字段的值
是oracle的,主要是2表 对比更新 展开
3个回答
展开全部
3个 UPDATE比开游标划算:
举其中一种情况的例子:
UPDATE BBB
SET BBB.DIQUHAO = (SELECT ABB.DIQUHAO FROM ABB WHERE ABB.ID = BBB.ID)
WHERE EXISTS(SELECT 1
FROM ABB
WHERE BBB.ID = ABB.ID
AND ABB.XINGMING = BBB.XINGMING
AND ABB.YIBAOHAO = BBB.YIBAOHAO);
展开全部
两个问题:
1、在做update时,没有写条件,是要将BBB这个表的对应字段都更新成相同的么?
2、在判断语句中,直接引用BBB表字段的方法,可行么?
1、在做update时,没有写条件,是要将BBB这个表的对应字段都更新成相同的么?
2、在判断语句中,直接引用BBB表字段的方法,可行么?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐于2017-09-02
展开全部
PLSQL游标批量更新数据问题
UPDATE BBB
SET BBB.DIQUHAO = (SELECT ABB.DIQUHAO FROM ABB WHERE ABB.ID = BBB.ID)
WHERE EXISTS(SELECT 1
FROM ABB
WHERE BBB.ID = ABB.ID
AND ABB.XINGMING = BBB.XINGMING
AND ABB.YIBAOHAO = BBB.YIBAOHAO);
UPDATE BBB
SET BBB.DIQUHAO = (SELECT ABB.DIQUHAO FROM ABB WHERE ABB.ID = BBB.ID)
WHERE EXISTS(SELECT 1
FROM ABB
WHERE BBB.ID = ABB.ID
AND ABB.XINGMING = BBB.XINGMING
AND ABB.YIBAOHAO = BBB.YIBAOHAO);
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询