sql - 如何在 Informix SQL 中插入多行?

标签 sql informix

我想使用单个插入语句插入多行。

以下代码插入一行,并且工作正常:

create temp table mytmptable
(external_id char(10),
int_id integer,
cost_amount decimal(10,2)
) with no log;

insert into mytmptable values 
('7662', 232, 297.26);

select * from mytmptable;

我尝试将插入更改为此,但它给出了语法错误:

insert into mytmptable values 
('7662', 232, 297.26),
('7662', 232, 297.26);

有没有办法让它工作,或者我需要运行很多插入吗?

最佳答案

你总是可以做这样的事情:

insert into mytmptable
select * 
from (
  select '7662', 232, 297.26 from table(set{1})
  union all
  select '7662', 232, 297.26 from table(set{1})
)

非常确定这是标准 SQL 并且可以在 Informix 上运行(派生表对于 Informix 接受 INSERT .. SELECT 语句中的 UNION ALL 是必需的)。

关于sql - 如何在 Informix SQL 中插入多行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12343857/

相关文章:

mysql - 有什么方法可以检查mysql中是否有一个表有我想要的字段名?

java - Entitymanager.persist 在 Informix UDR 中失败

sql - 如何将包含重复表的关联子查询转换为非关联子查询?

apache - 将 Informix JDBC 添加到 Jasper 服务器

sql - 缓冲池中没有可用的空闲缓冲区

mysql - 优化 mySQL 的 SQL 查询

SQL n 对 n 匹配多个值

sql - 我是否有理由选择包含 SHA1 十六进制摘要的字符串列?

linux - 从 HP-UX 迁移到 Red Hat Linux 时,ESQL/C 程序的不兼容性是什么?

informix - 如何在informix中获取之前执行过的sql