从不同数据库插入表
SQL
INSERT INTO t_publikasi
("idPublikasi","kdBahanPustaka","bulanTerbit", "tahunTerbit", "noUrutBI",
"pdfDir", "judul")
SELECT *
FROM dblink('dbname=perpus2 port=5432 user=dbdev password=develop',
'SELECT '113' || substring("no_pustaka",4,2) as bb ||
substring("no_pustaka",6,2) as cc ||
substring("no_pustaka",9,4) as dd,
'113',
substring("no_pustaka",4,2) as bb,
substring("no_pustaka",6,2) as cc,
substring("no_pustaka",9,4) as dd,
"file_pdf","judul"
FROM kuesioner
ORDER BY bb, cc, dd') AS kuesioner (
id varchar(10),
kd varchar(10),
bln varchar(10),
thn varchar(10),
urut varchar(10),
file_pdf varchar(50),
judul varchar(50));
错误
ERROR: syntax error at or near "113"
LINE 1: ...2 port=5432 user=dbdev password=develop','SELECT '113' || su...
^
ERROR: syntax error at or near "113"
SQL state: 42601
SQL
INSERT INTO t_publikasi
("idPublikasi","kdBahanPustaka","bulanTerbit", "tahunTerbit", "noUrutBI",
"pdfDir", "judul")
SELECT *
FROM dblink('dbname=perpus2 port=5432 user=dbdev password=develop',
'SELECT '113' || substring("no_pustaka",4,2) as bb ||
substring("no_pustaka",6,2) as cc ||
substring("no_pustaka",9,4) as dd,
'113',
substring("no_pustaka",4,2) as bb,
substring("no_pustaka",6,2) as cc,
substring("no_pustaka",9,4) as dd,
"file_pdf","judul"
FROM kuesioner
ORDER BY bb, cc, dd') AS kuesioner (
id varchar(10),
kd varchar(10),
bln varchar(10),
thn varchar(10),
urut varchar(10),
file_pdf varchar(50),
judul varchar(50));
ERRORS
ERROR: syntax error at or near "113"
LINE 1: ...2 port=5432 user=dbdev password=develop','SELECT '113' || su...
^
ERROR: syntax error at or near "113"
SQL state: 42601
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更改
将'SELECT '113'
为
'SELECT 113
或
'SELECT "113"
希望有帮助。
change
'SELECT '113'
to
'SELECT 113
or
'SELECT "113"
Hope it helps.
当您编写
'SELECT '113'||
时,您将终止包含 SELECT 语句的 dblink() 调用的第二个参数,然后启动一个数字文本 113。'SELECT 113
之所以有效,是因为它将选择一个数字而不是字符。然后,
||
运算符将默默地将其转换回字符值。在字符文字中嵌入单引号的正确方法是编写两个单引号:
, 'SELECT ''113''||substring(... '
When you write
'SELECT '113'||
you are terminating the second parameter for the dblink() call that contains the SELECT statement and then you start a numeric literal that is 113.'SELECT 113
works because it will select a number instead of a character literal.The
||
operator will then silently cast that back to a character value.The proper way to embedd a single quote in a character literal is to write two single quotes:
, 'SELECT ''113''||substring(... '
使用
E
或美元引用。Use
E
or dollar quoting.