Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Inconsistent datatypes: expected CHAR got NUMBER

Posted on 2014-09-24
2
287 Views
Last Modified: 2014-09-24
Why am I getting the following error when I run this query? "inconsistent datatypes: expected CHAR got NUMBER"
It seems to be triggered by the YEAR_OF_STUDY case statement.

SELECT rep_start_year,
         university_code,
         YEAR_OF_STUDY,
         COUNT(*) AS YEAR_OF_STUDY_count

    FROM (SELECT rep_start_year,
                 CASE
                     WHEN YEAR_OF_STUDY in (5,6,7,8,9)  THEN 'Other'
                     ELSE
                         YEAR_OF_STUDY
                 END
                     YEAR_OF_STUDY,

                 (CASE
                      WHEN uni.university_code = 'DOMC' THEN 'CARL'
                      WHEN uni.university_code = 'NOSM-LAKE' THEN 'NOSM'
                      WHEN uni.university_code = 'NOSM-LAUR' THEN 'NOSM'
                      WHEN uni.university_code = 'LAUR-ALGM' THEN 'ALGM'
                      WHEN uni.university_code = 'LAUR-HRST' THEN 'HRST'
                      WHEN uni.university_code = 'DOMC' THEN 'CARL'
                      ELSE uni.university_code
                  END)
                     AS university_code
            FROM edcs_unistat.ustat_enrolment_data enrol
            
                     
                 INNER JOIN edcs_unistat.uni_institution_type uniinst
                     ON enrol.uni_institution_type_id = uniinst.uni_institution_type_id
                     
                 INNER JOIN edcs_core.university uni ON uniinst.university_id = uni.university_id
                 
                 INNER JOIN edcs_unistat.reg_status_type regstatus
                     ON enrol.reg_status_type_id = regstatus.reg_status_type_id
                     
                 INNER JOIN edcs_unistat.fee_cat_type feetyp
                     ON enrol.fee_cat_type_id = feetyp.fee_cat_type_id
                     
           WHERE enrol.rep_start_year IN ('2012', '2013')
           AND enrol.period IN ('FAL')
           AND regstatus.reg_status_type_code IN ('12','13','14','15','16','18')
           AND feetyp.fee_cat_type_code IN ('3', '4')
           )
             
GROUP BY rep_start_year, university_code, YEAR_OF_STUDY
ORDER BY rep_start_year, university_code, YEAR_OF_STUDY

Open in new window

0
Comment
Question by:mariita
2 Comments
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 250 total points
ID: 40342005
The return values for a CASE statement have to be of the same data type.

If year_of_study is a number then:
...
CASE
                     WHEN YEAR_OF_STUDY in (5,6,7,8,9)  THEN 'Other'
                     ELSE
                         to_char(YEAR_OF_STUDY)
                 END
                     YEAR_OF_STUDY,
...

Same for the other CASE statement.
0
 
LVL 24

Assisted Solution

by:Phillip Burton
Phillip Burton earned 250 total points
ID: 40342009
It's lines 8 and 10.

If the YEAR_OF_STUDY, which appears to be a number, is 5, 6, 7, 8 or 9, you return a string. If it isn't, you return a number. That's the mismatch.

Maybe line 10 should be

CAST(YEAR_OF_STUDY as varchar(4))

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Email Header Detail 12 63
SYS password changed. Now can't log in as SYS 27 28
Checking for column width 8 29
oracle forms question 22 42
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question