Monday, June 23, 2025
HomeJavaDistinction between Oracle SQL Question vs Microsoft SQL Server or Sybase? Reply

Distinction between Oracle SQL Question vs Microsoft SQL Server or Sybase? Reply


Oracle and Microsoft SQL Server are two of the most well-liked database however they’re very totally different from one another and in case you are migrating SQL queries or databases, tables from Oracle database to Microsoft SQL Server 2008 then you might be certain to face some points. The principle purpose for these porting points are options which might be supported and exists within the Oracle database, however not accessible in Microsoft SQL Server 2008 like SEQUENCE, Order by clause in subqueries, and derived tables, derived desk and not using a identify, and so forth. I’m certain there are just a few extra and they’re going to floor primarily based upon totally different database objects you might be utilizing in your tables and queries.


On one other hand SQL engine for SQL Server and Sybase are very a lot comparable, a minimum of syntactically, and in case you are migrating queries from SQL Server to
Sybase you can do this with out a lot trouble, in fact, there shall be slight adjustments however not as a lot as Oracle.

So, in case you are migrating from Oracle to Sybase or SQL Server it is almost definitely the identical job and it’s best to first begin with both SQL Server or Sybase ASE after which later migrate them from one another. 

On this Oracle and SQL Server tutorial, we are going to see a few examples, the place Oracle and SQL Server are totally different and the way to change these SQL queries in order that they’ll run on Microsoft SQL Server. 

Migrating SQL queries from Oracle to SQL Server

As I stated, we confronted three predominant issues whereas migrating our SQL queries from Oracle to SQL Server, these are associated to SEQUENCE object, order by clause in subqueries, and utilizing nameless derived tables. Let’s see them one after the other.

1. Order by in subquery or derived desk

Oracle helps order by clause in a subquery and derived tables, however while you attempt to run the identical question, which is working superb in Oracle, in SQL Server or Sybase, you’ll get the next error as a result of they don’t assist order by clause on derived desk or subquery.

Error: The ORDER BY clause is invalid in views, inline features, derived tables, subqueries, and customary desk expressions until TOP or FOR XML can also be specified.

Answer:
With a purpose to clear up this drawback you want to take away order by clause from subquery and derived desk and transfer these to the principle consequence set, more often than not you are able to do that however if you cannot then you definately in all probability must rewrite the entire question. 

The beneath question will work in Oracle however won’t work in Microsoft SQL Server, as it’s utilizing order by clause in a subquery:

choose CUSTOMER_ID,CUSTOMER_ADDRESS from CUSTOMER 
the place CUSTOMER_IDS IN 
    (choose SELLER_ID from TRANSACTIONS the place ITME_TYPE='PC' 
     order by PURCHASE_DATE)

With a purpose to make it work we have to take away order by clause from subquery and like beneath:

choose CUSTOMER_ID,CUSTOMER_ADDRESS from CUSTOMER 
the place CUSTOMER_IDS IN 
    (choose SELLER_ID from TRANSACTIONS the place ITME_TYPE='PC')
if this isn’t what you want then you want to rewrite this question using SQL Joins.

2. Derived desk and not using a identify

The second distinction I discovered between Oracle and SQL Server question is that oracle permits you to question derived tables and not using a specifying identify however SQL Server does not permit it. Take a look at the next question, which works completely in Oracle however provides syntax error in SQL Server :

choose depend(*) from (
    choose BUYER_ID from TRANSACTIONS
     the place SELLER_ID= 'james_2012' 
     and item_type='PC'
    UNION
    choose SELLER_ID from TRANSACTIONS 
     the place BUYER_ID= 'james_2012' 
     and item_type='PC'
 )


Error: Incorrect syntax close to ‘)’

Answer:
This error was extraordinarily straightforward to repair, we simply want to supply a reputation to our derived desk utilizing “as” key phrase, right here is the modified SQL question which is able to work in Sybase and Microsoft SQL Server 2005, 2008 and could also be in one other model :

choose depend(*) from (
    choose BUYER_ID from TRANSACTIONS 
    the place SELLER_ID= 'james_2012' 
    and item_type='PC'
    UNION
    choose SELLER_ID from TRANSACTIONS 
    the place BUYER_ID= 'james_2012' 
    and item_type='PC'
 ) as sells



3. SEQUENCE Object

One other drawback we confronted whereas migrating our queries from Oracle to SQL Server is said to the SEQUENCE object. We had been utilizing Oracle SEQUENCE object to geneprice routinely incremented id and SEQUENCE are usually not supported in Microsoft SQL Server (let me know if it does as a result of I attempted to create SEQUENCE and it provides the error “Unknown object kind ‘SEQUENCE’ utilized in a CREATE, DROP, or ALTER assertion”).

The one resolution was to take away the SEQUENCE code and as a substitute use the IDENTITY function of SQL Server, which is just like sequence and creates routinely incremented columns. You present IDENTITY a seed and an incremental worth, the default is (1,1) and it routinely generates numbers for yours. 

What involves us as a nice shock was pagination queries, we had some oracle pagination queries in our software which is written utilizing the row_num() perform and we’re fascinated with the way to migrate them into the SQL server, earlier than discovering that SQL Server additionally helps ROW_NUM() perform.


Briefly Oracle, pagination queries run superb on SQL Server besides few adjustments talked about above like order by clause inside subquery or derived desk.

That is it on migrating SQL queries from Oracle to SQL Server or Sybase ASE database. I’m certain there’s way more distinction between Oracle and SQL Server, which I have not coated just because I have not confronted them.

By the way in which, these had been a number of the most typical adjustments, you want to make to run your oracle question into the SQL server.  In case you have additionally finished the identical job then please tell us what sort of subject you will have confronted on the SQL Server aspect and the way did you clear up it. Hmm, feels like query?

P. S. – By the way in which, I’ve additionally written a few posts on queries like 10 methods to make use of SQL SELECT queries and Don’t delete, truncate it. When you like studying extra on SQL queries then these are for you.



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments