Oracle to SQL Server Converter: Syntax Guide & Examples
A complete reference for converting Oracle SQL and PL/SQL to SQL Server T-SQL. Covers NVL to ISNULL, SYSDATE to GETDATE(), ROWNUM to TOP, and procedural code migration.
Why Convert Oracle to SQL Server?
Many enterprises migrate from Oracle to SQL Server to consolidate on the Microsoft stack. If your organization already uses Windows Server, Active Directory, .NET, and Azure, SQL Server integrates seamlessly. Microsoft's licensing model, while not free, is typically more predictable and less expensive than Oracle's per-core licensing.
SQL Server also offers strong BI integration with Power BI, SSRS (SQL Server Reporting Services), and SSIS (SQL Server Integration Services). For organizations that need analytics and ETL alongside their transactional database, this integrated ecosystem is a significant advantage.
The migration involves converting Oracle-specific SQL syntax, PL/SQL procedures to T-SQL, and Oracle data types to SQL Server equivalents. Microsoft provides free migration tools (SSMA) that automate much of this work.
Key Syntax Differences
| Feature | Oracle | SQL Server |
|---|---|---|
| NULL replacement | NVL(a, b) | ISNULL(a, b) |
| Current datetime | SYSDATE | GETDATE() / SYSDATETIME() |
| Row limiting | WHERE ROWNUM <= 10 | SELECT TOP 10 |
| String concatenation | a || b | a + b or CONCAT(a, b) |
| Sequence next value | seq.NEXTVAL | NEXT VALUE FOR seq |
| Dual table | SELECT 1 FROM DUAL | SELECT 1 |
| DECODE | DECODE(col, v1, r1) | IIF or CASE WHEN |
| Date arithmetic | SYSDATE + 30 | DATEADD(DAY, 30, GETDATE()) |
| Outer join | (+) operator | Standard LEFT/RIGHT JOIN |
| Procedural language | PL/SQL | T-SQL |
Common Conversions with Examples
NVL to ISNULL
-- Oracle
SELECT NVL(nickname, name) AS display_name FROM users;
SELECT NVL2(commission, salary + commission, salary) FROM employees;
-- SQL Server
SELECT ISNULL(nickname, name) AS display_name FROM users;
SELECT IIF(commission IS NOT NULL, salary + commission, salary) FROM employees;
ROWNUM to TOP
-- Oracle
SELECT * FROM employees WHERE ROWNUM <= 10;
SELECT * FROM (
SELECT e.*, ROWNUM rn FROM employees e ORDER BY salary DESC
) WHERE rn BETWEEN 11 AND 20;
-- SQL Server
SELECT TOP 10 * FROM employees;
SELECT * FROM employees
ORDER BY salary DESC
OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY;
SYSDATE to GETDATE()
-- Oracle
SELECT SYSDATE FROM DUAL;
SELECT * FROM orders WHERE order_date > SYSDATE - 30;
SELECT TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') FROM DUAL;
-- SQL Server
SELECT GETDATE();
SELECT * FROM orders WHERE order_date > DATEADD(DAY, -30, GETDATE());
SELECT FORMAT(GETDATE(), 'yyyy-MM-dd HH:mm:ss');
DECODE to CASE / IIF
-- Oracle
SELECT DECODE(status, 'A', 'Active', 'I', 'Inactive', 'Unknown') FROM users;
-- SQL Server
SELECT CASE status
WHEN 'A' THEN 'Active'
WHEN 'I' THEN 'Inactive'
ELSE 'Unknown'
END FROM users;
Sequences
-- Oracle
CREATE SEQUENCE order_seq START WITH 1 INCREMENT BY 1;
INSERT INTO orders (id, customer) VALUES (order_seq.NEXTVAL, 'Alice');
-- SQL Server (2012+)
CREATE SEQUENCE order_seq START WITH 1 INCREMENT BY 1;
INSERT INTO orders (id, customer) VALUES (NEXT VALUE FOR order_seq, 'Alice');
-- Or use IDENTITY instead of sequences
CREATE TABLE orders (
id INT IDENTITY(1,1) PRIMARY KEY,
customer NVARCHAR(100)
);
String Concatenation
-- Oracle
SELECT first_name || ' ' || last_name FROM employees;
-- SQL Server
SELECT first_name + ' ' + last_name FROM employees;
-- Or using CONCAT (NULL-safe):
SELECT CONCAT(first_name, ' ', last_name) FROM employees;
Data Type Mapping
| Oracle Type | SQL Server Type | Notes |
|---|---|---|
NUMBER(10) | INT or BIGINT | Based on precision |
NUMBER(10,2) | DECIMAL(10,2) | Same precision |
VARCHAR2(n) | NVARCHAR(n) | Unicode support |
CHAR(n) | NCHAR(n) | Fixed-length Unicode |
CLOB | NVARCHAR(MAX) | Up to 2GB |
BLOB | VARBINARY(MAX) | Binary data |
DATE | DATETIME2 | Oracle DATE includes time |
TIMESTAMP | DATETIME2(7) | Nanosecond precision |
BINARY_FLOAT | REAL | 4-byte float |
BINARY_DOUBLE | FLOAT | 8-byte float |
RAW(n) | VARBINARY(n) | Binary |
XMLTYPE | XML | Both have native XML |
Step-by-Step Migration Guide
- Use SSMA for Oracle. Microsoft's free SQL Server Migration Assistant for Oracle automates schema conversion, data type mapping, PL/SQL to T-SQL translation, and data migration. Download it from the Microsoft website.
- Convert the schema. Replace
VARCHAR2withNVARCHAR,NUMBERwithINT/DECIMAL,CLOBwithNVARCHAR(MAX), and OracleDATEwithDATETIME2. - Convert SQL queries. Replace
NVLwithISNULL,SYSDATEwithGETDATE(),ROWNUMwithTOP,||with+,DECODEwithCASE, and removeFROM DUAL. - Convert PL/SQL to T-SQL. Key changes: replace
DBMS_OUTPUT.PUT_LINEwithPRINT, Oracle cursors with T-SQL cursor syntax,EXCEPTION WHENwithTRY...CATCH, and Oracle packages with T-SQL stored procedures grouped in schemas. - Handle empty string behavior. Oracle treats empty string as NULL. SQL Server treats them as distinct. Review code that relies on this Oracle behavior and add explicit NULL checks.
- Test and validate. Run both systems in parallel and compare query results. Use SSMA's built-in comparison reports to identify discrepancies.
For SQL fundamentals, see What is SQL. For join syntax, see SQL Joins Explained.
Convert Automatically with AI2SQL
Paste your Oracle query into the SQL Converter tool and get correct T-SQL with ISNULL, GETDATE(), TOP, and proper data types automatically.
Try the converter free. See also: Oracle to PostgreSQL. Browse all converter tools.
Frequently Asked Questions
What is the SQL Server equivalent of Oracle NVL?
SQL Server uses ISNULL(a, b) as the equivalent of Oracle's NVL(a, b). Both return the second argument if the first is NULL. SQL Server also supports COALESCE which accepts multiple arguments and is SQL standard, working in both databases.
How do I convert Oracle ROWNUM to SQL Server?
Use TOP or OFFSET-FETCH. Oracle: SELECT * FROM employees WHERE ROWNUM <= 10. SQL Server: SELECT TOP 10 * FROM employees. For pagination, SQL Server 2012+ supports OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY. Both databases support ROW_NUMBER() OVER (ORDER BY col) for complex numbering.
Can I use SQL Server Migration Assistant for Oracle migration?
Yes. Microsoft provides SQL Server Migration Assistant (SSMA) for Oracle, a free tool that automates schema conversion, data type mapping, and data migration. It handles most PL/SQL to T-SQL conversion automatically and generates assessment reports showing potential issues.