简体   繁体   中英

ORA-01858: a non-numeric character was found where a numeric was expected - oracle 10g

My question is: For each conference, display conference title and words "First term" if the conference took place before July1, 2012 or the words "Second term" if the conference took place on or after July1,2012. For the column holding the words "First term" or "Second term" make a header Term. The table associated with it is

CONFID             TITLE                    LOCATION          SDATE
------        --------------------       -------------------- ---------
c00001    Hydroinformatics                  Singapore          15-JUN-12
c00002    Ecological_modeling                Berlin            15-JUL-12
c00003    Computational_M                    London            25-MAY-12
c00004    Ecoinformatics                     Boston            22-AUG-12
c00005    Uncertainty_analysis               Athens            10-OCT-12
c00006    Large_databases                    Toronto           13-APR-12
c00007    Systems_analysis                    Boston           23-MAR-12
c00008    Systems_integration                 Tokyo            24-FEB-12
c00009    Aquatic_biology                      Helsinki        12-MAY-12
c00010    Information_systems                   Paris          08-JAN-12
c00011    Simulation_modeling                   Rome           01-SEP-12
c00012    DSS                                  Melbourne       18-DEC-12

The sql statement that I wrote is:

select C.Title, 'First term' as "Term" 
from Conference_C C 
where C.ConfID in (select C.Sdate 
                   from Conference_C C 
                   where C.Sdate < '1-July-12') 
union 
select C.Title, 'Second term' as "Term" 
from Conference_C C 
where C.ConfID in (select C.Sdate 
                     from Conference_C C 
                     where C.Sdate >= '1-July-12');

I get the following error:

select C.Title, 'First term' as "Term" from Conference_C C where C.ConfID
                                                                 *
ERROR at line 1:
ORA-01858: a non-numeric character was found where a numeric was expected

Please clarify where I am going wrong, any help would be appreciated. Thank You

You are comparing the ConfID (a number) to a Sdate (a date) that is returned from your inner query:

where C.ConfID in (select C.Sdate 
                   from Conference_C C 
                   where C.Sdate < '1-July-12') 

All you need is a simple SQL like this:

select C.Title, 'First term' as "Term" 
from Conference_C C 
where C.Sdate < '1-July-12'
union
select C.Title, 'Second term' as "Term" 
from Conference_C C 
where C.Sdate >= '1-July-12'

Also since the two parts of the union are mutually exclusive, a union all can be used (which performs better because it does not have to eliminate duplicates)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM