使用 Oracle Insert Into...Values 插入多个值
Posted
技术标签:
【中文标题】使用 Oracle Insert Into...Values 插入多个值【英文标题】:Inserting multiple values with Oracle Insert Into...Values 【发布时间】:2014-02-05 02:06:57 【问题描述】:我试图在 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');
如果这种语法完全关闭,那么如何在一个语句中插入多个值?
【问题讨论】:
【参考方案1】:这样试试,
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。
【讨论】:
【参考方案2】:您始终可以使用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;
【讨论】:
以上是关于使用 Oracle Insert Into...Values 插入多个值的主要内容,如果未能解决你的问题,请参考以下文章