【问题标题】:ORA-01858: a non-numeric character was found where a numeric was expected - oracle 10gORA-01858: 在需要数字的地方发现了一个非数字字符 - oracle 10g
【发布时间】:2026-01-25 23:10:01
【问题描述】:

我的问题是: 对于每个会议,如果会议在 2012 年 7 月 1 日之前举行,则显示会议名称和“第一届”字样,如果会议在 2012 年 7 月 1 日或之后举行,则显示“第二届”字样。对于包含“First term”或“Second term”字样的列,请制作标题Term。 与之关联的表是

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

我写的sql语句是:

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');

我收到以下错误:

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

请澄清我哪里出错了,我们将不胜感激。 谢谢你

【问题讨论】:

  • 天哪,你能更好地格式化你的查询吗?

标签: sql oracle10g


【解决方案1】:

您正在将 ConfID(数字)与从内部查询返回的 Sdate(日期)进行比较:

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

您只需要这样一个简单的 SQL:

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'

另外,由于union 的两个部分是互斥的,所以可以使用union all(它的性能更好,因为它不必消除重复)

【讨论】:

    最近更新 更多