使用多个值插入sysadm.table名称

时间:2014-12-30 11:23:20

标签: sql guptateamdeveloper centura

我正在使用sql语句,但无法找到正确的语法。

我正在使用teamdeveloper 6.1进行编程,我正在使用函数SqlPrepareAndExecute(...)

我尝试的是插入一组值。在mysql上,它会像:

INSERT INTO supportContacts
    (type, details)
VALUES
    ('Email', 'admin@sqlfiddle.com'),
    ('Twitter', '@sqlfiddle');

使用SqlTalk我可以做到这一点......

INSERT INTO SYSADM.FOOBAR VALUES(:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13)
\
$datatypes CHARACTER,NUMERIC,NUMERIC,NUMERIC,NUMERIC,NUMERIC,NUMERIC,NUMERIC,NUMERIC,NUMERIC,NUMERIC,NUMERIC,NUMERIC
"01",0,0,0,0,0,0,0,0,0,0,0,0
"02",0,0,0,0,0,0,0,0,0,0,0,0
"03",0,0,0,0,0,0,0,0,0,0,0,0
"04",0,0,0,0,0,0,0,0,0,0,0,0
"05",0,0,0,0,0,0,0,0,0,0,0,0
"06",0,0,0,0,0,0,0,0,0,0,0,0
"07",0,0,0,0,0,0,0,0,0,0,0,0
"08",0,0,0,0,0,0,0,0,0,0,0,0
/

当我填充变量并在TD 6.1的SqlExecute函数中使用它时,Bot都无法工作

我总是遇到Statement not ended properlyInvalid constant等错误。

我还尝试将值设为:

('01',0,0,0,0,0,0,0,0,0,0,0,0),
('02',0,0,0,0,0,0,0,0,0,0,0,0),
('03',0,0,0,0,0,0,0,0,0,0,0,0), ...

...错误

我做错了什么?

编辑(我现在尝试的事情,直到现在):


尝试1

This here all


尝试2

"INSERT INTO SYSADM.FOOBAR VALUES(:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13)
\
$datatypes CHARACTER,NUMERIC,NUMERIC,NUMERIC,NUMERIC,NUMERIC,NUMERIC,NUMERIC,NUMERIC,NUMERIC,NUMERIC,NUMERIC,NUMERIC
'01',0,0,0,0,0,0,0,0,0,0,0,0
'02',0,0,0,0,0,0,0,0,0,0,0,0"

只说SQL command not properly ended


尝试3

我认为可能是因为\。实际上它是一个escapechar所以我像

一样逃脱了
"INSERT INTO SYSADM.FOOBAR VALUES(:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13)
\\
$datatypes....

现在它说无效字符


尝试4

"INSERT INTO SYSADM.FOOBAR VALUES(:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13)
\
$da...
\'01\',0,0,0,0,0,0,0,0,0,0,0,0
\'02\',0,0,0,0,0,0,0,0,0,0,0,0"

也失败了! :)

3 个答案:

答案 0 :(得分:0)

这可能只是由于示例查询,但我不确定您是否知道数据绑定在TD中是如何工作的:

INSERT INTO SYSADM.FOOBAR VALUES(:var1,:var2,:var3)

其中var1,var2,var3是在调用SqlExecute / SqlPrepareAndExecute的函数中可见的变量

答案 1 :(得分:0)

您的源数据是否在数据库表中? 然后您可以使用INSERT SELECT语句。

像这样:

INSERT INTO SYSADM.FOOBAR (COL1, COL2, COL3) SELECT COL1, COL2, COL3 FROM SOURCE_DATA

编辑:

或者您可以使用:

Call SqlPrepareAndExecute( hSql, '
INSERT INTO FOOBAR VALUES(:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13)
select \'01\',0,0,0,0,0,0,0,0,0,0,0,0 from dual union all
select \'02\',0,0,0,0,0,0,0,0,0,0,0,0 from dual union all
select \'03\',0,0,0,0,0,0,0,0,0,0,0,0 from dual union all
select \'04\',0,0,0,0,0,0,0,0,0,0,0,0 from dual union all
select \'05\',0,0,0,0,0,0,0,0,0,0,0,0 from dual union all
select \'06\',0,0,0,0,0,0,0,0,0,0,0,0 from dual union all
select \'07\',0,0,0,0,0,0,0,0,0,0,0,0 from dual union all
select \'08\',0,0,0,0,0,0,0,0,0,0,0,0 from dual ' )

答案 2 :(得分:0)

用于说明一般语法的一些代码 警告:

  1. 这是通过CTD 2.1完成的。
  2. 我遗漏了连接数据库的所有代码,只是假设h_SqlMain是一个有效的连接句柄。
  3. 数据来自数组。在现实生活中你会例如阅读CSV文件。
  4. 变量myTypemyDetail在SqlPrepare-Statment中用作绑定变量,因为CTD 2.1不支持直接使用数组变量作为绑定。
  5. "本地变量" -Part:

    String: myType
    String: myDetail
    String: types[*]
    String: details[*]
    Number: i
    Sql Handle: h_SqlMain
    

    "动作" -Part:

    Set types[0] = 'Email'
    Set details[0] = 'admin@sqlfiddle.com'
    Set types[1] = 'Twitter'
    Set details[1] = '@sqlfiddle'
    Set types[2] = 'Foo'
    Set details[2] = 'Bar'
    Call SqlPrepare( h_SqlMain, 
       "INSERT INTO supportContacts (type, details) 
        VALUES(:myType, :myDetail)")
    Set i=0
    While i <= 2 
        Set myType = types[i]
        Set myDetail = details[i]
        Call SqlExecute( h_SqlMain )
        Set i=i+1