pgsql 變量賦值方法


1、網上一般說的方法如下:

    :=,賦值,比如user_id := 20; 

   select into 賦值,比如 SELECT 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;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM