What’s New in Oracle Database 23c - Group By Alias - Demonstration
What’s New in Oracle Database 23c - Group By Alias - Demonstration!
- Oracle Database 23c delivers the most complete and simple converged database for developers looking to build new microservice, graph, document, and relational applications.
- Since Oracle's 23C is a long term release, the database has already been released for developers on April 6th, 2023. Oracle Cloud's non-production environments are updated on the first Friday of your quarterly update month.
- Whether you are a Developer, a Data Scientist, a DBA, an Educator, or just interested in databases, Oracle Database 23c Free—Developer Release is the ideal way to get started.
- Oracle will share new features updates about Oracle Database 23c with examples so you can get up and running quickly.
Okay, Let’s See the Feature Highlights…
GROUP BY column alias:
You can now use column alias or SELECT item position in GROUP BY, GROUP BY CUBE, GROUP BY ROLLUP, and GROUP BY GROUPING SETS clauses. Additionally, the HAVING clause supports column aliases. These new Database 23c enhancements make it easier to write GROUP BY and HAVING clauses, making SQL queries much more readable and maintainable while providing better SQL code portability.
In previous versions of Oracle, I could never understand why a GROUP BY clause in a SELECT statement does not allow a column alias or a position number. For ORDER BY this is allowed, but not for GROUP BY. For example, if you run the following query on an Oracle 19c database, it will cause an error message:
Demo:
In Oracle 19c Database:
SQL> create table pepsi_delivery (year number, pepsi varchar2(10), pepsi_type varchar2(10));
Table created.
SQL> insert into pepsi_delivery values (2020, '500 ml', 'Cane');
1 row created.
SQL> insert into pepsi_delivery values (2021, '300 ml', 'Cane');
1 row created.
SQL> insert into pepsi_delivery values (2022, '200 ml', 'Bottle');
1 row created.
SQL> commit;
Commit complete.
SQL> SELECT TO_CHAR(bottling_date, ‘YYYY’) year, pepsi, pepsi_type FROM pepsi_delivery GROUP BY year, pepsi, pepsi_type ORDER BY 1, 2, 3;
SELECT TO_CHAR(bottling_date, ‘YYYY’) year, pepsi, pepsi_type FROM pepsi_delivery GROUP BY year, pepsi, pepsi_type ORDER BY 1, 2, 3
*
ERROR at line 1:
ORA-00904: "???YYYY???": invalid identifier
The problem is the column alias year that is used in the SELECT clause. An alias is allowed in the ORDER BY clause, but not in the GROUP BY. There is no logical restriction for this – other relational databases support this syntax since years. In Oracle, we had to copy the expression of the SELECT clause into the GROUP BY clause to run the SQL statement:
SELECT year, pepsi, pepsi_type FROM pepsi_delivery GROUP BY 1, 2, 3 ORDER BY 1, 2, 3;
Connect me on:
Blog: https://www.oralgwr.com/
LinkedIn: https://www.linkedin.com/in/ramesh-kumar-krishnamoorthy-3a67ba69/
Twitter: https://twitter.com/sachinrameshdba
Facebook: https://www.facebook.com/rameshkumar.krishnamoorthy.9/
Facebook Page: https://www.facebook.com/oraclef1
Instagram: https://www.instagram.com/oraclef1_1
YouTube: https://www.youtube.com/oraclef1
YouTube: https://www.youtube.com/oracledbatutorialtamil
1 comments :
Thanks for this update.
Reply