如何在Oracle SQLcl中设置COLUMN HEADING?

问题描述 投票:0回答:1

我正在尝试创建一系列具有标题值的列来生成报告:

SET PAGESIZE 1;
SET LINESIZE 400;
    COLUMN C_DATEOFFSET NEW_VALUE VAL_DATEOFFSET    FORMAT A20  HEADING From_Julian;
    COLUMN C_DATEOFFSE2                             FORMAT A20  HEADING From_Date;
    COLUMN C_GLOBALNAME                             FORMAT A20  HEADING DB_Name;
    COLUMN C_OSUSER                                 FORMAT A20  HEADING OS_User;
    COLUMN C_DBUSER                                 FORMAT A20  HEADING DB_User;
    COLUMN C_TIMESTAMP                              FORMAT A40  HEADING TimeStamp;

ACCEPT MOFFSET DEFAULT '1' PROMPT 'Month Offset: ';

SELECT VARGN C_GLOBALNAME, VAROS C_OSUSER, VARDB C_DBUSER, 
        TO_CHAR(VARTS, 'YYYY-MON-DD HH24:MI TZH') C_TIMESTAMP, 
        TO_CHAR(VARDTOFF, 'YYYY-MON-DD') C_DATEOFFSE2, TO_CHAR(VARDTOFF, 'YYYYDDD') - 19E5 C_DATEOFFSET
        FROM (SELECT
            GLOBAL_NAME VARGN, UPPER(SYS_CONTEXT('USERENV', 'OS_USER')) VAROS, USER VARDB, SYSTIMESTAMP VARTS,
            TO_DATE(TO_CHAR(SYSDATE - INTERVAL '&MOFFSET' MONTH, 'YYYYMM"01"'), 'YYYYMMDD') VARDTOFF
                FROM GLOBAL_NAME);

SET PAGESIZE 0;

我的期望是得到像我在 SQL Developer 中看到的那样的结果:

DB_Name              OS_User              DB_User              TimeStamp                                From_Date                     From Julian
-------------------- -------------------- -------------------- ---------------------------------------- -------------------- --------------------
JDEPD03              FELIPE.VIDAL         43CY                 2024-SEP-11 16:57 -05                    2024-AUG-01                        124214

但是当我转向 SQLcl 时,它不起作用:

C_GLOBALNAME         C_OSUSER             C_DBUSER             C_TIMESTAMP                              C_DATEOFFSE2                 C_DATEOFFSET
-------------------- -------------------- -------------------- ---------------------------------------- -------------------- --------------------
JDEPD03              FELIPE.VIDAL         43CY                 2024-SEP-11 17:02 -05                    2024-AUG-01                        124214

对于为什么列标题不一致有什么建议吗?我可能缺少任何 SET 参数吗?

谢谢!

sql oracle oracle-sqldeveloper sqlcl
1个回答
0
投票

使用 SQL*Plus 命令设置标题的另一种方法是在查询中指定列别名:

COLUMN "From_Julian" NEW_VALUE VAL_DATEOFFSET  FORMAT A20;
COLUMN "From_Date"                             FORMAT A20;
COLUMN "DB_Name"                               FORMAT A20;
COLUMN "OS_User"                               FORMAT A20;
COLUMN "DB_User"                               FORMAT A20;

SELECT GLOBAL_NAME AS "DB_Name",
       UPPER(SYS_CONTEXT('USERENV', 'OS_USER')) AS "OS_User",
       USER AS "DB_User",
       TO_CHAR(SYSTIMESTAMP, 'YYYY-MON-DD HH24:MI TZH') AS "TimeStamp",
       TO_CHAR(
         ADD_MONTHS(TRUNC(SYSDATE, 'MM'), -&MOFFSET),
         'YYYY-MON-DD',
         'NLS_DATE_LANGUAGE=English'
       ) AS "From_Date",
       TO_CHAR(
         ADD_MONTHS(TRUNC(SYSDATE, 'MM'), -&MOFFSET),
         'YYYYDDD'
       ) - 1900000 AS "From_Date"
FROM   GLOBAL_NAME;
© www.soinside.com 2019 - 2024. All rights reserved.