有点类似c的宏定义,不知道sql里怎么实现,请各位赐教
比如select to_char(get_date_from_millisecond(tr.time),'yyyy/mm/dd hh24:mi:ss'), b, c from tr
怎么把to_char(get_date_from_millisecond(tr.time),'yyyy/mm/dd hh24:mi:ss')定义为一个常量,方便字段b和字段c调用呢?
先行谢过

解决方案 »

  1.   

    我的目的是这样,因为这个值得反复用,但是整个表达式又太长影响阅读,有没有方法定义一下,类似define A=....,然后以后就直接调用A就行了
      

  2.   

    oracle不支持宏定义。只能把一个值定义成常量。
    例如:GCN_STR_PGM_ID           CONSTANT VARCHAR2(20)  DEFAULT 'XX010101';或者把to_char(get_date_from_millisecond(tr.time),'yyyy/mm/dd hh24:mi:ss')定义成一个函数function getDateTime (pi_time in date)
    return varchar2
    is
    begin
        return to_char(get_date_from_millisecond(pi_time),'yyyy/mm/dd hh24:mi:ss')
    end;调用时select getDateTime (tr.time), b, c
    from tr;