【问题标题】:ORA-00933 Error for to_char formatting PLSQLORA-00933 to_char 格式化 PLSQL 错误
【发布时间】:2014-10-23 00:35:59
【问题描述】:

我有以下代码:

IF nvl(p_value, 0) >= 0 THEN
      l_currency_prefix := 'scc.currency_prefix_pos';
      l_currency_suffix := 'scc.currency_suffix_pos';
    ELSE
      l_currency_prefix := 'scc.currency_prefix_neg';
      l_currency_suffix := 'scc.currency_suffix_neg';
    END IF;

l_query := 'SELECT nvl('||l_currency_prefix||', '')'
                       ||'trim(to_char('||p_value||
                                       ',scc.currency_format
                                        ,'||'NLS_NUMERIC_CHARACTERS=' || 'scc.decimal_group_separator'||'))'
                       ||'nvl('||l_currency_suffix||',  '')
              FROM gss.gss_currency_locale scc
             WHERE scc.country_code =' ||p_country_code||
              'AND scc.currency_code ='|| p_currency_code||
              'AND rownum=1';

这是 l_query 的 dbms 输出:

SELECT nvl(scc.currency_prefix_pos, ')trim(to_char(10000,scc.currency_format
                                            ,NLS_NUMERIC_CHARACTERS=scc.decimal_group_separator))nvl(scc.currency_suffix_pos, ')
                  FROM gss.gss_currency_locale scc
                 WHERE scc.country_code =USAND scc.currency_code =USDAND rownum=1

但是,它一直显示 ORA-00933 错误。 我调试这些代码几个小时,找不到错误在哪里。 有人可以就此提供一些建议吗?

提前致谢!

【问题讨论】:

  • 这个错误是在设置字符串的代码中发生的,还是在您尝试执行它时发生的?
  • @GordonLinoff 嗨,戈登,我可以成功编译这个函数块,但是当我用这些输入参数调用/执行它时,它显示错误。谢谢!
  • 。 .替换后用l_query 的值更新问题。
  • @GordonLinoff 添加了一小段代码。谢谢!
  • 。 .不。打印出l_query 的值并显示出来。 (提示:dbms_output.put_line()。)

标签: sql plsql formatting ora-00933 to-char


【解决方案1】:

现在有些问题很明显。你需要这样的东西:

l_query := 'SELECT nvl('||l_currency_prefix||',
                       ||'trim(to_char('||p_value||
                                       ',scc.currency_format || ')' ||
              FROM gss.gss_currency_locale scc
             WHERE scc.country_code = ''' ||p_country_code|| '''' ||
              ' AND scc.currency_code = '''|| p_currency_code|| '''' ||
              ' AND rownum=1';

(我不确定这是否 100% 正确。)

通常,以这种方式创建查询时,我使用replace() 而不是直接替换。比如:

l_query := 'select nvl(@currency_prefix, trim(@p_value, @currency_format))
from . . . ';
l_query := replace(l_query, '@currency_prefix', l_currency_prefix);
l_query := replace(l_query, '@p_value', p_value);
. . .

我发现这种方法可以更轻松地维护代码并查看它在做什么。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-22
    • 2015-08-24
    • 1970-01-01
    • 1970-01-01
    • 2017-05-13
    • 1970-01-01
    • 2017-03-12
    • 1970-01-01
    相关资源
    最近更新 更多