【问题标题】:Change from Default Date to preferred date in this DBMS_SQL?在此 DBMS_SQL 中从默认日期更改为首选日期?
【发布时间】:2020-10-01 02:42:59
【问题描述】:

此代码来自建议的解决方案: https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:9541646100346616701

我的查询是'select * from table'

第二列是一个日期,这个例程将它写入我的 IDE 会话中显示的内容('DD-MON-YY');

如何将 DATE 列中的值报告给“YYYY-MM-DD”?

procedure clob_maker(p_query varchar2) is

      l_theCursor     integer default dbms_sql.open_cursor;
      l_columnValue   varchar2(4000);
      l_status        integer;
      l_descTbl       dbms_sql.desc_tab;
      l_colCnt        number;
      n number := 0;

      l_data clob;
  begin
      dbms_sql.parse(  l_theCursor,  p_query, dbms_sql.native );
      dbms_sql.describe_columns( l_theCursor, l_colCnt, l_descTbl );

      for i in 1 .. l_colCnt loop
          dbms_sql.define_column(l_theCursor, i, l_columnValue, 4000);
      end loop;

      l_status := dbms_sql.execute(l_theCursor);

      while ( dbms_sql.fetch_rows(l_theCursor) > 0 ) loop
          for i in 1 .. l_colCnt loop 
              dbms_sql.column_value( l_theCursor, i, l_columnValue );
              --dbms_output.put_line(l_columnValue);  --this puts every column on a separate line
                l_data := l_data || l_columnValue ||',';
          end loop;
            dbms_output.put_line(l_data);
          n := n + 1;
      end loop;
      --dbms_output.put_line(l_data);
  end  clob_maker;

clob_maker('select * from mlb_catcher_birthdays fetch first 10 rows only');

【问题讨论】:

标签: sql oracle date stored-procedures oracle12c


【解决方案1】:

表示日期的默认格式由 NLS 参数ns_date_format 控制。您可以在会话级别更改此参数:

alter session set nls_date_format = 'YYYY-MM-DD';

可以也使用TO_CHAR(),其格式说明符与第二个参数相同 - 但这不太适合您的用例,因为您需要检查每个参数的数据类型列之前打印它的值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-14
    • 2016-01-25
    • 2011-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多