我在我的數據庫(Oracle 11g)中有一個很大的表,我想更新表中有特定數字的一列。 我想通過設置此列的每個值的前面的prefix
來更新它。Oracle:通過添加到現有值來更新數據行
例(SpecificNumber是int
和PK,值1是Varchar2
,所以是最後一列):
實際數據:
[SpecificNumber] [Value1] [column2gettingupdated]
[1] 123456789 Test text
[2] 123456789102 sth text2
[3] 12233 text test3
未來的數據(我的SQL後):
[SpecificNumber] [Value1] [column2gettingupdated]
[1] 123456789 Test PREFIX-text
[2] 123456789102 sth PREFIX-text2
[3] 12233 text PREFIX-test3
所以我想到了:
Update table
set column2gettingupdated=("prefix"+
(select column2gettingupdated from table where SpecificNumber = '12233')
)
where SpecificNumber = '12233';
但是,這給我一個ORA-00904: "p": invalid identifier
錯誤。
如果我試試這個:
Update table
set column2gettingupdated=("prefix"+
(select column2gettingupdated from table where SpecificNumber = '12233')
)
where SpecificNumber = '12233';
我得到一個ORA-01722: invalid number
錯誤。
這甚至可能嗎?已經感謝您的幫助!
'SET column2gettingupdated = CONCAT( 「前綴 - 」,column2gettingupdated)' – Mihai 2014-10-16 13:38:10
@Mihai真。不知何故忘了CONCAT,並一直認爲它只適用於MySQL。無論如何,它發佈作爲答案,你得到的信貸! (但是,如果你使用「替換」,你會得到無效的標識符錯誤。) – DatRid 2014-10-16 13:45:02