我正在更新temp_docmeta表中的xprojecttype,并尝试通过包含"d.xproject_id NOT IN"
子句来忽略我的下方查询中的所有无效数字,但它仍然会引发01722. 00000
- "invalid number"
错误
BEGIN
FOR X IN
(SELECT projecttype,pid,enddate FROM temp_project
)
LOOP
UPDATE temp_docmeta d
SET d.xprojecttype =X.projecttype
WHERE d.xproject_id =X.PID
AND X.projecttype IS NOT NULL
AND X.enddate > '10-MAR-14 00.00.00'
AND d.xproject_id NOT IN
(SELECT TO_NUMBER(xproject_id)
FROM temp_docmeta
WHERE REGEXP_LIKE(xproject_id, '[^0-9]+')
);
END LOOP;
END ;
但是当我用delete语句删除同一组记录然后运行上面的更新命令时,它工作正常。
DELETE
FROM temp_docmeta
WHERE xproject_id IN
(SELECT xproject_id
FROM temp_docmeta
WHERE REGEXP_LIKE(xproject_id, '[^0-9]+')
);
我不想从temp_docmeta表中删除上述记录,但需要像第一次查询一样更新temp_docmeta
表。我该怎么办?
答案 0 :(得分:0)
您的查询尝试更改TO_NUMBER您不想要的所有值
也许你应该尝试
AND d.xproject_id IN
(SELECT TO_NUMBER(xproject_id)
FROM temp_docmeta
WHERE NOT REGEXP_LIKE(xproject_id, '[^0-9]+')
);
但这取决于订单,如何完成TO_NUMBER和REGEXP_LIKE
答案 1 :(得分:0)
我更改了X.PID的数据类型,如下所示,to_char
并且它有效,但是,当我将xproject_id的数据类型更改为“to number”时,它没有用。奇怪。不是吗?
或者我错过了什么?
BEGIN
FOR X IN
(SELECT projecttype,pid,enddate FROM temp_PROJECT where projecttype IS NOT NULL
AND enddate > '10-MAR-14 00.00.00'
AND PID NOT LIKE '-1'
)
LOOP
UPDATE temp_docmeta
SET xprojecttype =X.projecttype
WHERE xproject_id =to_char(X.PID)
AND xproject_id in
(SELECT UNIQUE(xproject_id)
FROM temp_docmeta
WHERE REGEXP_LIKE(xproject_id, '[0-9]+')
);
END LOOP;
END;