Monday, July 23, 2012

Scratch Editor in SQL Developer


I have been using SQL Developer since its inception ( I started reading about it from the original project "raptor" ) .  I can't say , I have explored all the possiblities with this tool .  

Today , I ran into  menu item "Scratch Editor"  . This neat utility lets me to translate T-SQL component into T-SQL . Also , it has options for MS-ACCESS to PL/SQL  , SYBASE T-SQL to PL/SQL , DB2 SQL to PL/SQL.

I have not tried all the variations of the T-SQL  to PL/SQL. So far , almost all the simple SQL gets translated correctly.

Source T-SQL:


select top 5 (FName + ', ' + LName) as Full_Name,
isnull(Graduated, 'GOK - God only Knows')
, COALESCE( null , 1 , 2, 3  ) as Test_Colasece
from dbo.Student
order by student_id



Translated PL/SQL:

SELECT *
  FROM ( SELECT (FName || ', ' || LName) Full_Name  ,
                NVL(Graduated, 'GOK - God only Knows') ,
                COALESCE(NULL, 1, 2, 3) Test_Colasece 
  FROM /*dbo.*/Student
  ORDER BY student_id )
  WHERE ROWNUM <= 5;



Few Observations :

1) The schema  ( dbo ) has been commented in the translated PL/SQL. Not sure why  , as the schema in MS SQL Server is almost same as the schema in Oracle.

2) The concatenation operator has been tranlated correctly.

3) ISNULL has been translated as NVL


To acccess this menu item , you would click on "Tools -> Translation Scratch Editor" .

Just one side note:
For some reason , SQL Developer does not support PostgreSQL. I wish SQL Developer supports connectivity to Postgres natively  in the near future.