Anmelden

View Full Version : JSON_TABLE in dynamischem SQL verwenden



Seiten : 1 [2]

Fuerchau
19-12-18, 17:02
Solange dein CLOB < 8 mb ist, kannst du ggf. auch eine Hostvariable vom Typ Unicode bis 8MB definieren. Einen CLOB brauchst du da noch nicht.

Ansonsten gibt es da noch den DBCLOB, der nun tatsächlich als Unicode 1200 definiert ist (max. 8 M).
Du kannst also von deinem HTTP-Request den CLOB in DBCLOB aus dem CLOB mit CCSID 1208 casten.
Der Typ der generierten Variablen ist GRAPH und die CCSID dafür bestimmst du in der H-Zeile (Default 1200, früher 13488).

PS:
Da warst du wirklich schneller. Aber eine CCSID kannst du auch hier nicht angeben, da der Default bereits 1200 ist.

dschroeder
20-12-18, 09:17
Vielen Dank. Wenn 1200 der Default Wert ist, werde ich ccsid(1200) weglassen. Macht den Code kürzer.

dschroeder
20-12-18, 09:25
Das Weglassen von ccsid(1200) geht leider doch nicht. Ich bekomme folgenden Fehler bei Kompilieren:

json_clobDS_data = %trim(json_in);
RNF0659: Implizite Zeichenfolgeumsetzung wird für Operand JSON_CLOBDS ... mit CCSID *GRAPH: *IGNORE nicht unterstützt.

Liegt möglicherweise an unseren Compileoptionen. Aber kein Problem. Dann schreibe ich ccsid(1200) halt explizit dran.

AG1965_2
20-12-18, 09:42
JSON ist aber per Definition immer UTF-8, das wäre CCSID 1208. Geht die?

dschroeder
20-12-18, 10:06
JSON ist aber per Definition immer UTF-8, das wäre CCSID 1208. Geht die?

Nein.



dcl-s json_clobDS sqltype(dbclob:200000) ccsid(1208);
SQL5067 ID des codierten Zeichensatzes (CCSID) 1208 ist für JSON_CLOBDS nicht gültig.

Fuerchau
20-12-18, 10:11
Du musst die CCSID für GRAPH in der H-Zeile definieren:

CCSID(*GRAPH : parameter | *UCS2 : number | *CHAR :
*JOBRUN)
CCSID(*GRAPH) and CCSID(*UCS2) set the default graphic (*GRAPH) and UCS-2
(*UCS2) CCSIDs for the module. These defaults are used for literals, compile-time
data, program-described input and output fields, and data definitions that do not
have the CCSID keyword coded.
CCSID(*CHAR) sets the CCSID used for the module’s character data at runtime.
CCSID(*GRAPH : *IGNORE | *SRC | number)
Sets the default graphic CCSID for the module. The possible values are:
*IGNORE
This is the default. No conversions are allowed between graphic and
UCS-2 fields in the module. The %GRAPH built-in function cannot be
used.
*SRC
The graphic CCSID associated with the CCSID of the source file will be
used.
number
A graphic CCSID. A valid graphic CCSID is 65535 or a CCSID with the
EBCDIC double-byte encoding scheme (X’1200’).
CCSID(*UCS2 : number)
Sets the default UCS-2 CCSID for the module. If this keyword is not
specified, the default UCS-2 CCSID is 13488.
number must be a UCS-2 CCSID. A valid UCS-2 CCSID has the UCS-2
encoding scheme (x’7200’). For example, the UTF-16 CCSID 1200 has
encoding scheme x’7200’.
If CCSID(*GRAPH : *SRC) or CCSID(*GRAPH : number) is specified:
v Graphic and UCS-2 fields in externally-described data structures will use the
CCSID in the external file.
v Program-described graphic or UCS-2 fields will default to the graphic or UCS-2
CCSID of the module, respectively. This specification can be overridden by using
the CCSID(number) keyword on the definition of the field. (See “CCSID(number
| *DFT)” on page 325.)
v Program-described graphic or UCS-2 input and output fields and keys are
assumed to have the module’s default CCSID.
CCSID(*CHAR : *JOBRUN)
When CCSID(*CHAR:*JOBRUN) is specified, character data will be
assumed to be in the job CCSID at runtime. The character X’0E’ will be
assumed to be a shift-out character only if the runtime job CCSID is a
mixed-byte CCSID.
Control-Specification Keywords
260 ILE RPG Reference
|
|
#
#
#
When CCSID(*CHAR : *JOBRUN) is not specified, character data will be
assumed to be in the mixed-byte CCSID related to the job CCSID. If the
character X’0E’ appears in character data, it will be interpreted as a
shift-out character. This may cause incorrect results when character data is
converted to UCS-2 data.
Note: Specifying CCSID(*CHAR:*JOBRUN) does not change the behaviour
of the compiler with respect to character literals containing X’0E’.
When a character literal contains X’0E’, the compiler will always
treat it as a shift-out character, independent of the CCSID(*CHAR)
keyword

Also
H CCSID(*GRAPH:1200)

Dann sollte der DBCLOB mit 1200 definiert werden.
Zusätzlich musst du das Ergebnis des HTTP-Requests, das ja vom Typ CLOB ist, in DBCLOB umwandeln:
cast(http..... as DBCLOB(1000000, 1208))
oder
DBCLOB(http....., 1000000, 1208)