Solved

Inconsistent datatypes: expected CHAR got NUMBER

Posted on 2014-09-24
2
258 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 76

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Via a live example, show how to take different types of Oracle backups using RMAN.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now