ORA-00932 错误。不知道如何修复

发布于 2024-09-30 12:04:14 字数 11680 浏览 5 评论 0原文

我正在尝试运行此 Oracle 查询...

  SELECT COUNT(*) as total, 
         q1 
    FROM exit_responses 
   WHERE sdate BETWEEN '03-Aug-10 12:00:00 AM' AND '03-Nov-10 12:00:00 AM' 
GROUP BY q1;

...但我不断收到此错误...

Error starting at line 3 in command:
SELECT COUNT(*) as total, q1 FROM exit_responses WHERE sdate BETWEEN '03-Aug-10 12:00:00 AM' AND '03-Nov-10 12:00:00 AM' GROUP BY q1 
Error at Command Line:3 Column:130
Error report:
SQL Error: ORA-00932: inconsistent datatypes: expected - got CLOB
00932. 00000 -  "inconsistent datatypes: expected %s got %s"
*Cause:    
*Action:

有人有任何想法吗?说这是不一致的数据类型......但我想我没有完全理解。

谢谢

顺便说一句,这是我的 exit_responses 表的 DESC:

DESC exit_responses
Name                           Null     Type                                                                                                                                                                                          
------------------------------ -------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
SDATE                                   DATE                                                                                                                                                                                          
F_NAME                                  VARCHAR2(255 CHAR)                                                                                                                                                                            
L_NAME                                  VARCHAR2(255 CHAR)                                                                                                                                                                            
TITLE                                   VARCHAR2(255 CHAR)                                                                                                                                                                            
DEPARTMENT                              VARCHAR2(255 CHAR)                                                                                                                                                                            
EMP_TYPE                                VARCHAR2(11 CHAR)                                                                                                                                                                             
LENGTH_OF_SERVICE                       VARCHAR2(255 CHAR)                                                                                                                                                                            
Q1                                      CLOB()                                                                                                                                                                                        
Q2                                      CLOB()                                                                                                                                                                                        
Q2_OTHER                                CLOB()                                                                                                                                                                                        
Q3_PAY                                  NUMBER                                                                                                                                                                                        
Q3_HOLIDAYS                             NUMBER                                                                                                                                                                                        
Q3_VACATION                             NUMBER                                                                                                                                                                                        
Q3_SICK                                 NUMBER                                                                                                                                                                                        
Q3_INSURANCE                            NUMBER                                                                                                                                                                                        
Q3_RETIREMENT                           NUMBER                                                                                                                                                                                        
Q3_FSA                                  NUMBER                                                                                                                                                                                        
Q4_AVAILABILITY                         NUMBER                                                                                                                                                                                        
Q4_QUALITY                              NUMBER                                                                                                                                                                                        
Q4_SATISFACTION                         NUMBER                                                                                                                                                                                        
Q4_COMMENTS                             NUMBER                                                                                                                                                                                        
Q5_ORIENTATION                          NUMBER                                                                                                                                                                                        
Q5_POLICIES                             NUMBER                                                                                                                                                                                        
Q5_PROMOTIONAL                          NUMBER                                                                                                                                                                                        
Q6_JOBDUTIES                            NUMBER                                                                                                                                                                                        
Q6_RELATIONSHIPS                        NUMBER                                                                                                                                                                                        
Q6_COOPERATION                          NUMBER                                                                                                                                                                                        
Q6_EQUIPMENT                            NUMBER                                                                                                                                                                                        
Q6_CONDITIONS                           NUMBER                                                                                                                                                                                        
Q6_SAFETY                               NUMBER                                                                                                                                                                                        
Q7                                      NUMBER                                                                                                                                                                                        
Q8_KNOWLEDGE                            NUMBER                                                                                                                                                                                        
Q8_DELEGATION                           NUMBER                                                                                                                                                                                        
Q8_OBSERVANCE                           NUMBER                                                                                                                                                                                        
Q8_FEEDBACK                             NUMBER                                                                                                                                                                                        
Q8_CONTRIBUTIONS                        NUMBER                                                                                                                                                                                        
Q8_LISTENED                             NUMBER                                                                                                                                                                                        
Q8_COMPLAINTS                           NUMBER                                                                                                                                                                                        
Q9                                      VARCHAR2(3 CHAR)                                                                                                                                                                              
Q9_DESCRIBE                             CLOB()                                                                                                                                                                                        
Q10                                     CLOB()                                                                                                                                                                                        
Q11                                     NUMBER                                                                                                                                                                                        
Q11_COMMENTS                            CLOB()                                                                                                                                                                                        
Q12                                     NUMBER                                                                                                                                                                                        
Q12_DESCRIBE                            CLOB()                                                                                                                                                                                        
ADDITIONAL_COMMENTS                     CLOB() 

