Skip to Main Content
  • Questions
  • execute already written Mysql query on the oracl

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, iram.

Asked: June 09, 2009 - 1:14 am UTC

Last updated: October 06, 2010 - 6:09 am UTC

Version: 10.2

Viewed 1000+ times

You Asked

Hi

I have successfully converted my MySql database in oracle. Now the problem is how to execute already written hundreds of Mysql query on the oracle. There are many syntax variation in Mysql query format which is not acceptable for oracle.

For Example

Select case_id as 'this is alias' from cases

The above query can run on Mysql database but have problem while executing Oracle, because single quotes should be replaced with double quotes before executing it on oracle. There are also many other syntax conflicts.

I have tried to resolve the problem through SwisSQLAPI but problem still exist as SwisSQLAPI is not dealing with all syntax conflict. In my case (select if (expresion, true,false)) must be replace with decode (expression, value,true,false) function of oracle and this conversion is not supported by SwisSQLAPI.

Please help me in resolving this problem

Thanks

and Tom said...

The above query does not conform to the ANSI SQL standard and is using proprietary MySQL syntax.

I would presume that you will encounter many such "mysql didn't follow the standard" issues.

and you would not replace "if(expression,true,false)" with decode, you would use CASE - which is standard compliant.

Sorry, I'm not aware of any mysql to ansi sql conversion packages.

I'll publish this to see if others have input for you.

Rating

  (5 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

why not Migration Workbench or SQL Developer?

Duke Ganote, June 09, 2009 - 4:03 pm UTC

Tom Kyte
June 10, 2009 - 8:48 am UTC

it moves the data

<quote>

Status Today

* Oracle SQL Developer
SQL Developer allows you to migrate your existing Microsoft SQL Server, Microsoft Access, Sybase Adaptive Server, or MySQL databases to any Oracle database in a simple point-and-click process. Tightly integrated with SQL Developer, the migration functionality migrates all schema objects, triggers, stored procedures and data.
* Oracle Migration Workbench (10.1.0.4.0 )
The original stand-alone Oracle Migration Workbench (OMWB) allows you to migrate your existing Informix Dynamic Server, IBM DB2/400 and IBM DB2 UDB database to any Oracle database. This tool migrates all schema objects, triggers, stored procedures and data.

</quote>

they already have accomplished that.

Migration of data yes, but more...

David Weigel, June 10, 2009 - 10:03 am UTC

There's the big migration thing in SQL Developer, but for easy conversion of just a procedure there's the "Translation Scratch Editor", listed under the "Migration" tab. Paste the other DBMS's code in the left window, click a button, and the Oracle equivalent appears in the right window. (I haven't used it for MySQL, but I have for SQL Server.)

It really transliterates the code rather than "converting" it, as you'd want to incorporate smart Oracle techniques that the other DBMS's code wouldn't have. It saves on the initial typing, though. I typed Iram's...
  select case_id as 'this is alias' from cases

...and it spat out:
  SELECT case_id "this is alias"
    FROM cases;

Tom Kyte
June 10, 2009 - 3:00 pm UTC

and that would not convert his program - he has a program with hundreds of SQL's and is looking for the magic esperanto translator so he can speak mysql to any database.

it doesn't exist.

translating the simple mysql queries into standard sql - simple.

to do it to hundreds of statements - time consuming.

SQL sprinkled like confetti?

Duke Ganote, June 11, 2009 - 9:20 am UTC

So the is SQL scattered around the application code, rather than condensed into a data access layer, or invoked through stored procedures?

Sounds like re-architecture time!

http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:12083187196917#1753309400346975595

oracle query to convert in mysql

goutham, October 06, 2010 - 5:48 am UTC

SELECT e.empid, e.logonid, e.title,
concat (e.first_name , ' ' , e.last_name)emp_name, e.dob, e.role_lookupid,
fnc_get_lookup_value ('Emp', 'Role', e.role_lookupid) role_value,
e.emp_is_dr_resource, e.release_date, p.MANAGERID,
FNC_GET_EMP_NAME(p.MANAGERID) manager_name, p.tlid,
FNC_GET_EMP_NAME(p.tlid) tlname, p.PLID,
FNC_GET_EMP_NAME(p.tlid) plname,e.emptype_lookupid,
fnc_get_lookup_value ('Emp','EmployeeType', e.emptype_lookupid) emp_type,
fnc_get_lookup_value ('Emp','WorkLoc', e.work_loc_lookupid) work_loc_value,
e.work_loc_lookupid, e.isactive, ep.prjid,
p.project_name, ep.work_bill_flag,e1.empid pm_id,
concat(e1.first_name, ' ',e1.last_name) pm_name, ec.extn,
p.prj_short_name,p.start_date, p.end_date,p.prj_static_folder,p.PROJECTSETUPCODE ,
p.prj_working_folder,
(select case when line_two is not null then concat(line_one,' ',line_two)
when city is not null then concat(line_one,' ',line_two,' ',city)
when state is not null then concat(line_one,' ',line_two,' ',city,' ',state)
when pincode is not null then concat(line_one,' ',line_two,' ',city,' ',state,' ',pincode)
ELSE line_two END as home_addr
FROM emp_client_address
WHERE emp_client_id =e.empid
AND addr_entry_type = 'E'
AND addresstype_lookupid = 43) address , e.first_name, e.last_name
FROM emp_mst e, emp_mst e1, emp_prj_dets ep, prj_mst p, emp_contact_info ec ;
WHERE UPPER (e.logonid) = UPPER ('arun')
AND e.isactive = 'T'
AND ep.empid = e.empid
AND p.prjid = ep.prjid
AND nullif(ep.work_bill_flag='W','') IN ('B', 'W')
AND e1.empid = p.MANAGERID
AND ec.empid = e.empid
AND ec.contact_type_lookupid = '55'
AND ep.primary_project = 'Y'
AND p.prjid = ep.prjid;

Tom Kyte
October 06, 2010 - 6:09 am UTC

I have no idea what you are trying to say, ask or whatever.

do you have "a question"

and do not say "my question is I want you to rewrite my query", the question may be something like - "as I am trying to rewrite this query, I have this specific question"

and if the question involves "how do I convert this specific mysql function", the question best include a complete description of what they function does in mysql, given I'm not a mysql developer.

plesae show some courtesy

Ravi B, October 06, 2010 - 3:50 pm UTC

Guys,

I have seen time and again people posting without any description of the problem, create statements, examples or any basic information. Please don't treat asktom as an entitlement (lack of better word) rather, it is a privilege to get a response from Tom. He takes time from his busy schedule to answer our questions. He doesn't have to answer questions without any details what-so-ever but he still does. Show respect for his time and provide as much details as you can. Tom doesn't know our business, schema, design or code. It is our duty to give the information if we need quick answer. Tom will ask you if he needs more info.

My 2c.

-Ravi

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library