【问题标题】:Not properly closed sql command未正确关闭 sql 命令
【发布时间】:2017-08-01 11:40:18
【问题描述】:

我有这个代码:

def_where:=def_where||'  TO_CHAR(date_of_input,''MM'') like '''||'to_char(date_of_input,''MM'')=nvl(:DSP_month,to_char(date_of_input,''MM''))'||'%'  ||'to_char(date_of_input,''RRRR'')=nvl(:DSP_year,to_char(date_of_input,''RRRR''))'||'%'''; 

我得到错误 sql 命令没有正确结束。

【问题讨论】:

  • 第一个赞之后你可能需要一个'
  • 最后你还有 2 个 ' 我想

标签: sql oracle plsql


【解决方案1】:

def_where 建议,这是动态构建查询的一部分,where 子句的条件。但是生成的字符串没有意义,应该是这样的:

declare 
    def_where varchar2(32767) := '';
begin
    def_where  :=  def_where 
        || ' to_char(date_of_input, ''MM'') '
        || ' = nvl(:DSP_month, to_char(date_of_input, ''MM'')) and' 
        || ' to_char(date_of_input, ''RRRR'') '
        || ' = nvl(:DSP_year, to_char(date_of_input, ''RRRR''))';

  dbms_output.put_line(def_where);

end;

看看你从dbms_output 得到了什么,如果需要更正这个语法。你也可以重写你的字符串来得到这个:

(extract(month from date_of_input) = :DSP_month or :DSP_month is null) and 
(extract(year  from date_of_input) = :DSP_year  or :DSP_year  is null)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-21
    相关资源
    最近更新 更多