Oracle SQL Developer: Scratch Editor
Learn how to use the Scratch Editor module in Oracle SQL Developer, which helps translate code written in non-Oracle systems.
Join the DZone community and get the full member experience.Join For Free
This article is about the Scratch Editor module provided with migration support of Oracle SQL Developer.
One of the strengths of Oracle SQL Developer (which is free) is to provide a powerful infrastructure for migration from non-Oracle databases to Oracle databases. There is more than one feature in this infrastructure, but I'm going to talk to Scratch Editor, which I find very useful.
Scratch Editor translates SQL/procedural SQL code written in non-Oracle (i.e. MS SQL, Teradata, Access, Sybase, DB2) systems into Oracle SQL or PL/SQL code. This allows you to rapidly translate the application code you have written in the database into an Oracle SQL/PLSQL notation when you need to migrate from non-Oracle systems to an Oracle system.
Now let's look at how the Scratch Editor is accessed and make a few examples.
In Scratch Editor, go to Tools > Migration > Scratch Editor.
After opening Scratch Editor, a screen like the one below is opened. Let's see how it's used.
To explain the numbered areas in the picture:
The section from which we choose to transform.
The part of the code that we will write to translate.
The button to start the conversion process.
The area where the result is written.
The button to run the generated code in the selected Oracle DB.
Let's look at how it works with a few examples.
First, I will try to translate the SQL statements I have written in MS SQL, in which MS SQL-specific functions are used, into Oracle.
SELECT Isnull(employee_id, 1) FROM hr.employees; SELECT TOP 5 * FROM hr.employees; SELECT first_name + ' ' + last_name FROM hr.employees; SELECT Len(first_name), Getdate() FROM hr.employees; SELECT Substring(first_name, Charindex('EM', first_name), 25) FROM employees;
SELECT Nvl(employee_id, 1) FROM hr.employees; SELECT * FROM hr.employees WHERE rownum <= 5; SELECT first_name || ' ' || last_name FROM hr.employees; SELECT Length(first_name), sysdate FROM hr.employees; SELECT Substr(first_name, Instr(first_name, 'EM'), 25) FROM employees;
We see that MS SQL-specific functions are properly translated into Oracle SQL.
Now, let's look at how the conversion from a stored procedure written in MS SQL to Oracle is done.
CREATE PROC Usp_kategoriurunadet (@KategoriID INT) AS BEGIN DECLARE @adet INT; SELECT @adet=Count(productid) FROM production.product WHERE productsubcategoryid=@KategoriID; RETURN @adet END//soruce codeFROM:HTTP://www.yazilimdilleri.net
CREATE OR replace FUNCTION Usp_kategoriurunadet(v_kategoriid IN NUMBER) RETURN NUMBER AS v_adet NUMBER(10, 0); BEGIN SELECT Count(productid) INTO v_adet FROM production.product WHERE productsubcategoryid = v_kategoriid; RETURN v_adet; EXCEPTION WHEN OTHERS THEN utils.Handleerror(SQLCODE, SQLERRM); END;
We see that our outcome is successful.
As seen in the Scratch Editor of Oracle SQL Developer, applications written in a non-Oracle system provide us with a lot of conveniences when adapting to an Oracle database. We need to do a real migration to test how successful the complex applications are in their conversions, but even if we can't achieve 100% success, we still don't have to rewrite the entire implementation with our translator.
Opinions expressed by DZone contributors are their own.