informix 存储过程

时间:2026-02-12 15:54:54

刚刚接触存储过程,将相关知识点做如下总结

1. 新建存储过程

  create procedure testpro(

     col1 varchar(10)

   , col2 decimal(20)

) returning decimal(10);

define v_count varchar(10);

select count(*) into v_count from systables;

return v_count;

end procedure;

上例为一个简单的存储过程。

在informix 中没有出参的写法,11.7版本之后才有了出参 ,调用的方法是需要新建一个存储过程传参。因为我的版本比较低,不能执行就不做具体解释了。

2. 存储过程中的循环

for i in (1 to 10 step 1)

end for;

foreach

end foreach;

个人用到的foreach比较多,写下foreach的用法

foreach

select tabname into v_tabname from systables  --该语句后不能有分号

return v_tabname with resume;

end foreach;

foreach 语境:通常用于查询结果是多条的赋值

3. informix 中的判断

if ** then

  **

elif ** then **

else ***

end if ;

case when ... then ... else ** end

语法同其他数据库一致,不做特殊说明

注:以上仅代表个人观点,我自己总结的,如果有错误,欢迎大家批评指正,有不清楚的也可以找我,共同探讨,共同进步

© 2026 长短途
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com