众所周知,Progress提供了4种大型对象数据类型数据类型MEMPTR、CLOB、BLOB、LONGCHAR。
但是字符串函数不能用于CLOB或LONGCHAR数据类型。
如何使用对这些LOB数据类型执行字符串操作。"字符串操作"是指可以对字符串执行的子字符串、替换、修剪等功能。更清晰的
将vChar定义为字符INITIAL"ashdbi"NO_UNDO。消息替换(vChar,1,1)视图即警报框。
我们可以用同样的方式对LOB执行字符串操作吗?
CLOB存储在数据库中,LONGCHAR是用于在本地操作它的数据类型。如果存储BLOB,如果要在本地处理,则必须使用MEMPTR。
由于您询问了与STRING相关的函数,我认为CLOBS和LONGCHARs就是您想要的(CLOB=Chararcter Large Object,应该是BLOB=Binary Large Object)。
LONGCHARS上可以使用几个(或一些)字符串操作方法和函数,例如SUBSTRING。无论您使用的是CHARACTER还是LONGCHAR,都会显示语法。如果你想
示例-SUBSTRING、INDEX和COPY-LOB
DEFINE VARIABLE cStart AS LONGCHAR NO-UNDO.
DEFINE VARIABLE cEnd AS LONGCHAR NO-UNDO.
DEFINE VARIABLE cString AS CHARACTER NO-UNDO.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
/* Fill the variable with lots of bogus data */
DO i = 1 TO 10000:
cStart = cStart + "ABCDEFGHIJKLMN".
/* Insert a _ once in 100 */
IF RANDOM(1, 100) = 100 THEN cStart = cStart + "_".
END.
DISPLAY LENGTH(cStart).
/* SUBSTRING */
cEnd = SUBSTRING(cStart, 1, 100000).
DISPLAY LENGTH(cEnd).
/* Is there a _ in the string - most likely! */
DISPLAY INDEX(cStart, "_").
/* SUBSTRING will convert output to CHARACTER if the length is less than roughly 32k */
cString = SUBSTRING(cStart, 1, 30000).
DISPLAY cString.
/* Lets save the CLOB so we can look at it */
COPY-LOB FROM cStart TO FILE "c:temptesting.txt".
/* Actually you can DISPLAY a LONGCHAR as well but why would you really? */
DISPLAY cStart
VIEW-AS EDITOR LARGE INNER-LINES 300 INNER-CHARS 300
WITH FRAME x1 WIDTH 320 .
旧版本中有一些例外,但"字符串函数"在longchar数据上运行得很好。
要在各种大型对象(CLOB、BLOB、MEMPTR和文件)之间获取数据,并将其放入LONGCHAR中,反之亦然,您需要使用COPY-LOB语句。怀疑那就是你所缺少的"秘密酱汁"。
例如:
define variable cfgData as longchar no-undo.
assign file-info:file-name = search( "etc/stomp.cfg" ).
copy-lob from file file-info:full-pathname to cfgData no-error.
stompCfg = new dotr.Stomp.StompConfig().
assign
stompCfg:StompPort = "61613"
stompCfg:StompServer = entry( 1, cfgData, ":" )
stompCfg:StompPort = entry( 2, cfgData, ":" ) when num-entries( cfgData, ":" ) > 1
stompCfg:LargeMessageSupport = yes
.