devxlogo

Convert Oracle Queries into Microsoft SQL Format

Convert Oracle Queries into Microsoft SQL Format

Migration of an Oracle database to Microsoft SQL server involves converting Oracle queries into the destination format. The syntax of queries in Oracle and SQL is similar, yet not equal. Also, these two DBMS have distinguished sets of built-in functions. Learn more about the most important differences between Oracle and MS SQL syntax.

  1. Oracle’s operator (+) is specific notation for LEFT OUTER JOIN. In Microsoft SQL it must be replaced by LEFT JOIN.
  2. Oracle’s function TO_DATE must be replaced by CONVERT in Microsoft SQL.
  3. Oracle’s CONCAT($s1, $s2) function returns $s2 appended or concatenated to $s1. MS SQL does not have the equivalent function, so it must be replaced by concatenation operator, the plus sign.
  4. Oracle’s function nvl($var, $expr) that returns $expr if $var is NULL must be replaced by MS SQL equivalent ISNULL($var, $expr).
  5. Oracle’s function nvl2($var,$expr1,$expr2) that returns $arg2 if $var is NULL and $arg1 if $var is not NULL must be replaced in MS SQL as follows:
    CASE WHEN $var IS NOT NULL THEN $arg1 ELSE $arg2 END
  6. Oracle’s function SYSDATE that returns the current date and time must be replaced by GETDATE().
  7. Oracle does not require aliases for subqueries, while Microsoft SQL require it.
  8. Oracle’s function TO_DATE must be replaced by CONVERT as follows:
    TO_DATE( $date, 'YYYYMMDD' ) - CONVERT( DATETIME, $date ) 
  9. Oracle’s function ADD_MONTHS($datetime, $n) that adds $n months to $datetime must be replaced by DATEADD($month, $n, datetime) in MS SQL.
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist