I'm trying to add a simple function in to monetDB at database level, which just does sum(n) and returns the result
create function sys.foo(number int)
returns int
begin
declare tsum int;
set tsum = 0;
while number > 0 do
set tsum = tsum + number;
set number = number -1;
end while;
return tsum;
end;
While attempting to execute the above code i'm seeing error as follows
[Error Code: 0, SQL State: 42000] syntax error, unexpected $end, expecting WHILE: end of input stream in "create function sys.foo(number int)
I could add the same function in to MySQL, and it works!!
>select sys.foo(10)
sys.foo(10)
-----------
55
Could some one please let me know whats going wrong here?
这对我来说很好用(MonetDB,Mac OS X的2014年10月版)
➜ ~ mclient Welcome to mclient, the MonetDB/SQL interactive terminal (unreleased) Database: MonetDB v11.19.16 (unreleased), 'demo' Type \\q to quit, \\? for a list of available commands auto commit mode: on sql>create function sys.foo(number int) more>returns int more>begin more>declare tsum int; more>set tsum = 0; more>while number > 0 do more>set tsum = tsum + number; more>set number = number -1; more>end while; more>return tsum; more>end; operation successful (2.127ms)
sql>select sys.foo(10); +------------------+ | foo_single_value | +==================+ | 55 | +------------------+ 1 tuple (1.771ms)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.