Moving an application from Oracle to PostgreSQL does not mean every SQL statement will work correctly after the migration. Both databases support standard SQL, but they differ in several important areas, including built-in functions, date handling, null values, pagination, sequences, joins, and stored procedures.

An application may connect successfully to PostgreSQL and execute simple queries while still containing Oracle-specific SQL that fails only when a particular feature is used. These issues can remain hidden until a user executes a specific report, processes a transaction, or accesses an older application workflow.

This makes SQL compatibility checking an important step after moving an application to PostgreSQL. Developers need to identify the remaining Oracle-specific statements, understand their original behavior, replace incompatible syntax, and test the results against the new database.

Microsoft's Postgres Skills plugin provides an Oracle application assessment workflow that can help identify Oracle-specific SQL and other database dependencies in an existing application repository. Developers can use its assessment report to locate migration hotspots and review the changes required for Azure Database for PostgreSQL.

This article explains common Oracle SQL differences, practical replacement examples, and how to use migration assessment reports to find SQL that still needs attention.

Why Oracle SQL Needs Another Review After Migration

Oracle and PostgreSQL support many common SQL operations, but their implementations are not identical. A query that looks valid in Oracle may produce a syntax error or different results in PostgreSQL.

Consider an application that uses Oracle's NVL function:

Code
SELECT
    EMPLOYEE_ID,
    NVL(COMMISSION, 0) AS COMMISSION
FROM EMPLOYEES;

PostgreSQL does not provide the Oracle NVL function. The equivalent expression uses COALESCE:

Code
SELECT
    employee_id,
    COALESCE(commission, 0) AS commission
FROM employees;

This is a straightforward conversion, but not every SQL difference is this simple. Some statements require changes to their logic rather than replacing one function with another.

For example, Oracle treats an empty character string as NULL in many character contexts, while PostgreSQL treats an empty string and NULL as different values. A query that previously handled both conditions in the same way can return different results after migration.

Therefore, SQL compatibility testing should focus on both syntax and application behavior.

Common Oracle SQL Statements That Need Changes

The first step is to identify the Oracle-specific SQL patterns used by the application. The following examples cover several common migration areas.

Replacing NVL With COALESCE

Oracle uses NVL to return an alternative value when an expression is NULL.

Code
SELECT
    EMPLOYEE_NAME,
    NVL(SALARY, 0) AS SALARY
FROM EMPLOYEES;

In PostgreSQL, use COALESCE:

Code
SELECT
    employee_name,
    COALESCE(salary, 0) AS salary
FROM employees;

COALESCE returns the first non-NULL expression from its arguments. It supports more than two arguments, which makes it useful for handling multiple fallback values.

For example:

Code
SELECT
    COALESCE(MOBILE_NUMBER, OFFICE_NUMBER, 'Not Available')
        AS CONTACT_NUMBER
FROM EMPLOYEES;

When converting NVL expressions, check the data types of all arguments. PostgreSQL requires compatible types and may need an explicit cast when Oracle previously performed an implicit conversion.

Replacing DECODE With CASE

Oracle's DECODE function provides conditional value matching.

An Oracle query might look like this:

SQL
SELECT
    EMPLOYEE_ID,
    DECODE(
        STATUS,
        'A', 'Active',
        'I', 'Inactive',
        'Unknown'
    ) AS STATUS_NAME
FROM EMPLOYEES;

PostgreSQL supports the CASE expression for this purpose:

SQL
SELECT
    employee_id,
    CASE status
        WHEN 'A' THEN 'Active'
        WHEN 'I' THEN 'Inactive'
        ELSE 'Unknown'
    END AS status_name
FROM employees;

CASE is also useful when the original DECODE statement contains more complicated conditions.

One important detail is that Oracle DECODE has special NULL comparison behavior. When converting statements that compare NULL values, verify that the PostgreSQL CASE expression preserves the original result.

Replacing SYSDATE With PostgreSQL Date and Time Functions

Oracle uses SYSDATE to return the current date and time from the database server.

Code
SELECT SYSDATE FROM DUAL;

PostgreSQL provides several date and time functions:

Code
SELECT CURRENT_TIMESTAMP;

If the application only needs the current date, use:

Code
SELECT CURRENT_DATE;

