2011-04-05 50 views
0

我想做一個INSERT INTO與SELECT和值,但沒有作品。即時嘗試使插入與選擇和價值

TABLE SOURCE:

CREATE TABLE "MICV_PRE"."TS$SEQUENCES" 
    (
    "ID_NODE"  NUMBER DEFAULT 1 NOT NULL ENABLE, 
    "ID_TASK"  NUMBER DEFAULT 1 NOT NULL ENABLE, 
    "ID_DOCUMENT" NUMBER DEFAULT 1 NOT NULL ENABLE, 
    "ID_WORD"  NUMBER DEFAULT 1 NOT NULL ENABLE, 
    "ID_TEAM"  NUMBER DEFAULT '1' NOT NULL ENABLE) 

修改表中:

CREATE TABLE TS$SEQUENCES_NEW(
    "ID_CODE" VARCHAR(255 CHAR) NOT NULL ENABLE, 
    "CODE_SUBSEQUENCE" VARCHAR2(255 CHAR) NOT NULL ENABLE, 
    "VALUE" NUMBER(10,0) NOT NULL ENABLE 
); 

表源:

id_task | id_node | id_word 
    10 | 20 | 30 

表來修改:

id_code | code_subsequence | value 
"id_task" | "empty"   | 10 
"id_node" | "empty"   | 20 
"id_word" | "empty"   | 30 
+0

你試過的SQL代碼是什麼? – Tobias 2011-04-05 12:59:35

+0

INSERT INTO TS $ SEQUENCES_NEW從TS $ SEQUENCES中選擇TS $ SEQUENCES.ID_TASK作爲「VALUE」,「ID_TASK」作爲「ID_CODE」,「VACIO」作爲「CODE_SUBSEQUENCE」; – petercartagena 2011-04-05 13:03:45

回答

2

所以,你試過SQL是這樣的:

SQL> INSERT INTO TS$SEQUENCES_NEW 
    2 SELECT TS$SEQUENCES.ID_TASK AS "VALUE", 'ID_TASK' AS "ID_CODE", 'VACIO' AS "CODE_SUBSEQUENCE" 
    3 FROM TS$SEQUENCES 
    4/
                   * 
ERROR at line 2: 
ORA-01722: invalid number 


SQL> 

失敗的原因是在查詢的投影數據類型不匹配的列的順序表。因此,要麼改變SELECT語句,要麼在INSERT子句中定義順序:

SQL> INSERT INTO TS$SEQUENCES_NEW ("VALUE", "ID_CODE","CODE_SUBSEQUENCE") 
    2 SELECT TS$SEQUENCES.ID_TASK AS "VALUE", 'ID_TASK' AS "ID_CODE", 'VACIO' AS "CODE_SUBSEQUENCE" 
    3 FROM TS$SEQUENCES 
    4/

1 row created. 

SQL> 
1

試試這個:

INSERT INTO TS$SEQUENCES_NEW (VALUE, ID_CODE, CODE_SUBSEQUENCE) 
SELECT TS$SEQUENCES.ID_TASK AS "VALUE", 'ID_TASK' AS "ID_CODE", 'VACIO' AS "CODE_SUBSEQUENCE" 
FROM TS$SEQUENCES; 
+0

真的花了八分鐘來處理示例代碼嗎?當你玩得開心時,不會有時間飛翔! – APC 2011-04-05 13:29:54

+0

謝謝,我忘了要替換的參數。 – petercartagena 2011-04-05 13:32:32