IF – Query Oracle


Percabangan tidak hanya dapat dilakukan pada struktur data bahasa pemprograman saja, termasuk query sebagai salah satu ‘question to database’ sangat mungkin dilakukan. Contoh percabangan di query oracle dengan Case .. When .. Else … , sbb:

SELECT ACCOUNTING_DOC,
 CASE WHEN SUM(TOTAL_SEMEN_RUSAK)>SUM(KLAIM_LEBIH)
                     THEN (SUM(TOTAL_SEMEN_RUSAK)-SUM(KLAIM_LEBIH))
                     ELSE 0
                 END klaim_semen_v,
  CASE WHEN SUM(TOTAL_SEMEN_RUSAK)>SUM(KLAIM_LEBIH)
                     THEN SUM(TOTAL_KTG_REZAK)+(SUM(TOTAL_SEMEN_RUSAK)-SUM(KLAIM_LEBIH))
                     ELSE SUM(TOTAL_KTG_REZAK)
                 END klaim_all_v
 FROM EX_TRANS_HDR WHERE DELETE_MARK = '0' AND
 TGL_CLEARING BETWEEN TO_Date('01-03-2012', 'DD-MM-YYYY') AND TO_Date('31-03-2012', 'DD-MM-YYYY')
 GROUP BY ACCOUNTING_DOC

Semoga manfaat!😀

About blackphp

All about programming php, ajax, jquery, mysql, etc, tips n trick. Now, i'm concern in php programming with codeigniter framework n also training my design skill with photoshop or corel... wish me luck! ('o')

Posted on April 20, 2012, in Oracle and tagged , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: