Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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

Learn how to move from MongoDB to Couchbase Server for consistent high performance in distributed environments at any scale.

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.

scratcheditor2

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; 

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; 

Results:

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; 

scratcheditor3

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

Result:

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; 

scratcheditor4

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.

Want to deliver a whole new level of customer experience? Learn how to make your move from MongoDB to Couchbase Server.

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

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}