[英]Oracle SQL Invalid Number Error with Strings
I have a query like this... 我有这样的查询...
SELECT 1,2,3
FROM (SELECT CASE WHEN something THEN TO_CHAR(1)... END,2,3
FROM tables WHERE condtions)
WHERE 1 NOT LIKE 'String'
All columns are varchar2, I get a Invalid Number error with this query, pointing to the inner case statement. 所有列都是varchar2,在此查询中,我指向内部case语句时收到“ Invalid Number”错误。 The inner query runs fine seperately.. the entire query runs fine if I remove the outer WHERE condtion.
内部查询单独运行良好..如果删除外部WHERE条件,则整个查询运行良好。
I understand this has to do something with the SQL Optimizer, but what am I doing wrong here and how can I get around this? 我知道这与SQL Optimizer有所关系,但是我在这里做错了什么,如何解决呢? Using To_CHAR for the String or outer select statement aren't working...
对字符串或外部select语句使用To_CHAR不起作用...
Updating for Better understanding, 更新以更好地理解,
SELECT COL1, COL2, COL3 FROM (
SELECT CASE WHEN LOGIC THEN TO_CHAR(1) ELSE TO_CHAR(0) END AS COL1,
COUNT(SOME_COL) AS COL2 , COUNT(SOME_COL2) AS COL3 FROM TABLES WHERE CONDTIONS
) WHERE COL1 NOT LIKE ‘0’
I was told the Oracle SQL Optimizer is interfering and causing the above stated error and that the query has to be written in a different way. 有人告诉我Oracle SQL Optimizer正在干扰并导致上述错误,并且查询必须以其他方式编写。
Indicate that 1 is a column name by surrounding it with back ticks. 通过用反斜线括起来,表明1是列名。
SELECT 1,2,3 FROM (SELECT CASE WHEN something THEN TO_CHAR(1)... END,2,3
FROM tables
WHERE condtions) WHERE `1` NOT LIKE 'String'
You need to use proper column names (that start with a letter) - 1,2,3 won't work (unless quoted): 您需要使用适当的列名(以字母开头)-1,2,3将不起作用(除非加引号):
create table tab1 as
select 1 as pk from dual
union all
select 2 as pk from dual
union all
select 3 as pk from dual;
SELECT col1,col2,col3
FROM (SELECT (CASE WHEN 1=2 THEN TO_CHAR(1) else to_char(2) END) as col1 ,
2 as col2,
3 as col3
FROM tab1 WHERE pk > 1)
WHERE col1 NOT LIKE '%1%'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.