Over a million developers have joined DZone.

Oracle SQL Developer: Scratch Editor

DZone's Guide to

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.

· Database Zone ·
Free Resource

Self-hosted vs Managed Service?  Learn how managed enterprise graph databases reduce project costs and increase time-to-delivery.

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.

scratcheditor1After 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:

  1. The section from which we choose to transform.

  2. The part of the code that we will write to translate.

  3. The button to start the conversion process.

  4. The area where the result is written.

  5. 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; 

FROM   hr.employees; 

SELECT first_name + ' ' + last_name 
FROM   hr.employees; 

SELECT Len(first_name), 
FROM   hr.employees; 

SELECT Substring(first_name, Charindex('EM', first_name), 25) 
FROM   employees; 


SELECT Nvl(employee_id, 1) 
FROM   hr.employees; 

FROM   hr.employees 
WHERE  rownum <= 5; 

SELECT first_name 
       || ' ' 
       || last_name 
FROM   hr.employees; 

SELECT Length(first_name), 
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) 
    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) 
  v_adet NUMBER(10, 0); 
    SELECT Count(productid) 
    INTO   v_adet 
    FROM   production.product 
    WHERE  productsubcategoryid = v_kategoriid; 

    RETURN v_adet; 
             utils.Handleerror(SQLCODE, SQLERRM); 


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.

Self-hosted vs Managed Service?  Learn how managed enterprise graph databases reduce project costs and increase time-to-delivery.

oracle ,sql ,database ,tutorial ,scratch editor ,oracle sql developer

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}