Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Decode and NVL

Posted on 2014-07-18
3
Medium Priority
?
310 Views
Last Modified: 2014-07-21
Hello,

Please assist with understanding the statement below. I understand for example NVL(PE.PAID,0) is stating if pe.paid is null place a zero.

where
 (NVL(DECODE(NVL(PE.OKTOBILL,0),1,DECODE(TO_CHAR(PE.HICFIRST,'YYYY'),'0000', 0, NVL(PE.BILLED,0)),0),0) - NVL(PE.WRITTENOFF,0) - NVL(PE.PAID,0)) >0

Thank you for the help.
0
Comment
Question by:jverasql
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 500 total points
ID: 40205056
decode goes like this:
decode(this_value,when_a,return_a,when_b,return_b,else_return_this)


Break it down and indent it to take each piece individually:
 
 (
 	NVL(
 		DECODE(
			--if the nvl on oktobill = 1 then return the value of the decode
 			NVL(PE.OKTOBILL,0),1,
 			DECODE(
				--If the YYYY = '0000' return 0
 				TO_CHAR(PE.HICFIRST,'YYYY'),'0000', 0,
				--else return this
 				NVL(PE.BILLED,0)
 			),0
 		),0
 	)
 	-
 	NVL(PE.WRITTENOFF,0) - NVL(PE.PAID,0)
 ) >0

Open in new window

0
 
LVL 1

Assisted Solution

by:Pooja Katiyar Verma
Pooja Katiyar Verma earned 500 total points
ID: 40205423
It will return PE.OKTOBILL 0 if it's data value is null or any other value apart from 1, If it is 1 then it will compare value of PE.HICFIRST in second decode used-  if year part i.e. to_Char(HICFIRST,'YYYY') is '0000' it will return 0, if not then it will compare PE.BILLED with PE.HICFIRST if PE.BILLED is null or value of both columns matches it will return 0.

The result of above value return is then compared in where clause: whether it is greater then 0 or not
0
 
LVL 49

Accepted Solution

by:
PortletPaul earned 1000 total points
ID: 40206877
perhaps as case expressions will help?
WHERE (
       NVL(
            CASE
                  WHEN NVL(PE.OKTOBILL, 0) = 1 THEN
                        CASE
                              WHEN TO_CHAR(PE.HICFIRST, 'YYYY') = '0000' THEN 0
                              ELSE NVL(PE.BILLED, 0) 
                        END
                  ELSE 0 
            END
        , 0)
      - NVL(PE.WRITTENOFF, 0) - NVL(PE.PAID, 0)
      ) > 0

Open in new window

0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question