DZone
Database Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Database Zone > Oracle SQL Developer: Scratch Editor

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.

Emrah Mete user avatar by
Emrah Mete
CORE ·
May. 17, 17 · Database Zone · Tutorial
Like (8)
Save
Tweet
5.88K Views

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.

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.

sql Scratch (programming language) Oracle SQL Developer dev Database

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Container Orchestration Tools Comparison
  • How Do You Integrate Emissary Ingress With OPA?
  • Top ALM Tools and Solutions Providers
  • Exhaustive JUNIT5 Testing with Combinations, Permutations, and Products

Comments

Database Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo