我正在尝试在Oracle 11g中运行以下命令,但一直收到“命令未正确结束”的错误。我是Oracle的新手,我无法找到有关插入多个值集的任何内容(除非从表中选择它们,否则它们不是)....
INSERT INTO category (catcode, catdesc)
VALUES ('BUS', 'BUSINESS'),
('CHN', 'CHILDREN'),
('COK', 'COOKING'),
('COM', 'COMPUTER'),
('FAL', 'FAMILY LIFE'),
('FIT', 'FITNESS'),
('SEH', 'SELF HELP'),
('LIT', 'LITERATURE'),
('CHN', 'CHILDREN'),
('BUS', 'BUSINESS');
如果此语法完全关闭,那么如何在一个语句中插入多个值?
答案 0 :(得分:6)
试试这个,
INSERT ALL
INTO category (catcode, catdesc) VALUES ('BUS', 'BUSINESS')
INTO category (catcode, catdesc) VALUES ('CHN', 'CHILDREN')
INTO category (catcode, catdesc) VALUES ('COK', 'COOKING')
INTO category (catcode, catdesc) VALUES ('COM', 'COMPUTER')
INTO category (catcode, catdesc) VALUES ('FAL', 'FAMILY LIFE')
INTO category (catcode, catdesc) VALUES ('FIT', 'FITNESS')
INTO category (catcode, catdesc) VALUES ('SEH', 'SELF HELP')
INTO category (catcode, catdesc) VALUES ('LIT', 'LITERATURE')
INTO category (catcode, catdesc) VALUES ('CHN', 'CHILDREN')
INTO category (catcode, catdesc) VALUES ('BUS', 'BUSINESS')
SELECT * FROM DUAL;
有关详情,请参阅here。
答案 1 :(得分:5)
您始终可以使用insert . . . select
语法:
INSERT INTO category (catcode, catdesc)
select 'BUS', 'BUSINESS' from dual union all
select 'CHN', 'CHILDREN' from dual union all
select 'COK', 'COOKING' from dual union all
select 'COM', 'COMPUTER' from dual union all
select 'FAL', 'FAMILY LIFE' from dual union all
select 'FIT', 'FITNESS' from dual union all
select 'SEH', 'SELF HELP' from dual union all
select 'LIT', 'LITERATURE' from dual union all
select 'CHN', 'CHILDREN' from dual union all
select 'BUS', 'BUSINESS' from dual;