where子句特定中间左值oracle

时间:2014-02-07 05:22:27

标签: sql oracle character where-clause

我有这个问题:

select s.ST_SAMPLE_ID, s.st_cn_no as CNNumber,
s.st_smptyp as SampleType,
s.st_wasgrp as WasteCode,
s.st_wascod as WasteCategory,
s.st_received_dt as ReceivedDate,
s.st_wastyp_name as WasteType,
s.st_status as SampleStatus,
s.st_dispose_ind as DisposalStatus,
s.st_container as SampleContainer,
s.st_smppnt as SamplePoint,
s.st_nature as SampleNature,
c.scm_name as Color,cm_client_name 
from sample_txn s,sample_color_mstr c,client_mstr cm  
where s.st_color=scm_auto_no (+) and st_client_id=cm_client_id 
and st_year='13' and s.st_lab_id='R'

结果是:

result of the query

如何按月过滤结果。我的意思是从列RECEIVEDDATE过滤3个字符,例如JAN,FEB,

我尝试将其添加到where子句

LPAD(s.st_received_dt,3,'JAN')

但没有工作,错误如下:

  

SQL错误:ORA-00920:无效的关系运算符   00920. 00000 - “无效的关系运营商”   *原因:
  *操作:

谢谢

2 个答案:

答案 0 :(得分:1)

我不明白你为什么会使用lpad()。试试这个:

to_char(s.st_received_dt, 'MON') = 'JAN'

或者:

extract(month from s.st_received_dt) = 1

答案 1 :(得分:0)

您可以使用TO_CHAR函数过滤月份,如下所示:

select s.ST_SAMPLE_ID, s.st_cn_no as CNNumber,
s.st_smptyp as SampleType,
s.st_wasgrp as WasteCode,
s.st_wascod as WasteCategory,
s.st_received_dt as ReceivedDate,
s.st_wastyp_name as WasteType,
s.st_status as SampleStatus,
s.st_dispose_ind as DisposalStatus,
s.st_container as SampleContainer,
s.st_smppnt as SamplePoint,
s.st_nature as SampleNature,
c.scm_name as Color,cm_client_name 
from sample_txn s,sample_color_mstr c,client_mstr cm  
where s.st_color=scm_auto_no (+) and st_client_id=cm_client_id 
and st_year='13' and s.st_lab_id='R'
and to_char(s.st_received_dt,'MON') = 'JAN';