嵌入式 SQL 中的 UNION 子句
UNION clause in embedded SQL
我正在使用 ingres 10S SQL,我正在尝试在嵌入式 SQL C 程序中编写以下 SQL 语句。它作为独立的 SQL 脚本工作正常,但编译 eSQL 程序会出现错误
%% Error in file localtask.sc, Line 498:
E_EQ0244 Syntax error on 'union'.
INSERT INTO nr301_tab2 (authority_id)
SELECT a.authority_id
FROM nrremdets a, nrstatus_hierarchy z
WHERE a.authority_id = z.authority_id
UNION
SELECT a.authority_id
FROM nrsumsamts a, nrsumsdets b
WHERE a.authority_id = b.authority_id;
(第 498 行是 UNION
行)那个 UNION
子句有什么问题?
只需稍微调整一下查询,它就可以工作了。试试这个:
INSERT INTO nr301_tab2 (authority_id)
SELECT authority_id
FROM
(SELECT a.authority_id
FROM nrremdets a, nrstatus_hierarchy z
WHERE a.authority_id = z.authority_id
UNION
SELECT a.authority_id
FROM nrsumsamts a, nrsumsdets b
WHERE a.authority_id = b.authority_id) Result
想法是合并结果集,这将创建一个新的结果集,并在 table 中插入一次。通过添加括号,我们可以确保发生这种情况。
我正在使用 ingres 10S SQL,我正在尝试在嵌入式 SQL C 程序中编写以下 SQL 语句。它作为独立的 SQL 脚本工作正常,但编译 eSQL 程序会出现错误
%% Error in file localtask.sc, Line 498: E_EQ0244 Syntax error on 'union'.
INSERT INTO nr301_tab2 (authority_id)
SELECT a.authority_id
FROM nrremdets a, nrstatus_hierarchy z
WHERE a.authority_id = z.authority_id
UNION
SELECT a.authority_id
FROM nrsumsamts a, nrsumsdets b
WHERE a.authority_id = b.authority_id;
(第 498 行是 UNION
行)那个 UNION
子句有什么问题?
只需稍微调整一下查询,它就可以工作了。试试这个:
INSERT INTO nr301_tab2 (authority_id)
SELECT authority_id
FROM
(SELECT a.authority_id
FROM nrremdets a, nrstatus_hierarchy z
WHERE a.authority_id = z.authority_id
UNION
SELECT a.authority_id
FROM nrsumsamts a, nrsumsdets b
WHERE a.authority_id = b.authority_id) Result
想法是合并结果集,这将创建一个新的结果集,并在 table 中插入一次。通过添加括号,我们可以确保发生这种情况。