0

我有以下代码:

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 错误。我调试这些代码几个小时,找不到错误在哪里。有人可以就此提供一些建议吗?

先谢谢了!

4

1 回答 1

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);
. . .

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

于 2014-08-29T02:53:57.220 回答