我有两个相同的表结构
我想将表[2]中的数据复制到表[1]
中我正在使用此插入语法
INSERT INTO normaltable ("COL1", "COL2", "COL3")
SELECT COL1, COL2, COL3
FROM textfiletable;
我收到此错误
data exception:string data, right truncation/Error code: -3401/state: 22001
使用其他插入语法时
SELECT COL1, COL2, COL3
INTO normaltable
FROM textfiletable;
我收到此错误
unexpected token : INTO required: FROM:line:2/error code: -5581/state:42581
任何人都可以解释一下吗?
我更新我的脚本的详细信息供您参考:
drop table pis_mdc;
drop table normaltable;
drop table textfiletable;
--- original table
CREATE TABLE PIS_MDC
(UD_MDC_CODE VARCHAR(25) ,
DRUG_GNR_NAME VARCHAR(200)DEFAULT 'NULL',
DRUG_PRODUCT_NAME VARCHAR(100),
UD_MDC_DESC VARCHAR(200)DEFAULT 'NULL',
ACTIVE_INGREDIENT_CODE VARCHAR(600),
DEF_CAUTIONARY_CODE VARCHAR(200),
DOSAGE_FORM_CODE VARCHAR(100)DEFAULT 'NULL',
DEF_DOSAGE VARCHAR(20),
DEF_ROUTE_CODE VARCHAR(100)DEFAULT 'NULL',
DEF_ADVISORY_CODE VARCHAR(200)DEFAULT 'NULL',
UD_ATC_CODE VARCHAR(15) ,
STATUS VARCHAR(20),
DRUG_STRENGTH VARCHAR(20),
PRIMARY KEY(UD_MDC_CODE,UD_ATC_CODE));
--create cached tbl
create cached table normaltable
(UD_MDC_CODE VARCHAR(25) ,
DRUG_GNR_NAME VARCHAR(100)DEFAULT 'NULL',
DRUG_PRODUCT_NAME VARCHAR(200),
UD_MDC_DESC VARCHAR(200)DEFAULT 'NULL',
ACTIVE_INGREDIENT_CODE VARCHAR(600),
DEF_CAUTIONARY_CODE VARCHAR(200),
DOSAGE_FORM_CODE VARCHAR(100)DEFAULT 'NULL',
DEF_DOSAGE VARCHAR (20),
DEF_ROUTE_CODE VARCHAR(100)DEFAULT 'NULL',
DEF_ADVISORY_CODE VARCHAR(200)DEFAULT 'NULL',
UD_ATC_CODE VARCHAR(15) ,
STATUS VARCHAR(20),
DRUG_STRENGTH VARCHAR(20));
--create the table that table
create text table textfiletable
(UD_MDC_CODE VARCHAR(25) ,
DRUG_GNR_NAME VARCHAR(100)DEFAULT 'NULL',
DRUG_PRODUCT_NAME VARCHAR(200),
UD_MDC_DESC VARCHAR(200)DEFAULT 'NULL',
ACTIVE_INGREDIENT_CODE VARCHAR(600),
DEF_CAUTIONARY_CODE VARCHAR(200),
DOSAGE_FORM_CODE VARCHAR(100)DEFAULT 'NULL',
DEF_DOSAGE VARCHAR (20),
DEF_ROUTE_CODE VARCHAR(100)DEFAULT 'NULL',
DEF_ADVISORY_CODE VARCHAR(200)DEFAULT 'NULL',
UD_ATC_CODE VARCHAR(15) ,
STATUS VARCHAR(20),
DRUG_STRENGTH VARCHAR(20));
--SET TABLE textfiletable SOURCE ON
SET TABLE textfiletable SOURCE "gabung.csv;ignore_first=true"
--OPTION 0 line 1 with quotes without MAX(CHAR_LENGTH())
INSERT INTO normaltable ("UD_MDC_CODE","DRUG_GNR_NAME","DRUG_PRODUCT_NAME","UD_MDC_DESC","ACTIVE_INGREDIENT_CODE","DEF_CAUTIONARY_CODE","DOSAGE_FORM_CODE","DEF_DOSAGE","DEF_ROUTE_CODE","DEF_ADVISORY_CODE","UD_ATC_CODE","STATUS","DRUG_STRENGTH")
select UD_MDC_CODE,DRUG_GNR_NAME,DRUG_PRODUCT_NAME,UD_MDC_DESC,ACTIVE_INGREDIENT_CODE,DEF_CAUTIONARY_CODE,DOSAGE_FORM_CODE,DEF_DOSAGE,DEF_ROUTE_CODE,DEF_ADVISORY_CODE,UD_ATC_CODE,STATUS,DRUG_STRENGTH
from textfiletable;
-- OPTION 1 line 1 without quotes
--SELECT MAX(CHAR_LENGTH(COL1)), MAX(CHAR_LENGTH(COL2)), ... FROM textfiletable
--INSERT INTO normaltable ("UD_MDC_CODE","DRUG_GNR_NAME","DRUG_PRODUCT_NAME","UD_MDC_DESC","ACTIVE_INGREDIENT_CODE","DEF_CAUTIONARY_CODE","DOSAGE_FORM_CODE","DEF_DOSAGE","DEF_ROUTE_CODE","DEF_ADVISORY_CODE","UD_ATC_CODE","STATUS","DRUG_STRENGTH")
INSERT INTO normaltable (UD_MDC_CODE,DRUG_GNR_NAME,DRUG_PRODUCT_NAME,UD_MDC_DESC,ACTIVE_INGREDIENT_CODE,DEF_CAUTIONARY_CODE,DOSAGE_FORM_CODE,DEF_DOSAGE,DEF_ROUTE_CODE,DEF_ADVISORY_CODE,UD_ATC_CODE,STATUS,DRUG_STRENGTH)
SELECT MAX(CHAR_LENGTH(UD_MDC_CODE)),MAX(CHAR_LENGTH(DRUG_GNR_NAME)),MAX(CHAR_LENGTH(DRUG_PRODUCT_NAME)),MAX(CHAR_LENGTH(UD_MDC_DESC)),MAX(CHAR_LENGTH(ACTIVE_INGREDIENT_CODE)),MAX(CHAR_LENGTH(DEF_CAUTIONARY_CODE)),MAX(CHAR_LENGTH(DOSAGE_FORM_CODE)),MAX(CHAR_LENGTH(DEF_DOSAGE)),MAX(CHAR_LENGTH(DEF_ROUTE_CODE)),MAX(CHAR_LENGTH(DEF_ADVISORY_CODE)),MAX(CHAR_LENGTH(UD_ATC_CODE)),MAX(CHAR_LENGTH(STATUS)),MAX(CHAR_LENGTH(DRUG_STRENGTH))
FROM textfiletable
--ORDER BY UD_MDC_CODE DESC;
--we are done with the text file table
DROP TABLE textfiletable;
COMMIT;
来自textfiletable的数据示例列表,希望将其复制/插入到normaltable中 https://docs.google.com/open?id=0B-7fkDVcLbxnclBZZDZRQWg4ZEE
使用max(char_length(col_name))的结果示例 https://docs.google.com/open?id=0B-7fkDVcLbxnREpzNUp3d3NNSlE
答案 0 :(得分:0)
unexpected token
错误是语法错误。这意味着版本2.x中不支持此语法。
data exception
错误意味着存储在TEXT表中的某些字符串太大而无法插入到CACHED表中的字段中。尝试查询,例如:
SELECT MAX(CHAR_LENGTH(UD_MDC_CODE)), MAX(CHAR_LENGTH(DRUG_GNR_NAME)), MAX(CHAR_LENGTH(DRUG_PRODUCT_NAME)) FROM textfiletable
查看结果并将最大长度与normaltable
的列大小进行比较。例如,如果UD_MDC_CODE的MAX值为29,则必须使此列更大。这可以使用此语句来完成,该语句将列的大小更改为30:
ALTER TABLE normaltable ALTER COLUMN UD_MDC_CODE SET DATA TYPE VARCHAR(30)
仅对大小小于MAX值的列使用ALTER TABLE语句。对所有太小的列完成此操作后,使用INSERT INTO语句将数据从TEXT表复制到CACHED表。这里记录了ALTER TABLE语句:
http://hsqldb.org/doc/2.0/guide/databaseobjects-chapt.html#dbc_table_manupulation