Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Why isn't my group by on to_char working?

stomJan 15 2020 — edited Jan 17 2020

Hi,

I am trying to group the records in a table by year. I don't know why it isn't working.

When I try it with a sample data set, it works fine.

for example, this query has 2 dates in 2018 and 1 date in 2019. The group by works as expected.

SQL> set echo on;

SQL>     with data_set(date_value) as

  2  (

  3  select to_date('9/26/2018','mm/dd/yyyy') from dual union all

  4  select to_date('9/27/2018','mm/dd/yyyy') from dual union all

  5  select to_date('9/28/2019','mm/dd/yyyy') from dual

  6  )

  7  select to_char(date_value,'YYYY') year_value, count(*) from data_set group by to_char(date_value,'YYYY');

YEAR   COUNT(*)

---- ----------

2019          1

2018          2

When I try it on one of my tables, it doesn't work. It list all the dates separately instead of grouping them. I have used the ddl function in Sql Developer to show the table structure.

SQL> ddl ref_clearing_calendar;

  CREATE TABLE "ICEREF"."REF_CLEARING_CALENDAR"

   ( "CALENDAR_NAME" CHAR(17),

"BUSINESS_DATE" DATE,

"UPDATE_TS" TIMESTAMP (6) DEFAULT systimestamp,

CONSTRAINT "PK_REF_CLEARING_CALENDAR" PRIMARY KEY ("BUSINESS_DATE")

  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS

  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645

  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1

  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)

  TABLESPACE "REF_DATA"  ENABLE,

SUPPLEMENTAL LOG GROUP "GGS_92500" ("BUSINESS_DATE") ALWAYS,

SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS,

SUPPLEMENTAL LOG DATA (UNIQUE INDEX) COLUMNS,

SUPPLEMENTAL LOG DATA (FOREIGN KEY) COLUMNS

   ) SEGMENT CREATION IMMEDIATE

  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255

NOCOMPRESS LOGGING

  STORAGE(INITIAL 81920 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645

  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1

  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)

  TABLESPACE "REF_DATA" ;

SQL>

SQL> SELECT

  2      to_char(business_date, 'yyyy'),

  3      COUNT(*)

  4  FROM

  5      ref_clearing_calendar

  6  GROUP BY

  7      to_char(business_date, 'yyyy');

TO_C   COUNT(*)

---- ----------

2000          1

2000          1

2000          1

2000          1

2000          1

2000          1

2000          1

2000          1

2000          1

2000          1

2000          1

TO_C   COUNT(*)

---- ----------

2000          1

2000          1

2000          1

2000          1

2000          1

2000          1

2000          1

2000          1

2000          1

2000          1

2000          1

TO_C   COUNT(*)

---- ----------

2000          1

2000          1

2000          1

2000          1

2000          1

2000          1

2000          1

2000          1

2000          1

2000          1

I tried to create a sample table with date values but I wasn't able to replicate the issue on a different object. What am I doing wrong?

Version: 12.2.0.1.0

Thanks!

This post has been answered by Solomon Yakobson on Jan 15 2020
Jump to Answer

Comments

Russ Proudman
Well if you mean, can Discoverer look at tables / views on a SQL server then yes, I believe you can make a connection such as odbc or jdbc. However, not all SQL functions will be supported as Oracle has some of it's own whereas the protocol standards would only be supported.

If you mean can Discoverer run on the SQL server (ie: EUL tables, etc.), then no.

Russ
SteveF-Oracle
To add to what Russ stated.

You have to install the EUL on Oracle DB, then use Heterogenous Services (ODBC connectors) connectivity from Oracle DB to non-Oracle DB.

It is covered in the Adminstrator Guide in pretty good detail
http://download-west.oracle.com/docs/html/B13916_04/rdb_support.htm#CIHJEJBB
23 Discoverer support for non-Oracle databases and Oracle Rdb

Regards,

Steve.
Russ Proudman
And one thing I'm just passing by all, is the quote about non-Oracle database using / not using ODBC drivers.

This question came up a while ago and I quoted the manual saying that if you use ODBC drivers, then the EUL could be in the non-Oracle database.

After lotsa' posts, etc. it was decided that the documentation was wrong. Whether or not you use ODBC, you cannot have the EUL in a non-Oracle database.

Just passing this on as the manual differs.

Russ

=========================================================
quote from manual:

What is the difference between using generic connectivity and ODBC drivers to connect to non-Oracle databases?

In previous versions of Discoverer, users could connect to non-Oracle databases using ODBC drivers. The major difference between using ODBC drivers to connect to a non-Oracle database and using the Oracle database generic connectivity feature is the location of the EUL, as follows:

with ODBC drivers, the EUL is stored in the non-Oracle database

with generic connectivity, the EUL is stored in the Oracle database

===========================================================
1 - 3

Post Details

Added on Jan 15 2020
14 comments
20,979 views