暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

GBase 8s SPL语法

wj2021 2022-04-20
871

概述 

SPL例程由开始语句,语句块,结束语句组成。 SPL例程根据是否需要返回值,分为存储过程和函数。 语句块由SQL和SPL语句组成。 

存储过程 

语法 

create procedure proc_name(param1 data_type1, param2 data_type2, ...)

    spl_code;

end procedure;

 

函数 

语法 

create function func_name(param1 data_type1, param2 data_type2, ...)

returning data_type1 [as id1], data_type2 [as id2], ...

spl_code;

    return val1, val2, ... [with resume];

end function;

 

语法 


变量声明 

语法  

create procedure proc_name(param1 data_type1, param2 data_type2, ...)

    spl_code;

end procedure;

define m, n int;

define global i int default 1;

 

变量赋值 

语法 

let var = value;

let var1, var2,... = val1, val2, ...;

let var1, var2, ... = function(args1, args2, ...);

let var1, var2, ... = (select col1, col2, ... from table_name);

 

 

 

条件 

语法 

case expr

when val_1 then

    code_1

[when val_2 then

code_2 ...]

else

    code_n

end case;

 

 

 

循环 

GOTO

语法 

<<lbl_goto>>

    spl_code;

if expr then

    goto lbl_goto;

end if;

 

LOOP

语法 

 

loop

    if expr then

exit; end if;

end loop;

loop

    exit when expr;

end loop;

 

 

 

FOR/FOREACH

语法 

for i in (start_val to end_val) loop

    spl_code;

end loop;

for i in (start_val to end_val)

    spl_code;

end for;

foreach select col1, col2,... into var1, var2,... from table_name

    spl_code;

end foreach;

 

WHILE

语法 

while expr loop

    spl_code;

end loop;

while expr

    spl_code;

end while;

 

异常处理 

语法 

on exception [in (...)] set sql_err_num[,isam_err_num]

    spl_code;

end exception [with resume];

 

 

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论