2017-08-06 93 views
0

我有低於我從SQL Developer的出口從開發環境2個INSERT語句。之後我從dev中刪除這些記錄。現在我想,因爲那是我的回升到在開發中再次運行此insert語句,但我得到的錯誤作爲是ORD_DAYID不能插入腳本中使用虛擬列。所以我想排除此列,並使用替代函數相應的值或者我不知道任何工具。我以前不知道,我有這個表的虛擬列。我想知道是否有任何工具或功能,我可以選擇ORD_DAYID也相應值都被選擇,然後我可以刪除那些然後我可以能夠在測試enviornment再次運行此插入語句。進展插入腳本替換

P.S我所提到的僅2樣品插入語句,但有1000個插入語句。所以很難從這個插入語句中手動刪除這個ORD_DAYID和各自的值。

Insert into test_ord (IS_GRP,ORD_DAYID,REF_CAMPA_CODE) values (1,20150813,null); 
Insert into test_ord (IS_GRP,ORD_DAYID,REF_CAMPA_CODE) values (1,20150828,null); 
+0

爲什麼開發環境看起來與備份不同? –

+0

只需使用vi,sed,awk,Editplus或Notepad ++或任何可用於從sql文件中選擇性刪除這些文件的東西。在sql中這樣做沒有意義。而在SQL開發人員不能在導出到插入語句之前選擇只有真正的列? –

+0

@戈登與其相同的環境沒有什麼不同。 Kaushik,正如我在我的問題中提到的,我以前不知道我有這個表的虛擬列,否則我可以exlcuded那些列。我使用Notepad ++,但它確實選擇了我選擇的列的相應值 – Andrew

回答

1

您可以在編輯器(如Notepad ++)中使用正則表達式編輯INSERT語句。

因此,要改變這種...

Insert into test_ord (IS_GRP,ORD_DAYID,REF_CAMPA_CODE) values (1,20150813,null); 

...這個...

Insert into test_ord (IS_GRP,REF_CAMPA_CODE) values (1,null); 

您需要的搜索模式:

Insert into test_ord \(IS_GRP,ORD_DAYID,REF_CAMPA_CODE\) values \(([0-9]+),([0-9]+),null\); 

和一個取代的圖案:

Insert into test_ord \(IS_GRP,REF_CAMPA_CODE\) values \(\1,null\); 

很顯然,您需要優化搜索模式,以應付IS_GRP的所有不同的值,並REF_CAMPA_CODE在1000個語句。


「有什麼辦法,我們可以數列和價值的地方,用空替換爲」

號與虛擬列問題在於,它們不能被引用INSERT或UPDATE語句。所以你需要完全從投影中排除它。

「我不能夠找到在記事本中那些選項++」

真的嗎?搜索和替換是不是一種奇異期權:

  • 從菜單:Search > Find > Replace [tab](或[ctrl]+h
  • 由於搜索模式選擇regular expression單選按鈕

Notepad++ regex search'n'replace

+0

我無法在記事本++中找到這些選項。你可以在記事本++中顯示你想說的嗎?而且我也不知道如何改進搜索模式?我想有什麼方法可以計算列和值的位置並用空值代替它 – Andrew

0
  1. 創建一個沒有虛擬列的輔助表。
  2. 將數據恢復到此輔助表。
  3. 將數據從輔助表傳輸到原始表。
 
    -- this is your table 
    create table mytab(A number, b number, s as (a+b)); 
    --fill it with data 
    insert into mytab(a,b) values(1,1); 
    insert into mytab(a,b) values(1,2); 
    insert into mytab(a,b) values(2,1); 
    insert into mytab(a,b) values(2,2); 
    commit; 
    -- check its content 
    select * from mytab; 
    -- now delete the rows 
    delete from mytab; 
    commit; 

    -- restore your data 
    -------------------- 

    -- create a table similar the table you want to restore 
    -- but the virtual colums as regular columns. 
    create table ctas as 
     select * from mytab where 1!=0; 

    -- insert your backup data 
    insert into ctas(a,b,s) values(1,1,2); 
    insert into ctas(a,b,s) values(1,2,3); 
    insert into ctas(a,b,s) values(2,1,3); 
    insert into ctas(a,b,s) values(2,2,4); 
    commit; 

    -- transfer the data to the table you want to restore 
    insert into mytab(a,b) select a,b from ctas;