I'm attempting to run this Oracle query...

  SELECT COUNT(*) as total, 
         q1 
    FROM exit_responses 
   WHERE sdate BETWEEN '03-Aug-10 12:00:00 AM' AND '03-Nov-10 12:00:00 AM' 
GROUP BY q1;

...but I keep getting this error...

Error starting at line 3 in command:
SELECT COUNT(*) as total, q1 FROM exit_responses WHERE sdate BETWEEN '03-Aug-10 12:00:00 AM' AND '03-Nov-10 12:00:00 AM' GROUP BY q1 
Error at Command Line:3 Column:130
Error report:
SQL Error: ORA-00932: inconsistent datatypes: expected - got CLOB
00932. 00000 -  "inconsistent datatypes: expected %s got %s"
*Cause:    
*Action:

Anyone have any ideas? Says it's an inconsistent data type... but I guess I'm not understanding completely.

Thanks

Btw, here's the DESC of my exit_responses table:

DESC exit_responses
Name                           Null     Type                                                                                                                                                                                          
------------------------------ -------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
SDATE                                   DATE                                                                                                                                                                                          
F_NAME                                  VARCHAR2(255 CHAR)                                                                                                                                                                            
L_NAME                                  VARCHAR2(255 CHAR)                                                                                                                                                                            
TITLE                                   VARCHAR2(255 CHAR)                                                                                                                                                                            
DEPARTMENT                              VARCHAR2(255 CHAR)                                                                                                                                                                            
EMP_TYPE                                VARCHAR2(11 CHAR)                                                                                                                                                                             
LENGTH_OF_SERVICE                       VARCHAR2(255 CHAR)                                                                                                                                                                            
Q1                                      CLOB()                                                                                                                                                                                        
Q2                                      CLOB()                                                                                                                                                                                        
Q2_OTHER                                CLOB()                                                                                                                                                                                        
Q3_PAY                                  NUMBER                                                                                                                                                                                        
Q3_HOLIDAYS                             NUMBER                                                                                                                                                                                        
Q3_VACATION                             NUMBER                                                                                                                                                                                        
Q3_SICK                                 NUMBER                                                                                                                                                                                        
Q3_INSURANCE                            NUMBER                                                                                                                                                                                        
Q3_RETIREMENT                           NUMBER                                                                                                                                                                                        
Q3_FSA                                  NUMBER                                                                                                                                                                                        
Q4_AVAILABILITY                         NUMBER                                                                                                                                                                                        
Q4_QUALITY                              NUMBER                                                                                                                                                                                        
Q4_SATISFACTION                         NUMBER                                                                                                                                                                                        
Q4_COMMENTS                             NUMBER                                                                                                                                                                                        
Q5_ORIENTATION                          NUMBER                                                                                                                                                                                        
Q5_POLICIES                             NUMBER                                                                                                                                                                                        
Q5_PROMOTIONAL                          NUMBER                                                                                                                                                                                        
Q6_JOBDUTIES                            NUMBER                                                                                                                                                                                        
Q6_RELATIONSHIPS                        NUMBER                                                                                                                                                                                        
Q6_COOPERATION                          NUMBER                                                                                                                                                                                        
Q6_EQUIPMENT                            NUMBER                                                                                                                                                                                        
Q6_CONDITIONS                           NUMBER                                                                                                                                                                                        
Q6_SAFETY                               NUMBER                                                                                                                                                                                        
Q7                                      NUMBER                                                                                                                                                                                        
Q8_KNOWLEDGE                            NUMBER                                                                                                                                                                                        
Q8_DELEGATION                           NUMBER                                                                                                                                                                                        
Q8_OBSERVANCE                           NUMBER                                                                                                                                                                                        
Q8_FEEDBACK                             NUMBER                                                                                                                                                                                        
Q8_CONTRIBUTIONS                        NUMBER                                                                                                                                                                                        
Q8_LISTENED                             NUMBER                                                                                                                                                                                        
Q8_COMPLAINTS                           NUMBER                                                                                                                                                                                        
Q9                                      VARCHAR2(3 CHAR)                                                                                                                                                                              
Q9_DESCRIBE                             CLOB()                                                                                                                                                                                        
Q10                                     CLOB()                                                                                                                                                                                        
Q11                                     NUMBER                                                                                                                                                                                        
Q11_COMMENTS                            CLOB()                                                                                                                                                                                        
Q12                                     NUMBER                                                                                                                                                                                        
Q12_DESCRIBE                            CLOB()                                                                                                                                                                                        
ADDITIONAL_COMMENTS                     CLOB() 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

