oracle数据库拼接sql语句字符串问题

近日遇到一个问题,在使用存储过程拼接动态语句时,传输参数一直提示无效标识符,研究发现拼接sql语句的时候,作为字符串参数的变量要加' ',具体代码如下:

declare
    vc_sql varchar2(20000); 

    v_table varchar2(200) ;  
    v_status number;
    v_opinion varchar2(500);
    v_proId number;
    v_deptId number;

begin     

    v_table := '';
    v_status := '';
    v_opinion := '';
    v_proId := '';
    v_deptId := '';
    if  v_dept_id   is null then
        vc_sql := 'update '||v_table || ' set status='||v_status  ||',opinion='''||nvl(v_opinion,'') || '''where proj_id=' || v_proId ;
    else
        vc_sql := 'update '||v_table || ' set status='||v_status  ||',opinion='''||nvl(v_opinion,'') || '''where proj_id=' || v_proId || ' and dept_id=' || v_deptId ;
    end if;
    execute immediate vc_sql;
end;

表现就是''单引号的转义,相当于''代表一个'

猜你喜欢

转载自blog.csdn.net/wslsh614801/article/details/75009720