Forum Stats

  • 3,851,919 Users
  • 2,264,053 Discussions
  • 7,904,904 Comments

Discussions

ORA-00932 on second execution

I have a bizarre behavior when I execute this query:

  SELECT TITLE,
         "1",
         "2",
         "3",
         "4",
         "5",
         NB,
         ROUND(POUR * 100, 2) || '%' POUR
    FROM (SELECT *
            FROM (SELECT 'NUM_Q1' TITLE,
                         NUM_Q1 VAL
                    FROM TABLE_REP
                  UNION ALL
                  SELECT 'NUM_Q2' TITLE,
                         NUM_Q2 VAL
                    FROM TABLE_REP) PIVOT (COUNT (VAL)
                                          FOR (VAL)
                                          IN  (1 AS "1", 2 AS "2", 3 AS "3", 4 AS "4", 5 AS "5")))
         INNER JOIN (SELECT 'NUM_Q1' TITLE,
                            COUNT(NUM_Q1) NB,
                            COUNT(NUM_Q1) / COUNT (*) POUR,
                            1 ORD
                       FROM TABLE_REP
                     UNION ALL
                     SELECT 'NUM_Q2' TITLE,
                            COUNT(NUM_Q2) NB,
                            COUNT(NUM_Q2) / COUNT (*) POUR,
                            2 ORD
                       FROM TABLE_REP)
            USING (TITLE)
ORDER BY ORD

I receive this error:

ORA-00932: inconsistent datatypes; expected : - ; obtained : NUMBER

But only the second time I run the query, the first time, there is no error and the result is what I want. I have other queries with the same structure that never produces that error. All the columns are NUMBER(1) and are nullable. 

The fact that it’s only on subsequent run make me believe this a problem with the query parser.

Tagged:
This discussion has been closed.