0

我有一个查询,其中有以下子查询

(select account from asl_data where alias_accunt = trim(field) )

其中 alias_account 是 varchar2(20),而字段值来自另一个子查询的 substr。然而,值为 00123456789

为此,我收到错误为无效号码。我尝试了 to_char,在这两个字段上强制转换函数。但似乎没有任何效果。

我错过了什么?对此有何建议?

谢谢!!

4

1 回答 1

1

在此查询/过程中的某处,尝试将字符串隐式转换为数字。可能在您的子查询中,或者可能是因为变量声明是您的变量之一的数字。您发布的示例似乎没有任何问题。

识别字段后,您可以使用这样的查询查看导致此问题的行。

with t1 as 
(
    select '100' id1, 'first' name1 from dual
    union all
    select '100A' id1, 'second' name1 from dual
    union all
    select '$$1' id1, 'third' name1 from dual
)
select * from t1

100    first
100A   second
$$1    third

如果您尝试将 id 转换为数字,则第一个将起作用(可能您的示例就是这种情况),但其他会引发错误。

with t1 as
(
    select '100' id1, 'first' name1 from dual
    union all
    select '100A' id1, 'second' name1 from dual
    union all
    select '$$1' id1, 'third' name1 from dual
)
select id1,
       name1,
       to_number(id1)
   from t1

/

ERROR:
ORA-01722: invalid number

要识别存在此问题的行,请使用...

with t1 as 
(
    select '100' id1, 'first' name1 from dual
    union all
    select '100A' id1, 'second' name1 from dual
    union all
    select '$$1' id1, 'third' name1 from dual
)
select id1, 
       name1
       --,replace( translate( id1, '0123456789', '0000000000' ), '0', '' ),
       --length(replace( translate( id1, '0123456789', '0000000000' ), '0', '' ))
   from t1
   where length(replace( translate( id1, '0123456789', '0000000000' ), '0', '' )
               ) <> 0

id1     name1
---------------
100A    second
$$1     second
于 2012-10-05T16:23:37.363 回答