考虑表......
TABLE_1
OPTION VARCHAR2 (2),
NAME VARCHAR2 (50),
SQLSOURCE VARCAHR2(400)
TABLE_2
USER_NAME VARCHAR2 (50),
USER_ID NUMBER (10)
DEPT_ID NUMBER (10)
这是更新stmt ..
UPDATE table1 SET OPTION='K',
SQLSOURCE='SELECT DEPT_ID FROM TABLE_2 USER_ID= 15 ORDER BY USER_NAME'
WHERE NAME='GURU'
它的工作正常,但是 我不想在查询中使用硬编码值。
以下查询将替换15 ..
SELECT GROUP_ID FROM TABLE_3 WHERE UPPER(GROUP_NAME)='GROUP1'
所以.. 我试过这样的..
UPDATE table1 SET OPTION='K',
SQLSOURCE='SELECT DEPT_ID FROM TABLE_2 USER_ID='||(SELECT GROUP_ID FROM TABLE_3 WHERE UPPER(GROUP_NAME)='GROUP1') ORDER BY USER_NAME
WHERE NAME='GURU'
它显示错误..
谁能告诉我这样做的方法???
答案 0 :(得分:3)
这可能是你想要的:
UPDATE table_1
SET "OPTION" = 'K',
SQLSOURCE = 'SELECT DEPT_ID FROM TABLE_2 USER_ID=' ||
(SELECT GROUP_ID
FROM TABLE_3
WHERE UPPER(GROUP_NAME) = 'GROUP1') ||
' ORDER BY USER_NAME'
WHERE NAME = 'GURU'
答案 1 :(得分:1)
我想你想要:
UPDATE table1
SET OPTION='K'
, SQLSOURCE='SELECT DEPT_ID FROM TABLE_2 USER_ID='
||(SELECT GROUP_ID FROM TABLE_3 WHERE UPPER(GROUP_NAME)='GROUP1')
||' ORDER BY USER_NAME'
WHERE NAME='GURU'