使用 SQL 通过 QSYS2.IFS_WRITE 将 json 文件发送到 IBM System i 上的 IFS
Using SQL to send json file to IFS on IBM System i with QSYS2.IFS_WRITE
我想从 db2 文件中提取数据并将它们以 .json 格式写入 IFS。
以下代码在将平面文件发送到 IFS 时确实有效。
BEGIN
CALL QSYS2.IFS_WRITE(
PATH_NAME =>'/myIFSdir/testout.txt',
LINE => '',
OVERWRITE => 'REPLACE',
END_OF_LINE => 'NONE',
FILE_CCSID => 1208);
FOR select btbnbr as a
from gldbfa/glpbt
where btbnbr in (241858, 241934, 241983, 242534, 242538, 242657, 242708, 242717, 242723)
DO
CALL QSYS2.IFS_WRITE(
PATH_NAME => '/myIFSdir/testout.txt',
LINE => a,
FILE_CCSID => 1208);
END FOR;
END;
但是,当添加 json 格式时,它不再有效并产生错误。
BEGIN
CALL QSYS2.IFS_WRITE(
PATH_NAME =>'/myIFSdir/testout.json',
LINE => '',
OVERWRITE => 'REPLACE',
END_OF_LINE => 'NONE',
FILE_CCSID => 1208);
FOR select
json_object('top' value (json_arrayagg(
json_object ('number' value btbnbr)
))) as a
from gldbfa/glpbt
where btbnbr in (241858, 241934, 241983, 242534, 242538, 242657, 242708, 242717, 242723)
DO
CALL QSYS2.IFS_WRITE(
PATH_NAME => '/myIFSdir/testout.json',
LINE => a,
FILE_CCSID => 1208);
END FOR;
END;
错误是:
SQL State: 42904
Vendor Code: -7032
Message: [SQL7032] SQL procedure, function, trigger, or variable *N in *N not created. Cause . . . . . : SQL procedure, function, trigger, or variable *N in *N, or program for compound (dynamic) statement was not created. The compile was not successful. SQL creates an SQL procedure, function, trigger, variable, or a compound (dynamic) statement as a C program that contains embedded SQL. Errors not found during the initial parsing of the CREATE PROCEDURE, ALTER PROCEDURE, CREATE FUNCTION, ALTER FUNCTION, CREATE TRIGGER, CREATE VARIABLE, or compound (dynamic) statement can be found during the precompile. Recovery . . . : If a compile error occurred, see the appropriate listing in QSYSPRT. If the SQL precompile failed, there is always a listing with the error. If the C compile failed, the listing is only created if requested. Specify SET OPTION OUTPUT=*PRINT prior to the routine body in the CREATE PROCEDURE, CREATE FUNCTION, or CREATE TRIGGER statement if listings are required. To see these errors for a compound (dynamic) statement, temporarily change it to a CREATE PROCEDURE statement.
我在V7R3M0
PTF SF99703 是 22 级
感谢您的帮助,
似乎生成的 C 代码试图创建一个可以接收的结构 a
太大了
$$$***/
typedef struct {
/***$$$
SQL TYPE IS CLOB(2147483647) A
$$$***/
_Packed struct A_t {
unsigned long length;
char data[2147483647];
} A
;
short SQLP_I2;
short AT_END;
unsigned SQLCursorOpen_0 :1;
} SQLP_L4_T;
SQLP_L4_T SQLP_L4;
*=SEVERE==========> a - CZM0049 The size of object SQLP_L4 exceeds the compiler limit.
如果你需要那么大的 clob 那么我想你必须问 IBM,或者使用 declare/open/fetch 游标(它将使用定位器)
但如果没有,如果15M足够的话,你可以CAST(... AS CLOB(15M))
BEGIN
CALL QSYS2.IFS_WRITE(
PATH_NAME =>'/myIFSdir/testout.json',
LINE => '',
OVERWRITE => 'REPLACE',
END_OF_LINE => 'NONE',
FILE_CCSID => 1208);
FOR select
cast(json_object('top' value (json_arrayagg(
json_object ('number' value btbnbr)
))) as clob(15m)) as a
from (values 241858, 241934, 241983, 242534, 242538, 242657, 242708, 242717, 242723) e (btbnbr)
DO
CALL QSYS2.IFS_WRITE(
PATH_NAME => '/myIFSdir/testout.json',
LINE => a,
FILE_CCSID => 1208);
END FOR;
end
切换到 json_arrayagg
后,就不需要 for
循环了。 json_object
或 json_arrayagg
的整个 select 可以指定为 ifs_write
过程的 line
参数的值。
CALL QSYS2.IFS_WRITE(
PATH_NAME => '/home/steve/srcmbr.json',
overwrite => 'REPLACE',
LINE => (
select json_arrayagg(
json_object('srcseq' value a.srcseq,
'srcdat' value a.srcdat,
'srcdta' value rtrim(a.srcdta))
) json
from qrpglesrc a ),
FILE_CCSID => 1208)
我想从 db2 文件中提取数据并将它们以 .json 格式写入 IFS。 以下代码在将平面文件发送到 IFS 时确实有效。
BEGIN
CALL QSYS2.IFS_WRITE(
PATH_NAME =>'/myIFSdir/testout.txt',
LINE => '',
OVERWRITE => 'REPLACE',
END_OF_LINE => 'NONE',
FILE_CCSID => 1208);
FOR select btbnbr as a
from gldbfa/glpbt
where btbnbr in (241858, 241934, 241983, 242534, 242538, 242657, 242708, 242717, 242723)
DO
CALL QSYS2.IFS_WRITE(
PATH_NAME => '/myIFSdir/testout.txt',
LINE => a,
FILE_CCSID => 1208);
END FOR;
END;
但是,当添加 json 格式时,它不再有效并产生错误。
BEGIN
CALL QSYS2.IFS_WRITE(
PATH_NAME =>'/myIFSdir/testout.json',
LINE => '',
OVERWRITE => 'REPLACE',
END_OF_LINE => 'NONE',
FILE_CCSID => 1208);
FOR select
json_object('top' value (json_arrayagg(
json_object ('number' value btbnbr)
))) as a
from gldbfa/glpbt
where btbnbr in (241858, 241934, 241983, 242534, 242538, 242657, 242708, 242717, 242723)
DO
CALL QSYS2.IFS_WRITE(
PATH_NAME => '/myIFSdir/testout.json',
LINE => a,
FILE_CCSID => 1208);
END FOR;
END;
错误是:
SQL State: 42904
Vendor Code: -7032
Message: [SQL7032] SQL procedure, function, trigger, or variable *N in *N not created. Cause . . . . . : SQL procedure, function, trigger, or variable *N in *N, or program for compound (dynamic) statement was not created. The compile was not successful. SQL creates an SQL procedure, function, trigger, variable, or a compound (dynamic) statement as a C program that contains embedded SQL. Errors not found during the initial parsing of the CREATE PROCEDURE, ALTER PROCEDURE, CREATE FUNCTION, ALTER FUNCTION, CREATE TRIGGER, CREATE VARIABLE, or compound (dynamic) statement can be found during the precompile. Recovery . . . : If a compile error occurred, see the appropriate listing in QSYSPRT. If the SQL precompile failed, there is always a listing with the error. If the C compile failed, the listing is only created if requested. Specify SET OPTION OUTPUT=*PRINT prior to the routine body in the CREATE PROCEDURE, CREATE FUNCTION, or CREATE TRIGGER statement if listings are required. To see these errors for a compound (dynamic) statement, temporarily change it to a CREATE PROCEDURE statement.
我在V7R3M0
PTF SF99703 是 22 级
感谢您的帮助,
似乎生成的 C 代码试图创建一个可以接收的结构 a
太大了
$$$***/
typedef struct {
/***$$$
SQL TYPE IS CLOB(2147483647) A
$$$***/
_Packed struct A_t {
unsigned long length;
char data[2147483647];
} A
;
short SQLP_I2;
short AT_END;
unsigned SQLCursorOpen_0 :1;
} SQLP_L4_T;
SQLP_L4_T SQLP_L4;
*=SEVERE==========> a - CZM0049 The size of object SQLP_L4 exceeds the compiler limit.
如果你需要那么大的 clob 那么我想你必须问 IBM,或者使用 declare/open/fetch 游标(它将使用定位器)
但如果没有,如果15M足够的话,你可以CAST(... AS CLOB(15M))
BEGIN
CALL QSYS2.IFS_WRITE(
PATH_NAME =>'/myIFSdir/testout.json',
LINE => '',
OVERWRITE => 'REPLACE',
END_OF_LINE => 'NONE',
FILE_CCSID => 1208);
FOR select
cast(json_object('top' value (json_arrayagg(
json_object ('number' value btbnbr)
))) as clob(15m)) as a
from (values 241858, 241934, 241983, 242534, 242538, 242657, 242708, 242717, 242723) e (btbnbr)
DO
CALL QSYS2.IFS_WRITE(
PATH_NAME => '/myIFSdir/testout.json',
LINE => a,
FILE_CCSID => 1208);
END FOR;
end
切换到 json_arrayagg
后,就不需要 for
循环了。 json_object
或 json_arrayagg
的整个 select 可以指定为 ifs_write
过程的 line
参数的值。
CALL QSYS2.IFS_WRITE(
PATH_NAME => '/home/steve/srcmbr.json',
overwrite => 'REPLACE',
LINE => (
select json_arrayagg(
json_object('srcseq' value a.srcseq,
'srcdat' value a.srcdat,
'srcdta' value rtrim(a.srcdta))
) json
from qrpglesrc a ),
FILE_CCSID => 1208)