0

我正在尝试向我们的数据库的查询添加一些格式化的列,但我认为我在 CASE 语句中弄错了运算符。

我也不清楚如何为 TO_CHAR 操作编写格式。它与 TO_DATE 操作相同吗?(在 oracle 文档中找不到)

我也不确定我是否应该使用 TO_DATE 或其他调用来创建一个对象,该对象存储为来自四个数字的字符串的时间。

最重要的是,我的代码产生了错误,所以我什么也没看到。

我收到此错误:

ORA-00920: invalid relational operator
00920. 00000 -  "invalid relational operator"
*Cause:    
*Action:
Error at Line: 53 Column: 30

从这段代码

/* Code written for exercize 3 in the Banner Tutorials by Alex Ackroyd on 18april2013*/
/* Objective: use functions to transform and shape data in the result set*/
/* Tables: SSRMEET ( add to SPRIDEN, SFRSTCR, SSBSECT ) */
/* Select: in addition to the columns from exercize 2, add the following values: 
    - SSRMEET_ROOM_CODE, 
    - a computed column for the start time, 
    - a computed column for the end time, and
    - a computed column that shows the days the class meets*/
/* Hint: The computed columns are created by passing table columns through functions. 
          You can use any non-analytical database function documented by Oracle to transform data from one thing to another.
          You can also write your own functions! Whoa there Shadowfax, coming soon to the tutorial near you!*/


/* Note:ssrmeet_begin_time and ssrmeet_end_time are are in a 4 character string 24hr format
        so I'm trying to read that in, convert it to a datetime type variable, 
        then convert it to the final standard format am/pm (ex: 5:00 A.M. , 3:30 P.M., etc.*/
/* Start code from this exercize, 3*/

select 
  ssrmeet.ssrmeet_room_code, 
  TO_CHAR(
          TO_DATE( ssrmeet.ssrmeet_begin_time, 'HH24MI' )
          /*, char format*/
          ), 
  TO_CHAR(
          TO_DATE( ssrmeet.ssrmeet_end_time, 'HH24MI' ) 
          /*, char format*/
          ),

  CASE
    when
/* line 53*/   ssrmeet.ssrmeet_sun_day,
             | ssrmeet.ssrmeet_mon_day, 
             | ssrmeet.ssrmeet_tue_day,
             | ssrmeet.ssrmeet_wed_day,
             | ssrmeet.ssrmeet_thu_day,
             | ssrmeet.ssrmeet_fri_day,
             | ssrmeet.ssrmeet_sat_day
      IS NOT NULL   
    END

from ssrmeet

/* End code from this exercize, 3*/

提前感谢您的帮助。

4

2 回答 2

0

我认为 SELECT 子句中的 CASE 构造也应该有一个 THEN 块。如果一个或所有工作日不为空,就像你想要做的那样。请参考以下示例 -

select
CASE
  WHEN a < b THEN 'hello'
  WHEN d < e THEN 'goodbye'
END
from my_table;

所以在你的情况下,它应该是这样的 -

select 
ssrmeet.ssrmeet_room_code, 
TO_CHAR(
    TO_DATE( ssrmeet.ssrmeet_begin_time, 'HH24MI' )
      /*, char format*/
      ), 
TO_CHAR(
      TO_DATE( ssrmeet.ssrmeet_end_time, 'HH24MI' ) 
      /*, char format*/
      ),

CASE
when
/* line 53*/   ssrmeet.ssrmeet_sun_day IS NOT NULL   
       OR  ssrmeet.ssrmeet_mon_day IS NOT NULL   
       OR  ssrmeet.ssrmeet_tue_day IS NOT NULL   
       OR  ssrmeet.ssrmeet_wed_day IS NOT NULL   
       OR  ssrmeet.ssrmeet_thu_day IS NOT NULL   
       OR  ssrmeet.ssrmeet_fri_day IS NOT NULL   
       OR  ssrmeet.ssrmeet_sat_day IS NOT NULL   
then 
/*Here comes the value that you want to show if one or all of the weekdays is not null*/
'WEEKDAY NOT NULL'
END
from ssrmeet;

请让我知道这是否适合您。

谢谢,阿迪亚

于 2013-04-19T03:46:33.110 回答
0

谢谢您的帮助!你是对的,这将是使用 case 语句的正确方法,但它最终并没有给我我正在寻找的结果。

/* Code written for exercize 3 in the Banner Tutorials by Alex Ackroyd on 18april2013*/
/* Edited last: 22april2013*/
/* Objective: use functions to transform and shape data in the result set*/
/* Tables: SSRMEET ( add to SPRIDEN, SFRSTCR, SSBSECT) */
/* Select: in addition to the columns from exercize 2, add the following values: 
    - SSRMEET_ROOM_CODE, 
    - a computed column for the start time, 
    - a computed column for the end time, and
    - a computed column that shows the days the class meets*/
/* Hint: The computed columns are created by passing table columns through functions. 
          You can use any non-analytical database function documented by Oracle to transform data from one thing to another.
          You can also write your own functions! Whoa there Shadowfax, coming soon to the tutorial near you!*/

/* Start code from exercizes 1, 2, unt 3 that queries my student record*/

select 
  spriden.spriden_id, spriden.spriden_pidm,
  sfrstcr.sfrstcr_term_code, sfrstcr.sfrstcr_crn,
  ssbsect.ssbsect_subj_code, ssbsect.ssbsect_crse_numb, ssbsect.ssbsect_seq_numb,
    ssbsect.ssbsect_crn,
  ssrmeet.ssrmeet_term_code, ssrmeet.ssrmeet_crn, ssrmeet.ssrmeet_room_code, 

  TO_CHAR( TO_DATE( ssrmeet.ssrmeet_begin_time, 'HH24MI' ), 'HH12:MI PM') as start_time, 
  TO_CHAR( TO_DATE( ssrmeet.ssrmeet_end_time, 'HH24MI' ), 'HH12:MI PM') as end_time,

  ( nvl(       decode( ssrmeet.ssrmeet_sun_day, null, '', 'Su')
            || decode( ssrmeet.ssrmeet_mon_day, null, '', 'M')
            || decode( ssrmeet.ssrmeet_tue_day, null, '', 'T')
            || decode( ssrmeet.ssrmeet_wed_day, null, '', 'W')
            || decode( ssrmeet.ssrmeet_thu_day, null, '', 'Th')
            || decode( ssrmeet.ssrmeet_fri_day, null, '', 'F')
            || decode( ssrmeet.ssrmeet_sat_day, null, '', 'Sa'),
            'TBA')
    ) as meetDays

from spriden, sfrstcr, ssbsect, ssrmeet

where
  spriden.spriden_id = /* insert id code here ->'XXXXXXXX' */
  and
  sfrstcr.sfrstcr_pidm = spriden.spriden_pidm
  and
  ssbsect.ssbsect_crn = sfrstcr.sfrstcr_crn
  and
  ssbsect.ssbsect_term_code = sfrstcr.sfrstcr_term_code
  and
  ssbsect.ssbsect_term_code = ssrmeet.ssrmeet_term_code
  and 
  ssbsect.ssbsect_crn = ssrmeet.ssrmeet_crn
  ;

/* End code from exercizes 1, 2, unt 3 */
于 2013-04-22T23:04:06.687 回答