简体   繁体   English

ORA-01722: 无效号码错误

[英]ORA-01722: invalid number error

I am running the below mentioned query in my Oracle client and i am getting我在我的 Oracle 客户端中运行下面提到的查询,我得到

ORA-01722: invalid number ORA-01722: 无效号码

error.错误。 I know the issue is due to the TAG_VALUE column being of type " varchar2 " and i am converting it to number and then using that field in where clause.我知道问题是由于 TAG_VALUE 列的类型为“ varchar2 ”,我将其转换为数字,然后在 where 子句中使用该字段。 I have tried using " CAST " function but that is also not helping.我曾尝试使用“ CAST ”功能,但这也无济于事。 If i run the query neglecting the last where condition with code WHERE (P.TAG_VALUE > '100') then i am getting the result but including the last where clause gives me error.如果我使用代码WHERE (P.TAG_VALUE > '100')运行查询而忽略最后一个 where 条件,那么我会得到结果,但包括最后一个 where 子句会给我错误。

 SELECT DISTINCT
      count(P.CREATED_DATETIME)
    FROM
      ( 
      select OUTPUT_TAG_ID,TO_NUMBER(TAG_VAL,'9999.99') AS 
    TAG_VALUE,TAG_VAL_TS,CREATED_DATETIME
    from OV80STG.PRCSD_DATA_OUTPUT_ARCHIVE
    where MODEL_CODE='MDLADV1538'
    AND TAG_VAL <> 'U_Transfer_rate'
      )   P
    WHERE
    (P.TAG_VALUE > '100')

Any suggestion will be appreciated.任何建议将不胜感激。 Thanks.谢谢。

Remove the single quotes from around the value in the where , you don't need them when its an integer.where的值周围删除单引号,当它是整数时不需要它们。 query will be like this:查询将是这样的:

SELECT DISTINCT
    COUNT(P.CREATED_DATETIME)
FROM
(
    SELECT
        OUTPUT_TAG_ID,
        TO_NUMBER(TAG_VAL, '9999.99') AS TAG_VALUE,
        TAG_VAL_TS,
        CREATED_DATETIME
    FROM OV80STG.PRCSD_DATA_OUTPUT_ARCHIVE
    WHERE MODEL_CODE = 'MDLADV1538'
          AND TAG_VAL <> 'U_Transfer_rate'
) P
WHERE(P.TAG_VALUE > 100);

TO_NUMBER函数返回一个数值,因此,如注释中所述,您不应将其与字符串值进行比较。

我通过在子查询中包含外部where子句解决了这个问题,然后我得到了所需的结果,没有任何错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM