gbase8s 存储过程示例

gbase不支持sys_refcursor返回结果集,因此用下面的方法来实现:
CREATE PROCEDURE p_get_all_userid
(p_partid VARCHAR(50)) returning varchar(50),varchar(50); --跟return返回的字段对应
define puserid varchar(50); – 使用define定义变量
define pname varchar(50);
foreach SELECT t1.userid,t1.usercname into puserid,pname FROM t1 left join t2 on t1.userid=t2.userid where t2.roletype in (1,2,3) and t1.partid=p_partid —注意没有分号
return puserid,pname with resume;
end foreach;
END procedure;

函数示例:
CREATE FUNCTION GETDATE() teturning date
define datenow date;
select current into datenow from t1;
RETURN datenow;
END FUNCTION;

CREATE FUNCTION test_sub_level
( parenttext VARCHAR(50),
maxsublevel VARCHAR(50)) returning VARCHAR(100);
define levellen integer;
define rtntext VARCHAR(255);
define tem VARCHAR(200);
let levellen=4; —变量赋值
let tem=maxsublevel||‘null’;
if tem<>‘null’ then
let tem=SUBSTR(maxsublevel,Length(parenttext)+1,levellen);
let tem=to_number(tem)+1;
let tem=trunc(tem);
if Length(tem)=1 then
let tem=concat(‘000’,tem);
end if
if Length(tem)=2 then
let tem=concat(‘00’,tem);
end if
if Length(tem)=3 then
let tem=concat(‘0’,tem);
end if
let rtntext=concat(parenttext,tem);
else
let rtntext=parenttext||‘0001’;
end if
RETURN rtntext;
END function;

你可能感兴趣的:(gbase8s)