SAP Sybase WHILE 在 FOR 循环中

SAP Sybase WHILE inside of FOR LOOP

我正在努力让它发挥作用,但它一直想出

Could not execute statement.

Syntax error near 'BEGIN' on line 14
SQLCODE=-131, ODBC 3 State="42000"
Line 1, column 1
You can continue executing or stop.

代码如下:

IF VAREXISTS('@count') = 0  THEN CREATE VARIABLE @count  int; END IF;
IF VAREXISTS('@string') = 0  THEN CREATE VARIABLE @string char(50); END IF;
IF VAREXISTS('@found') = 0  THEN CREATE VARIABLE @found char(50); END IF;
IF VAREXISTS('@result') = 0  THEN CREATE VARIABLE @result char(50); END IF;
IF VAREXISTS('@fieldsToSearch') = 0  THEN CREATE VARIABLE @fieldsToSearch long varchar; END IF;

SET @count = 0;
SET @string = '';
SET @found = '';
SET @result = '';
SET @fieldsToSearch = '';

FOR LoopGetForeignChar AS CursGetForeignChar Dynamic Scroll CURSOR FOR ( -- Line 1
    SELECT
        row_value stringToSearch
    FROM
        sa_split_list(@fieldsToSearch) 
    WHERE
        A1 <> '' 
    ORDER BY A1
    )
DO
    SET @string = stringToSearch;

    WHILE @count <= Length(@string)
    BEGIN                                                                -- Line 14
        SET @found = (SELECT SUBSTR(@String, @count, 1) WHERE SUBSTR(@String, @count, 1) NOT REGEXP '[a-zA-Z0-9]*')
        SET @result = @result + (SELECT STRING(@found,'x') WHERE LOCATE(@result, @found) = 0 )
        SET @count = @count + 1
    END

END FOR;

我已经检查过,@fieldsToSearch 包含一个用逗号分隔的字母数字字符串列表。

工作逻辑:

这是更大的 SQL 的一部分,一直到现在。

原来 FOR 语句是 WATCOM SQL 而

WHILE something
BEGIN 
<do this>
END 

是 TRANSACTSQL。

解决方法: 使用 WHILE 语句的 WATCOM SQL 版本:

WHILE something LOOP
<do this>
END LOOP