DB2正则表达式SQL在绿屏上不起作用。

huangapple go评论54阅读模式
英文:

DB2 regular expression sql not working in green screen

问题

面临一个奇怪的问题,下面的SQL查询在"运行SQL脚本" GUI中返回了预期的结果,但在绿屏STRSQL中却没有返回正确的值。这意味着我无法正确地嵌入这个SQL到一个SQLRPGLE程序中。

在运行SQL GUI中的结果是这样的:

0374 ARTX LU 079 PUBLDTE=20120101 LA2=B C PD A

但是当我在STRSQL中运行以下查询时,

SELECT wrktitle FROM IACDTAA.IACWTL WHERE workkey = 57944682 and
REGEXP_LIKE(TRIM(WRKTITLE), '^[0-9]{6}.*') 

我得到了下面的输出,这是不正确的!

0374 ARTX LU 079 PUBLDTE=20120101 LA2=B C PD A
英文:

Facing a weird issue where the below SQL query returns expected results in "Run SQL scripts" gui but whereas in green screen STRSQL, it just doesn't return the right values. Meaning, I would not be able to embed this SQL properly in an SQLRPGLE program.

SELECT wrktitle FROM IACDTAA.IACWTL WHERE workkey = 57944682 and        
REGEXP_LIKE(TRIM(WRKTITLE), '^[0-9]{4}.*')     

Result from RUN SQL gui is this:

0374 ARTX LU 079 PUBLDTE=20120101 LA2=B C PD A        

But when I run the below in STRSQL,

SELECT wrktitle FROM IACDTAA.IACWTL WHERE workkey = 57944682 and
REGEXP_LIKE(TRIM(WRKTITLE), '^[0-9]{6}.*') 

I get the below output, which is incorrect !

 0374 ARTX LU 079 PUBLDTE=20120101 LA2=B C PD A   

答案1

得分: 1

我发现使用某些SQL文本函数,特别是ASCII、REGEXP_SUBST和其他REGEXP函数,在GUI JDBC/ODBC环境中可以得到正确的结果,但在RPG或STRSQL的绿屏界面中(包括调用UDF),如果我不在RPG或SQL代码中特别声明字符串变量带有CCSID参数,就会得到错误的结果或报错。这是因为该环境中默认的CCSID被声明为EBCDIC,但这些函数期望ASCII或UTF字符串。

如果你使用WRKACTJOB查看活动作业,你可能会看到不同作业可以有不同的默认CCSID,而像437或1208这样的CCSID可能会在为远程SQL请求提供服务的PJ作业中出现。

英文:

I have found that using certain SQL text functions, specifically ASCII, REGEXP_SUBST, and other REGEXP functions will give correct results in a GUI JDBC/ODBC environment, but will give wrong results or error out in the green screen of RPG or STRSQL (including calling UDF's) unless I specifically declare the string variables with a CCSID parameter in RPG or SQL code. This is because the default CCSID in that environment is declared to be EBCDIC, but these functions expect ASCII or UTF strings.

If you look at the active jobs using WRKACTJOB, you may see that different jobs can have different default CCSIDs, and the PJ ones that service remote SQL requests like JDBC/ODBC probably will have a CCSID like 437 or 1208.

答案2

得分: 0

请尝试在RPG程序中使用,不要假设因为STRSQL输出不正确,RPG也会如此。STRSQL与SQL预编译器/RPG编译器/RPG运行时组合非常不同。

英文:

Don't assume that because STRSQL gives incorrect output that RPG will, too. STRSQL is very different to the SQL precompiler / RPG compiler / RPG runtime combination.

Please try it in an RPG program.

huangapple
  • 本文由 发表于 2023年5月25日 18:09:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76331131.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定