1.普通打字符串值用当引号
例:
V_DYN_SQL := 'SELECT EMP,DEPTNO,''xiaoli'' chenhu from emp';
2.带字符串值的动态引号
例:
v_chenhu = 'xiaoli'; V_DYN_SQL := 'SELECT EMP,DEPTNO, '''|| v_chenhu || ''' from emp;';
3.动态sql中含有表名的变量
v_tablename = 'emp' V_DYN_SQL := 'select emp,deptno, ''xiaoli' chenhu from '|| v_tablename;
4.动态sql中字符串中有单引号
比如想输出如下内容:
emp | deptno | chenhu | pingjia |
jack | 10 | xiaoli | '工作小能手' |
v_pingjia := '工作小能手’; V_DYN_SQL := 'SLEECT EMP,DEPTNO,'xiaoli' chenhu,''''' || v_pingjia|| ''''' from emp ';
中文版官方文档:
http://www.postgres.cn/docs/12/plpgsql-development-tips.html#PLPGSQL-QUOTE-TIPS