pgsql 变量赋值方法及需要注意的事项
1、网上一般说的方法如下:
:=,赋值,比如user_id := 20;
select into 赋值,比如
1SELECT INTO myrec * FROM emp WHERE empname = myname
2、我今天介绍的是一个更通用更实用的赋值方法
select ...into ...
使用示例:
一个变量,select 30 into user_id;
多个变量,select 20,30,50 into a,b.c;
3、在存储函数中(即存储过程中)还有Into也很常用。
比如,拼接字符中时,直接into即可。
select 'update student set remark ='''|| now() ||''' where student.id = '|| $1 into sql_str_run ; execute sql_str_run;
补充:postgresql 赋值注意
在函数里面赋值需要注意以下
定义变量是在begin前
变量赋值时使用 :=
select 中赋值使用into
如下:
create or replace... return i int declare value int; begin value:=100; select id into value from table_name (编辑:ASP站长) 【免责声明】本站内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。 |
-
无相关信息