Showing posts with label Oracle 23c. Show all posts
Showing posts with label Oracle 23c. Show all posts

Monday, April 29, 2024

Oracle 23c New Feature - Grouping by an alias


Probably , this is my shortest blog post till now. 

In Oracle 23c , we can group by the alias name .

This simple enhancement  improves readability in the SQL statements. 


SQL> select banner from v$version ;  

BANNER           

Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release    


SQL> create table t as select * from all_objects;

Table T created.


SQL> select to_char(created,'MON') as created_month , count(*) from t

  2* group by created_month;


CREATED_MONTH       COUNT(*) 

________________ ___________ 

MAR                    57620 

APR                     1014 

MAY                        1 


Maria DB 

This feature has been in MySQL / MariaDB for quite sometime. Here is an example from MariaDB


MariaDB [(none)]> create database testdb ;

Query OK, 1 row affected (0.008 sec)


MariaDB [(none)]> use testdb;

Database changed

MariaDB [testdb]> Create table t as select * from information_schema.tables;

Query OK, 324 rows affected (0.129 sec)

Records: 324  Duplicates: 0  Warnings: 0


MariaDB [testdb]> select

    ->  to_char(create_time,

    ->  'MON') as created_month ,

    ->  count(*)

    -> from

    ->  t

    -> group by

    ->  created_month;

+---------------+----------+

| created_month | count(*) |

+---------------+----------+

| NULL          |      184 |

| May           |      140 |

+---------------+----------+

2 rows in set (0.007 sec)


 

Monday, May 1, 2023

Scalar SQL Macro and DUAL in 23c

 

In the last blog post on SQL Macros , ( https://zahirmohideen.blogspot.com/2023/03/sql-macros.html) , I was exploring SQL macros. 

In Oracle 23c , scalar macro is ported from 21c . 

BTW , I am testing this feature on 23c Free - Developer's Release ( https://www.oracle.com/database/free/)  

Here is the test case from the previous post. 


BANNER                                                                          

___________________________________________________________________             

Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release   

SQL> CREATE OR replace FUNCTION calculate_pies (

  2          p_arg1 NUMBER

  3      ) RETURN VARCHAR2 sql_macro ( scalar ) is

  4      begin         

  5      return q'{                                                  

  6          p_arg1 * 3.14                                            

  7        }';

  8      end;                                                        

  9*     /                                                                      

Function CALCULATE_PIES compiled                                                

  SQL> SELECT   

  2    level,                                                      

  3    calculate_pies(level)                                         

  4   FROM    

  5  dual                                                            

  6  CONNECT BY                                                      

  7* level <= 5;                                                        

 LEVEL    CALCULATE_PIES(LEVEL)                                     ________ ________________________                                           1                     3.14   

       2                     6.28                                  

       3                     9.42                                    

       4                    12.56                                    

       5                     15.7                                  

Another new feature is that we don't need DUAL  to get the results.Albeit this feature is tiny , it goes parallel with all other RDBMSes 

SQL> SELECT  

  2    level,                                                     

  3    calculate_pies(level)                                         

  4  CONNECT BY                                                      

  5* level <= 5;


LEVEL    CALCULATE_PIES(LEVEL) 

________ ________________________ 

       1                     3.14 

       2                     6.28 

       3                     9.42 

       4                    12.56 

       5                     15.7 

More to come on 23c New Features. 

Stay Tuned.