我有這個用於存儲應用程序設置的Oracle表。SQL - 如何用一條SQL語句更新兩行表
這是SQL腳本,它被用來創建該表:
CREATE TABLE "GLOBALSETTINGS"(
"SettingName" Varchar2(40) NOT NULL,
"SettingValue" Varchar2(40)
)
/
-- Add keys for table GLOBALSETTINGS
ALTER TABLE "GLOBALSETTINGS" ADD CONSTRAINT "Key14" PRIMARY KEY ("SettingName")
/
ALTER TABLE "GLOBALSETTINGS" ADD CONSTRAINT "SettingName" UNIQUE ("SettingName")
/
這是我想使用的SQL語句:
UPDATE GLOBALSETTINGS
SET settingValue =
CASE
WHEN settingName = 'SessionTTL'
THEN '30'
WHEN settingName = 'MaxUsersActive'
THEN '40'
ELSE settingValue
END
WHERE settingName IN ('SessionTTL', 'MaxUsersActive');
但是當我在SQL開發者中運行它我收到以下錯誤消息:
Error starting at line 1 in command:
UPDATE GLOBALSETTINGS
SET settingValue = case
when settingName = 'SessionTTL' then '30'
when settingName = 'MaxUsersActive' then '40'
else settingValue
end
WHERE settingName in ('SessionTTL', 'MaxUsersActive')
Error at Command Line:7 Column:6
Error report:
SQL Error: ORA-00904: "SETTINGNAME": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
我該如何解決這個問題?
最良好的祝願 彼得
你的問題完全是錯誤的,因爲你沒有理解錯誤信息。您將其作爲編程或語法問題進行構建,但該消息明確指出INVALID IDENTIFIER無效。這是因爲你不明智地在雙引號中使用混合大小寫的名稱。看到這個問題的更多細節:http://stackoverflow.com/questions/6027961/ora-00904-invalid-identifier/6030439#6030439 – APC 2012-03-16 16:51:49