2012-09-13 63 views
0

我是SQL Anywhere的新手。我将我们在PostgreSQL 9.1中开发的数据库移植到SQL Anywhere 12.0.1。我有一个函数返回一个模式的所有组合作为结果集。模式是一系列字母和数字,组括括号括起来。例如,“A1 [0] [0]] Z1”是可能的一种这样的模式。该函数应该做的是将原本不在方括号内的任何字符按原样复制,然后为方括号中所有字符的每个组合返回一个字符串。所以函数返回的一个值应该是“A1000Z1”;另一个将是“A1O00Z1”,依此类推。在函数调用中不断收到“无效参数”错误

每当我调用函数,我得到下面的消息从SQL Anywhere:在

Coult not execute statement. Function 'AllCombinations' has invalid parameter 'Combination' ('OUT') 

这里是函数的源代码:

CREATE OR REPLACE PROCEDURE "AllCombinations" (
    IN Plate VARCHAR(50) 
) RESULT (Combination VARCHAR(50)) 
BEGIN 
    DECLARE @Combinations VARCHAR(8000); 
    DECLARE @Combination VARCHAR(50); 
    DECLARE i    INT  DEFAULT 1; 

    -- Create the temporary table to hold all of the combinations 
    CREATE TABLE #Combinations (
     Combination  VARCHAR(50) NOT NULL 
    ); 

    -- Get all of the combinations AS a big string 
    SET @Combinations = "NextDigit"(Plate, 1, ''); 

    -- Begin a loop 
    BuildCombinations: 
    LOOP 
     -- Find the i-th combination 
     SELECT row_value INTO @Combination 
     FROM sa_split_list(@Combinations, '|') 
     WHERE line_num = i; 

     -- Do we have a string? 
     IF @Combination <> '' THEN 
      -- We do. Add it to the Combinations table 
      INSERT INTO #Combinations (Combination) VALUES (@Combination); 
     ELSE 
      -- We do not. Exit the loop 
      LEAVE BuildCombinations; 
     END IF; 

     -- Move on to the next combination 
     SET i = i + 1; 
    END LOOP BuildCombinations; 

    -- Return all of the combinations we built 
    SELECT Combination FROM #Combinations; 
END; 

我不相信这个问题是在NextDigit存储过程。当我打电话时,我会得到正确的返回值。只是这个不会返回正确的值。

我的代码有什么问题?

托尼

+0

我怀疑这是什么原因导致你的问题,但你可能想要更改'CREATE TABLE'到'DECLARE LOCAL TEMPORARY TABLE'以避免头痛... – sybkar

+0

什么样的头痛? –

+0

如果不将表指定为临时表,则该过程将在每次运行时尝试创建它。这只会在第一次运作。如果你看一下'DECLARE LOCAL TEMPORARY TABLE',它只会声明表存在存储过程的持续时间...我怀疑这是你的行为。 http://dcx.sybase.com/index.html#1201/en/dbreference/create-table-statement.html http://dcx.sybase.com/index.html#1201/en/dbreference/declare-local -temporary-table-statement.html – sybkar

回答

1

我发现这个问题是不是在存储过程中,它是在调用存储过程的语句。

呼叫是这样写的:

SELECT "AllCombinations"('A1[0O][0O][0OU]Z1'); 

此产生的误差。另一方面,如果我写这样的电话:

SELECT Combination FROM "AllCombinations"('A1[0O][0O][0OU]Z1'); 

然后它的工作。第一种语法是它在PostgreSQL中的调用方式;它也使用PostgreSQL的RETURN NEXT语句来返回值。不同的数据库,语法不同。

相关问题