沧笙踏歌 2024-10-07 12:04:14

假设sdate的日期类型是Oracle DATE,则使用TO_DATE函数 将字符串转换为 Oracle 中的 DATE:

  SELECT COUNT(*) as total, 
         q1 
    FROM exit_responses 
   WHERE sdate BETWEEN TO_DATE('03-Aug-10 12:00:00 AM', 'DD-MON-YY HH12:MI:SS AM') 
                   AND TO_DATE('03-Nov-10 12:00:00 AM', 'DD-MON-YY HH12:MI:SS AM') 
GROUP BY q1;

Assuming sdate's date type is Oracle DATE, use the TO_DATE function to convert a string to a DATE in Oracle:

  SELECT COUNT(*) as total, 
         q1 
    FROM exit_responses 
   WHERE sdate BETWEEN TO_DATE('03-Aug-10 12:00:00 AM', 'DD-MON-YY HH12:MI:SS AM') 
                   AND TO_DATE('03-Nov-10 12:00:00 AM', 'DD-MON-YY HH12:MI:SS AM') 
GROUP BY q1;
哎呦我呸! 2024-10-07 12:04:14

SDATE 列的数据类型是什么?假设它是一个 DATE,您几乎肯定希望使用显式 TO_DATE 调用将字符串转换为日期,即,

WHERE sdate BETWEEN to_date('03-Aug-2010', 'DD-MON-YYYY') 
                AND to_date( '03-Nov-2010', 'DD-MON-YYYY' )

由于午夜是未指定的默认时间,因此您不一定需要 12:00:00 AM 位。如果您想包含

WHERE sdate BETWEEN to_date('03-Aug-2010 12:00:00 AM', 'DD-MON-YYYY HH:MI:SS AM') 
                AND to_date( '03-Nov-2010 12:00:00 AM', 'DD-MON-YYYY HH:MI:SS AM' )

If SDATE is a DATE 并且您希望 BETWEEN 采用两个不同的 Unix 纪元(自 1970 年 1 月 1 日起的毫秒数)而不是字符串,您可能需要类似的内容,

WHERE sdate BETWEEN date '1970-01-01' + :1/86400000  
                AND date '1970-01-01' + :2/86400000 

其中 :1 和 :2 是两个绑定变量。如果你的纪元是自 1970 年 1 月 1 日以来的秒数

WHERE sdate BETWEEN date '1970-01-01' + :1/86400  
                AND date '1970-01-01' + :2/86400 

