简体   繁体   English

MonetDB准备函数中的语句

[英]MonetDB Prepare Statement in Function

I'm trying to create a function that takes the parameters for the column, the table, the limit, and offset. 我正在尝试创建一个函数,该函数采用列,表,限制和偏移量的参数。 Basically, I want to be able to get a specified number of rows data from a specified table from a specified column. 基本上,我希望能够从指定列的指定表中获取指定数量的行数据。

However, I'm unable to get the following code to work - I get several errors such as: 但是,我无法使以下代码正常工作-我遇到了一些错误,例如:

syntax error, unexpected SELECT, expecting ':' in: "create function get_banana(lim int, off int, tbl varchar(32), col varchar(32)) r"
syntax error, unexpected RETURN in: "return"
syntax error, unexpected END in: "end"

These errors seem kind of meaningless. 这些错误似乎毫无意义。

My code is as follows: 我的代码如下:

CREATE FUNCTION GET_BANANA(lim int, off int, tbl varchar(32), col varchar(32)) 
RETURNS TABLE (clm int) 
BEGIN 
    PREPARE SELECT col FROM tbl LIMIT ? OFFSET ?; 
    RETURN EXEC (lim, off); 
END;

I'd appreciate any help :) Thanks! 我将不胜感激:)谢谢!

I see at least two issues 我至少看到两个问题

  • EXEC needs the identifier that is returned by PREPARE , eg: EXEC需要PREPARE返回的标识符,例如:

     sql>prepare select * from tables; execute prepared statement using: EXEC 2(...) sql>exec 2(); 
  • The function parameters tbl and col are string values. 函数参数tblcol是字符串值。 You cannot use them as table/column identifiers. 您不能将它们用作表/列标识符。

Having said that, I am not even sure if PREPARE can be used inside a function. 话虽如此,我什至不确定是否可以在函数内使用PREPARE

不,PREPARE是顶层语句修饰符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM