You are on page 1of 1

Exhibit 3 Outer JOIN and Decode Example

8/13/15, 8:49 PM

Exhibit 3 Outer JOIN and Decode Example


Category: PL/SQL Translation Tool
Published Date

Oracle Outer Join (+) and DECODE example

select acc.id, decode( type, 'C', amount, 0 ) acc_credit, decode( type, 'D', amount, 0 ) acc_debit,
nvl(cust.lastName, '--') cust_lastName,
nvl(pri.cust_priority, 'unknown') pri_priority
from (select id, type, amount, transaction_date from accounts order by id) acc, customers cust, prio
where acc.id = cust.id(+)
and cust.id = pri.id(+)
and acc.transaction_date > SYSDATE - 1000
and rownum < 2
order by acc.id
;

Postgres as translated by magicHat


-- magicHat translation v2.1 July 30, 2014
SELECT acc.id,
CASE WHEN type = 'C' THEN amount ELSE 0 END acc_credit,
CASE WHEN type = 'D' THEN amount ELSE 0 END acc_debit,
coalesce(cust.lastName, '--') cust_lastName,
coalesce(pri.cust_priority, 'unknown') pri_priority
FROM
( SELECT id , type , amount , transaction_date FROM accounts ORDER BY id ) acc LEFT OUTER
ON acc.id = cust.id
LEFT OUTER JOIN priority pri
ON cust.id = pri.id
WHERE
acc.transaction_date > clock_timestamp() - (1000 || ' D')::interval
ORDER BY acc.id
LIMIT 1;

http://postgresmigrations.com/database-migration/stored-procedurbit-3-outer-join-and-decode-example?tmpl=component&print=1&page=

Page 1 of 1

You might also like