What is the data type of the SDATE column? Assuming it is a DATE, you almost certainly want to use explicit TO_DATE calls to convert your strings to dates, i.e.

WHERE sdate BETWEEN to_date('03-Aug-2010', 'DD-MON-YYYY') 
                AND to_date( '03-Nov-2010', 'DD-MON-YYYY' )

Since midnight is the default time when none is specified, you don't necessarily need the 12:00:00 AM bit. If you want to include that

WHERE sdate BETWEEN to_date('03-Aug-2010 12:00:00 AM', 'DD-MON-YYYY HH:MI:SS AM') 
                AND to_date( '03-Nov-2010 12:00:00 AM', 'DD-MON-YYYY HH:MI:SS AM' )

If SDATE is a DATE and you want the BETWEEN to take two different Unix epochs (milliseconds since Jan 1, 1970) rather than strings, you would want something like

WHERE sdate BETWEEN date '1970-01-01' + :1/86400000  
                AND date '1970-01-01' + :2/86400000 

where :1 and :2 are the two bind variables. If your epochs are seconds since Jan 1, 1970

WHERE sdate BETWEEN date '1970-01-01' + :1/86400  
                AND date '1970-01-01' + :2/86400 
傲娇萝莉攻 2024-10-07 12:04:14

我的猜测是 sdate 是 DATE 或 DATETIME 列,在这种情况下您需要转换日期字符串:

  SELECT COUNT(*) as total,  
         q1  
    FROM exit_responses  
   WHERE sdate BETWEEN to_date('03-Aug-10 12:00:00 AM') AND to_date('03-Nov-10 12:00:00 AM')  
GROUP BY q1; 

my guess is that sdate is a DATE or DATETIME column, in which case you need to convert your date strings:

  SELECT COUNT(*) as total,  
         q1  
    FROM exit_responses  
   WHERE sdate BETWEEN to_date('03-Aug-10 12:00:00 AM') AND to_date('03-Nov-10 12:00:00 AM')  
GROUP BY q1; 
吃素的狼 2024-10-07 12:04:14

由于对 ORACLE 一无所知,我敢打赌您实际上无法对 CLOB 字段进行 GROUP BY 。这很有道理......

另外,看看 这个。摘抄:

从 Oracle 的角度来看,这很重要,因为您无法对 Clob 进行分组。为了进行分组依据,您需要能够排序,而 clob 字段没有自然的排序顺序。解决方法是在 clob 字段上执行 to_char 函数,但最多可以获得 4000 个字符。对我来说,这符合要求,因为我需要的子字符串是一个小字符串。但问题是我需要对 clob 字段内的 XML 标记的一部分进行排序,并根据该结果对它们进行分组。不仅如此,我还需要在 XML 消息中查找特定类型的错误并对其进行计数。

Not knowing anything about ORACLE, I would bet that you in fact can't GROUP BY on CLOB fields. It makes perfect sense...

Also, look at this. Excerpt:

This was significant from Oracle perspective because you cannot do a group by on a clob. In order to do a group by, you need to be able to sort and clob fields do not have a natural sort order. The workaround is to do a to_char function on the clob field but you can get a max of 4000 chars. For me, this suited the requirement because the substring I needed was a small string. But the issue is that I needed to sort a portion of an XML tag inside the clob field and group them based on that. Not only that I needed to find a specific type of error in the XML message and count them.

月朦胧 2024-10-07 12:04:14

我认为,最好使用 to_date 函数。

where sdate between
  TO_DATE('03.08.2010:00:00:0','DD.MM.YYYY:HH24:MI:SS') and TO_DATE('03.10.2010:00:00:0','DD.MM.YYYY:HH24:MI:SS') 

i think, it's better to use to_date function for that.

where sdate between
  TO_DATE('03.08.2010:00:00:0','DD.MM.YYYY:HH24:MI:SS') and TO_DATE('03.10.2010:00:00:0','DD.MM.YYYY:HH24:MI:SS') 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文