Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql ORA-01722:无效的数字where子句_Sql_Oracle - Fatal编程技术网

Sql ORA-01722:无效的数字where子句

Sql ORA-01722:无效的数字where子句,sql,oracle,Sql,Oracle,当我想比较这两列时,它向我显示了这个menssage,没有“where子句”,没有任何错误,但是当我写“where”时,错误就出现了 这是我的sql语句: select MONEY , to_char(MONEY, 'FM999G999G999G999D99', 'NLS_NUMERIC_CHARACTERS='',.''') from ACOUNT where MONEY is not null 错误:ORA-01722:无效号码 172200000-“无效号码” *原因:

当我想比较这两列时,它向我显示了这个menssage,没有“where子句”,没有任何错误,但是当我写“where”时,错误就出现了

这是我的sql语句:

select MONEY
       , to_char(MONEY, 'FM999G999G999G999D99', 'NLS_NUMERIC_CHARACTERS='',.''')  
from ACOUNT
where MONEY is not null
错误:ORA-01722:无效号码 172200000-“无效号码” *原因:指定的数字无效。 *操作:指定一个有效的数字


表中的
a count
列中的
MONEY
数据不是数字

下面是一个演示:

我假设它在没有where子句的情况下工作的原因是因为您的工具只显示前50个结果。。。当您添加where子句并过滤数据时,在前50个结果中有一个不是数字的数据

您可以在工具中更改此设置,方法是:工具>>首选项>>数据库>>高级

您可以创建此函数:

CREATE OR REPLACE FUNCTION is_number (p_str IN VARCHAR2)
  RETURN NUMBER
IS
  l_num NUMBER;
BEGIN
  l_num := to_number(p_str);
  RETURN l_num;

EXCEPTION
  WHEN others THEN
    RETURN NULL;
END is_number;
/
我在这里建立的:

然后,您可以使用以下代码:

select *
from (select MONEY_c
             , to_char(is_number(MONEY_c), 'FM999G999G999G999D99', 'NLS_NUMERIC_CHARACTERS='',.''')  as money_2
      from ACOUNT)
where money_2 is not null

它可能不仅是非数字字符,而且只是一个逗号分隔的“数字”字符串值

此示例会导致相同的错误

select to_char('2,5', 'FM999G999G999G999D99', 'NLS_NUMERIC_CHARACTERS='',.''') from dual;
因此,下面是在ACOUNT表中查找问题记录的查询

select * from ACOUNT where not regexp_like(replace(MONEY, '.', ''),'^[0-9]+$');
-- replace() is here to make regexp_like to ignore values like '2.5' which can be converted to a number

请告诉我们该列的数据类型。另外,您是否有任何虚拟列?请附加表结构。没有虚拟列,类型为VARCHAR2(1字节)。请告诉我们您使用什么工具?SQL Developer可能吗?是的,SQL Developer 20.2和Database 11gI不认为该变量做了任何有用的事情,尽管使用它代码可能更容易理解。我也会考虑声明它>代码> RealPiabele>代码>,包括。