These expressions are not interchangeable in every situation. PostgreSQL CURRENT_TIMESTAMP represents the transaction start time, while clock_timestamp() returns the actual current time when the function is called.

For example, an application that records the exact time of an individual event may need:

Code
INSERT INTO employee_audit
    (employee_id, changed_at)
VALUES
    (101, clock_timestamp());

Choose the function based on the application's timestamp requirements rather than replacing SYSDATE without reviewing its usage.

Removing DUAL From Queries

Oracle commonly uses the DUAL table to evaluate expressions that do not require application tables.

Code
SELECT
    SYSDATE,
    USER
FROM DUAL;

PostgreSQL does not require DUAL for this type of query.

The equivalent statement can be written as:

Code
SELECT
    CURRENT_TIMESTAMP,
    CURRENT_USER;

When migrating application queries, search for references to DUAL. Some statements can simply remove the table reference, while others may need additional changes to Oracle-specific functions used in the same query.

Replacing ROWNUM With LIMIT

Oracle applications often use ROWNUM to restrict the number of returned records.

Code
SELECT *
FROM EMPLOYEES
WHERE ROWNUM <= 10;

PostgreSQL supports LIMIT:

Code
SELECT *
FROM employees
LIMIT 10;

However, pagination requires additional care. Consider an Oracle query that sorts employees before limiting the result:

SQL
SELECT *
FROM (
    SELECT *
    FROM EMPLOYEES
    ORDER BY SALARY DESC
)
WHERE ROWNUM <= 10;

The PostgreSQL equivalent is:

Code
SELECT *
FROM employees
ORDER BY salary DESC
LIMIT 10;

Do not replace every ROWNUM condition with LIMIT mechanically. Oracle's ROWNUM is assigned during query processing, and its interaction with ordering and nested queries matters. Review the original query to understand whether it selects the first rows, ranks rows, or implements pagination.

Replacing Oracle Outer Join Syntax

Older Oracle applications may use the (+) operator for outer joins.

For example:

Code
SELECT
    E.EMPLOYEE_ID,
    D.DEPARTMENT_NAME
FROM EMPLOYEES E,
     DEPARTMENTS D
WHERE E.DEPARTMENT_ID = D.DEPARTMENT_ID(+);

PostgreSQL uses explicit JOIN syntax:

Code
SELECT
    e.employee_id,
    d.department_name
FROM employees e
LEFT JOIN departments d
    ON e.department_id = d.department_id;

Explicit joins make the relationship between tables easier to understand and maintain.

When converting complex queries, review every condition in the WHERE clause. Moving conditions between WHERE and ON can change the result of an outer join, especially when the condition refers to the optional table.

Replacing MINUS With EXCEPT

Oracle uses MINUS to return rows from one query that do not appear in another query.

Code
SELECT EMPLOYEE_ID
FROM CURRENT_EMPLOYEES

MINUS

SELECT EMPLOYEE_ID
FROM FORMER_EMPLOYEES;

PostgreSQL uses EXCEPT:

Code
SELECT employee_id
FROM current_employees

EXCEPT

SELECT employee_id
FROM former_employees;

Both operations remove duplicate rows by default. PostgreSQL also supports EXCEPT ALL when duplicate-preserving behavior is required. Check the original query's intended duplicate handling before selecting the replacement.

SQL Differences That Can Change Application Results

Syntax errors are usually easy to identify because PostgreSQL rejects the statement. More difficult problems occur when a converted query executes successfully but returns different results.

Empty Strings and NULL Values

Oracle treats a zero-length character string as NULL in ordinary character value handling. PostgreSQL distinguishes between an empty string and NULL.

For example, this PostgreSQL query checks only NULL values:

Code
SELECT *
FROM employees
WHERE middle_name IS NULL;

If the application considers both NULL and empty strings to mean a missing value, the condition needs to be:

Code
SELECT *
FROM employees
WHERE middle_name IS NULL
   OR middle_name = '';

Review inserts, updates, comparisons, and application validation rules that depend on empty strings. This difference can affect search results, reports, and business rules.

Date and Timestamp Differences

Oracle's DATE data type stores both date and time information. PostgreSQL's DATE type stores a calendar date without a time component.

If an Oracle DATE column contains timestamps, mapping it directly to PostgreSQL DATE can discard important information.

For example, a column storing an employee's last login time should generally use a PostgreSQL timestamp type rather than DATE.

