2017-10-06 55 views
2

我對SQL很陌生,並且遇到了代碼問題。我一直試圖在表格中複製一行並替換記錄的一部分。不過,我不斷收到錯誤:SQL複製和替換記錄

ORA-00907: missing right parenthesis

下面的代碼提供了錯誤:

insert into mi_structure 
    select replace parent_mi_id, (child_mi_id,'GR','GR_V') child_mi_id, startdate, enddate, mutnr 
    from mi_structure 
    where parent_mi_id like 'MIPFV%29' 
    and sysdate between startdate and enddate; 

用下面的代碼表mi_structure看起來像這樣

select * 
    from mi_structure 
    where parent_mi_id like 'MIPFV%29' 
    and sysdate between startdate and enddate; 


PARENT_MI_ID || CHILD_MI_ID  || STARTDATE || ENDDATE || MUTNR 
MIPFV_POOL 29 || CSLLXXXX.USD.GR || 42917  || 36526  || 11 

我在做什麼錯誤?

+0

'(child_mi_id,'GR','GR_V')'寫成函數但不是。可能這會導致錯誤。 –

+0

你想使用替換功能嗎?它使用像這樣 REPLACE('Atestword','word','Phrase'); = AtestPhrase – Moudiz

回答

1

可以試一下這個

insert into mi_structure 
    select parent_mi_id, replace (child_mi_id,'GR','GR_V') child_mi_id, startdate, enddate, mutnr from mi_structure 
    where parent_mi_id like 'MIPFV%29' 
    and sysdate between startdate and enddate; 
+0

感謝您的幫助。這給我更新的線,如我所料。這是否也將記錄添加到表格中? – Roosz0rd

+0

它是唯一的選擇部分,你也應該寫入插入部分。我還添加了插入部分 –

+0

'insert into mi_structure'我得到一個完整性約束.. – Roosz0rd

2

select replace parent_mi_id, (child_mi_id,'GR','GR_V') child_mi_id, startdate, enddate, mutnr from mi_structure

看來你是使用替換功能錯了,它應該像下面

insert into mi_structure (parent_mi_id_col,child_mi_id_col,startdate_col,enddate,mutnr) 
    select parent_mi_id, replace(child_mi_id,'GR','GR_V') child_mi_id, startdate, enddate, mutnr 
    from mi_structure 
     where parent_mi_id like 'MIPFV%29' 
     and sysdate between startdate and enddate; 

順便說一句我推薦你在插入作爲添加列以上。

+0

但是,然後標題不是以正確的順序。這不是問題嗎?這是否將該行添加到表中? – Roosz0rd

+0

如果有inserte。那麼是它的一個問題,請添加插入部分。順便說一句我建議你添加在插入列像我的例子 – Moudiz