我正在尝试使用SELECT和值创建INSERT INTO,但没有效果。
表来源:
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 :(得分: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 :(得分: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;