Review the source column definitions and application requirements before selecting DATE, TIMESTAMP, or TIMESTAMPTZ.

Also check date formatting and conversion functions. Oracle's TO_DATE and TO_CHAR usage may need adjustment to match PostgreSQL function signatures and format patterns.

Sequence and Generated Identifier Syntax

Oracle applications may generate identifiers through sequences.

An Oracle query can use:

Code
SELECT EMPLOYEE_SEQ.NEXTVAL
FROM DUAL;

PostgreSQL supports nextval:

Code
SELECT nextval('employee_seq');

PostgreSQL also supports identity columns, which can simplify new table designs:

Code
CREATE TABLE employees (
    employee_id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    employee_name VARCHAR(150)
);

Before changing sequence usage, check how the application retrieves generated identifiers. The correct approach depends on whether the application uses a standalone sequence, an identity column, or an ORM-generated key.

Using Azure Migration Skills to Find Remaining Oracle SQL

Manual searches are useful, but a large application may contain SQL in source files, repository configuration, ORM mappings, and database access layers.

The migrate-oracle-application skill in Microsoft's Postgres Skills plugin can help assess these dependencies.

Open the application repository in Visual Studio Code, start a GitHub Copilot agent session, and verify that the skill is available.

Then run the assessment command:

Code
/migrate-oracle-application mode=assess codebase=. postgres-connection=my-profile database=my_database schema=app

Replace the example connection, database, and schema values with the actual destination details.

The assessment examines the application's database interactions and identifies Oracle-specific SQL, drivers, connection settings, ORM mappings, and routine calls. It also checks relevant destination objects when the PostgreSQL connection is available.

After the assessment, review:

Code
.github/migrate-oracle-app/assessment/assessment-report.md

Pay particular attention to the Migration Impact Assessment section. It identifies Oracle migration hotspots, affected application paths, and proposed conversion actions.

The assessment also records destination readiness and validation gaps. A finding marked Convertible does not mean the SQL has already been changed or validated.

The assessment is read-only by default. It does not automatically modify application source files.

After reviewing the findings, developers can authorize the conversion workflow separately. The conversion report and file-level differences help identify which Oracle dependencies were converted, retained, or deferred.

A Practical SQL Compatibility Review Process

A structured review makes it easier to find problems without introducing unnecessary changes.

  1. Search the repository for Oracle-specific functions and syntax, including NVL, DECODE, SYSDATE, ROWNUM, DUAL, CONNECT BY, and the legacy outer join operator.

  2. Group the findings by application module, database access layer, stored routine, and business function.

  3. Compare each SQL statement with the PostgreSQL destination schema and available routine definitions.

  4. Convert syntax while preserving the original query's behavior.

  5. Execute the converted SQL against a nonproduction PostgreSQL database.

  6. Compare the results with the Oracle application's expected output using representative test data.

  7. Run application integration tests and review performance for frequently executed queries.

For complex SQL, involve both Oracle and PostgreSQL developers. A query can be syntactically valid and still contain incorrect business logic after conversion.

Common Mistakes to Avoid

One common mistake is replacing Oracle functions without checking their behavior. NVL and COALESCE are similar, but implicit type conversion and NULL handling can produce differences.

Another mistake is treating every date column as a PostgreSQL DATE. Oracle DATE values can contain time information, so the destination type must preserve the original requirements.

Developers should also avoid changing all ROWNUM statements to LIMIT without reviewing ordering and pagination. The same applies to outer joins, where moving conditions can change which rows are returned.

Finally, do not consider a successful build as proof that all Oracle SQL has been removed. Some queries execute only when a specific application feature is used. Integration tests should cover important business workflows and database operations.

Summary

Checking Oracle SQL after moving an application to PostgreSQL is essential because database compatibility involves more than syntax. Functions such as NVL and DECODE, date and time expressions, ROWNUM, DUAL, legacy outer joins, and sequence operations may require changes.

Some differences, particularly empty-string handling and date storage, can also change application results even when the converted SQL executes successfully.

Microsoft's migrate-oracle-application skill can help locate Oracle-specific SQL and other database dependencies through an assessment report. Developers can use these findings to prioritize changes, review destination compatibility, and validate the converted application.

The safest approach is to assess first, convert in manageable groups, review every important SQL change, and compare application behavior against PostgreSQL before deployment.