Use of NVL, Is it correct or wrong

Hi,
I've doubt regarding the use of NVL in SQL query,
Eg.
for query :
SELECT *
FROM NBS_POLICY_MST
WHERE ORG_POLICY_ID = NVL(:p1,ORG_POLICY_ID);
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
| 0 | SELECT STATEMENT | | 2084 | 439K| 33 (4)|
| 1 | CONCATENATION | | | | |
| 2 | FILTER | | | | |
| 3 | TABLE ACCESS FULL | NBS_POLICY_MST | 2083 | 439K| 30 (4)|
| 4 | FILTER | | | | |
| 5 | TABLE ACCESS BY INDEX ROWID| NBS_POLICY_MST | 1 | 216 | 3 (0)|
| 6 | INDEX RANGE SCAN | IDXPT_NMP_TRAIL | 1 | | 2 (0)|
In above plan there is an FTS
but if I convert the query to
SELECT *
FROM NBS_POLICY_MST
WHERE POLICY_ID = :p1 or :p1 is null;
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
| 0 | SELECT STATEMENT | | 105 | 22680 | 29 (0)|
| 1 | TABLE ACCESS FULL| NBS_POLICY_MST | 105 | 22680 | 29 (0)|
the plan table output cost decreased little.
Can anyone help me in the above query which one is the best practice and why and
for the other one why it is consuming more memory
If possible provide a comprehensive description for my above doubt,
thanks in advance
regards/ goutam

SELECT  *
FROM    NBS_POLICY_MST
WHERE   ORG_POLICY_ID   = NVL(:p1,ORG_POLICY_ID);
PLAN_TABLE_OUTPUT
| Id  | Operation                     | Name            | Rows  | Bytes | Cost (%CPU)|
|   0 | SELECT STATEMENT              |                 |  2084 |   439K|    33   (4)|
|   1 |  CONCATENATION                |                 |       |       |            |
|   2 |   FILTER                      |                 |       |       |            |
|   3 |    TABLE ACCESS FULL          | NBS_POLICY_MST  |  2083 |   439K|    30   (4)|
|   4 |   FILTER                      |                 |       |       |            |
|   5 |    TABLE ACCESS BY INDEX ROWID| NBS_POLICY_MST  |     1 |   216 |     3   (0)|
|   6 |     INDEX RANGE SCAN          | IDXPT_NMP_TRAIL |     1 |       |     2   (0)|
--------------------------------------------------------------------------------------here the problem comes when org_policy_id is a nullable field. what if both org_policy_id is null and : p is null. It will not be matched.
Hence i guess oracle does perdicate like this.
(:p is null and org_policy_id is not null) or (:p is not null and org_policy_id = :p)
SELECT  *
FROM    NBS_POLICY_MST
WHERE   POLICY_ID   = :p1 or :p1 is null;
PLAN_TABLE_OUTPUT
| Id  | Operation         | Name           | Rows  | Bytes | Cost (%CPU)|
|   0 | SELECT STATEMENT  |                |   105 | 22680 |    29   (0)|
|   1 |  TABLE ACCESS FULL| NBS_POLICY_MST |   105 | 22680 |    29   (0)|
-------------------------------------------------------------------------I guess this is the correct way to do it and not NVL.

Similar Messages

  • I'm unable to correct a wrong url for my home page in Firefox

    I'm unable to correct a wrong url for my home page and have to manually use a separate bookmark that works once the home page loads. I use 3 url's total for the home page and the other 2 load properly.
    I've searched for the incorrect url and find it in 'about:config at browser.startup.homepage'. I've made the correction to the url but it does not seem to save when I close out of about:config.
    I've reset the home page under Tools and Options many, many times and it still doesn't change what is in
    'about:config at browser.startup.homepage
    I have been able to save the bookmark with the correct url in other folders.
    I've had this problem for quite awhile, at least 8 months or so and keep FF up to date, currently using V33.0.2 and Win7 Home Premium SP1

    I changed the pref.js file and that fixed the problem. thanks to those who responded to this question and for the quick replies. jjg18

  • I have just requested my ipod nano 1st generation to be replaced using the scheme, i have entered the wrong postcode on the shipping of the replacement box, will it still come to my address? or how can i change it?

    I have just requested my ipod nano 1st generation to be replaced using the scheme, i have entered the wrong postcode on the shipping of the replacement box, will it still come to my address? or how can i change it?

    Call up apple care,  (08000480408 if you are in the UK) and ask them to change the postcode and request another replacement packet

  • How to use Adobe Edge Web Fonts correctly

    I am a Dreamweaver newbie and am trying to learn how to use it through the tutorials. I am stuck at part 3 trying to use Adobe Edge Web Fonts correctly in my web site. As far as I can tell I have followed the instructions in the tutorial correctly, but the font style effect does not show up on my site. I am working on a Windows 7 machine and using Dreamweaver 5.5. I have copied and pasted the javascript into the correct spot in the head of the index.html page as well as included the font-family name in the CSS file and saved the whole smash. The source code for my index page looks exactly like the sample in the tutorial, and I have tried to view my site in my browser, but no dice. Doesn't display the Edge Web Font style in the web page. I believe I've done everything according to the directions, but I suppose I've missed some small detail. Any suggestions greatly appreciated

    You need to add a <script> to the head of your documents like the example below.  In my example, I'm using all of the aguafina-script and league-gothic fonts.
    <!--Edge Font-->
    <script src="//use.edgefonts.net/aguafina-script:n4:all;league-gothic:n4:all.js"></script>
    CSS:
         h1 {
         font-family: league-gothic, sans-serif;
         font-weight:bold;
         color: #639;
         font-size: 250%;
    A simple way to get the correct codes is to go to Adobe Edge Web Fonts and select the font you wish to use.
    https://edgewebfonts.adobe.com/fonts
    NOTE: You won't see the custom web fonts displayed in Design View, Live View or when previewed locally unless you use a local testing server.  An easier way to test is by uploading the page to your remote server.
    Hope this helps,
    Nancy O.

  • XML page cannot be displayed cannot view XML input using XSL style sheet Please correct the error and then click the REfresh

    XML page cannot be displayed cannot view XML input using XSL style sheet Please correct the error and then click the REfresh

    Is the error message displayed in Firefox or in IE, or in a customized window that doesn't identify the browser?
    ''If it displays in Firefox:''
    It's possible that the Troubleshooter doesn't work correctly unless IE is your default browser. You could test that possibility by having IE make itself the default and testing the Troubleshooter again.
    ''If it displays in IE or embedded in another Microsoft application:''
    In a web search I found these suggestions:
    (1) Reset your Internet Explorer settings, according to http://answers.microsoft.com/en-us/ie/forum/ie8-windows_7/cannot-view-xml-using-xsl-style-sheet/ccfe80c6-c0db-4594-a7e3-475f9eac0e85
    (2) Try the System File Checker, according to http://ask-leo.com/why_do_i_get_the_xml_page_cannot_be_displayed_after_running_a_microsoft_troubleshooter.html
    Any luck?

  • I installed bootcamp but became a pain to use so I unistalled it. Now every time I turn my Macbook pro on it keeps asking me what startup disk to use. I tried using the system preferences to correct this but it hasn't worked. Can someone help

    I installed bootcamp but became a pain to use so I unistalled it. Now every time I turn my Macbook pro on it keeps asking me what startup disk to use. I tried using the system preferences to correct this but it hasn't worked. I even restored my mac back to factory settings but it still asks me what startup disk to use. I have looked everywhere for a solution but one anywhere

    Delete the System Preference .plist file (preference file) and when rebooting and #2 Reset the PRAM
    Deleting the System Preference or other .plist file
    ..Step by Step to fix your Mac
    Then head to System Preferences > Startup Disk and select the OS X volume to boot from.

  • HT3275 Time Machine Error: The backup disk image "Volumes/Data/My Macbook Pro.sparsebundle" is already in use. (How do I correct this issue?)

    Time Machine did not back up:
    Time Machine Error; ("The backup disk image "/Volumes/Data/My MacBook Pro.sparsebundle" is already in use.")
    How do I correct this issue?
    Thanks!

    You need to be careful Bob.. people might take this literally.
    Bob Timmons wrote:
    How do I correct this issue?
    Call the exterminator to get rid of the bugs in Lion and Mountain Lion.
    https://discussions.apple.com/thread/5222487?tstart=0

  • My iPhoto icon has a cross over it, when i open it, it You have "iPhoto" 9.2.1. you can't use this with this version of OSX? it used to work ?what's gone wrong?

    my iPhoto icon has a cross over it, when i open it, it You have “iPhoto” 9.2.1. you can't use this with this version of OSX? it used to work ?what's gone wrong?

    iPhoto 9.2.3 is incompatible with MacOS 10.9.3 Mavericks. If you are running Mavericks on your system you need to update iPhoto to 9.5.1. Only, the problem is, that this version is no longer available at the App Store.
    The easiest way to get a compatible iPhoto version in that case would be to upgrade to Yosemite, MacOS X 10.10, and then download the most recent iPhoto version from the AppStore, iiPhoto 9.6, like LarryHN suggested.
    If you cannot download iPhoto after upgrading to iPhoto 9.6 post back.

  • I keep getting prompts to update my Firefox to 4.0.1 but I already use 4.0.1. What's wrong with Firefox that it keeps sending these?

    I keep getting prompts to update my Firefox to 4.0.1 but I already use 4.0.1. What's wrong with Firefox that it keeps sending these prompts and what can I do to stop them?

    I keep getting prompts to update my Firefox to 4.0.1 but I already use 4.0.1. What's wrong with Firefox that it keeps sending these prompts and what can I do to stop them?

  • Why does Apple TV sons using in dorm keep saying password is wrong when the home Apple TV uses same password with no problem

    MY son is away at school and the Apple TV I got him to use keeps telling him his password is wrong.  This is the same password we use on the home Apple TV and he wants to be able use the movies, shows etc that have been purchased from this Apple ID.  Please help

    Most school's require a login to use the network, and the Apple TV has no browser to accomplish this task. It is likely not connected to the network, which is causing the error. Best to speak to the IT dept

  • Hello, i am using iphone 4. I made the wrong purchase for ipad.navturk live navigation i bought. just trying to do update. I would ask you to cancel the order. best regards.

    Hello, i am using iphone 4. I made the wrong purchase for ipad.navturk live navigation i bought. just trying to do update. I would ask you to cancel the order.
    best regards.

    There is no one here from Apple or iTunes support. You need to contact iTunes support here:
    http://www.apple.com/support/itunes/contact.html

  • Finding text in a PDF using preview has stopped working (correctly)

    Finding text in a PDF using preview has stopped working (correctly).
    When I search for certain words in a PDF using preview, it correctly finds all the pages in the document with that word.  However, it no longer highlights the word being searched for.  I have looked through the various settings and cannot figure out how to turn this back on.
    Thanks.

    4Shared worked, but having to register to retrieve files from there is a nuisance.
    The problem is that you use special graphic state operators inside text objects which is not allowed:
    BT
    /printmatic_F1 58.133398014634 Tf
    q
    /DeviceCMYK CS
    1 1 1 1 SCN
    /DeviceCMYK cs
    1 1 1 1 scn
    0.62060289801053 w
    0 J
    0 j
    2.189349112426 M
    0 Tr
    /printmatic_F1 58.133398014634 Tf
    1 0 0 1 86.448306387737 264.65046258267 cm
    (t) Tj
    Q
    q
    /DeviceCMYK CS
    1 1 1 1 SCN
    /DeviceCMYK cs
    1 1 1 1 scn
    0.62060289801053 w
    0 J
    0 j
    2.189349112426 M
    0 Tr
    /printmatic_F1 58.133398014634 Tf
    1 0 0 1 102.60939103581 264.65046258267 cm
    (e) Tj
    Q
    q
    /DeviceCMYK CS
    1 1 1 1 SCN
    /DeviceCMYK cs
    1 1 1 1 scn
    0.62060289801053 w
    0 J
    0 j
    2.189349112426 M
    0 Tr
    /printmatic_F1 58.133398014634 Tf
    1 0 0 1 134.93156033194 264.65046258267 cm
    (x) Tj
    Q
    q
    /DeviceCMYK CS
    1 1 1 1 SCN
    /DeviceCMYK cs
    1 1 1 1 scn
    0.62060289801053 w
    0 J
    0 j
    2.189349112426 M
    0 Tr
    /printmatic_F1 58.133398014634 Tf
    1 0 0 1 163.99825933926 264.65046258267 cm
    (t) Tj
    Q
    ET
    Have a look at the PDF specification ISO 32000-1:2008 (e.g. at http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf). Table 51 shows that q, Q, and cm are special graphics state operators, and Figure 9 illustrates that these operators, therefore, are not allowed in text objects, i.e. between BT and ET.

  • Devanagari font in layed out in Indesign (using IndicPlus) does not export correctly to a PDF.

    Namaste InDesign gurus,
          I have a problem at hand. Wondering if anyone has encoutered similar problem before? Any help is greatly appreciated. And if you're in San Francisco bay area - I can buy you a lunch :-)
    Short description: Devanagari font in layed out in Indesign (using IndicPlus) does not export correctly to a PDF. All the ligatures are assembled and displayed in the PDF.
    Adobe Indesign Version: InDesign CS5 Design Premium - regular U.S. version (not ME).
    Steps I took:
              I purchased CS5 Design Premium and also purchased the IndicPlus plugin to author sanskrit documents in InDesign. I create Sanskrit text using either of the following methods.
    1) Itranslator
    2) Paste the devanagari from the Itranslator directly into InDesign or paste it first into MSWord and then copy from MSWord and paste it to Indesign.
    It doesn't matter how I paste it. After I apply the IndicPlus character/paragraph style so that the sanskrit looks good in InDesign, when I try to export it to a PDF. The PDF does not display the ligatures currectly. It just lists all the characters in order without assembling.
    I've spent a lot of money buying CS5, IndicPlus and then I can't even create a simple PDF document from InDesign. It is very frustrating.
    Has anyone been able to successfully export a sanscrit document from InDesign PDF ?
    (Please let me know if my problem description needs more fleshing out).
    I could create the PDF from MSWord directly but I'm trying to use indesign to layout my book. If InDesign cannot export to PDF I'll just have to use MSWord for my book layout. I've spend probably scores of hours trying to learn InDeisn and formatting my book content - seems like it is all going to be waste.
    Is MSWord the best choice or only choice for laying out books that have sanskrit text in them?
    -Ravi

    Has anyone been able to successfully export a sanscrit document from InDesign PDF ?
    Not Sanskrit, no, but plenty of Hindi, Nepali, Marathi, and other languages written in Devanagari script - so it should be possible. I don't even use IndicPlus, which by most accounts makes working with Indic text much easier.
    1) Itranslator
    I've never seen this, but a quick Google led me to the homepage of ITranslator for Windows, where I saw this:
    Itranslator 99 (Build 1.3.0.86)  & New Beta Version
    uses 8-bit true type fonts and is compatible
    with Windows 95/98/ME/NT/2000/XP.
    For more information, click here.
    Itranslator 2003 (Build 2.0.0.38) & New Beta Version
    uses 16-bit Unicode-compatible fonts and is working
    only on Windows 2000 / XP / Server 2003.
    For more information, click here.
    So, if you're using ITranslator 99, there's the problem - those "8-bit true type fonts" won't work in InDesign. Can you post a sample of the text you're trying to paste into InDesign? Name the font(s) you are using, both in Word and in Indesign, and if possible make a small sample of the text available for us to test. It's also possible that InDesign is using a substituted font, which could cause this problem. So, if the font name in InDesign has brackets around it, you know that InDesign doesn't actually have that font installed and is auto-substituting. Also, if you go to View -> Screen Mode -> Normal and the text is highlighted pink, you know that the font has dropped. (Unless the highlighting for dropped fonts was turned off - check in Edit -> Preferences -> Composition and make sure that "Substituted Fonts" is checked.
    Also, for what it's worth, is there any way you could Place your text instead of copying and pasting? This may be cause of your problem - but even though it probably isn't, it's still worth a try.
    Lastly - no, I've found InDesign to be superior for typesetting for almost all languages, but the learning curve is pretty steep, and many of the problems faced by people working in non-English languages are not easy to research when you have a problem.

  • Hello , im working with hebrew and the dot  "." isnt correcting to right with the align , i know that in indesign u use with paragraph direction to correct it but here what should i do. sorry for my english

    hello , im working with hebrew and the dot  "." isnt correcting to right with the align , i know that in indesign u use with paragraph direction to correct it but here what should i do. sorry for my english

    You are right, but how could i send it to Apple? when the phone company first replaced my iphone they had in stock alots of iphones and they just sent mine back to Apple and gave me a new one, so all i did is to give them my phone, but now how could i sent it to Apple? and i cant send it by myself, and the store wont do that, its a lost for them.. so sending it to Apple wasnt an option from the begining.
    and for the record, i dont think the store where i bought it is an authorized shop.. its just a store who boughts phone's from Apple in a low price and sells it in much more money..

  • What does this odd use of NVL in a comparison do?

    The TOAD query optimizer recommended changing this test:
    (NOT (sites.pay_site_flag = 'N' AND sites.purchasing_site_flag = 'Y'))
    to this:
    (sites.pay_site_flag &lt;&gt; NVL ('N', UID) OR sites.purchasing_sige_flag &lt;&gt; 'Y')
    both sites.pay_site_flag and sites.purchasing_site_flag allow nulls, so the logical contrapositive is not valid.
    Testing seems to show that the query optimizer test returns the same result as the original test, but why? I don't understand how NVL ('N', UID) can ever evaluate to anything but 'N', and how can that be useful in this comparison?
    Edited by: Pete Hall on May 6, 2012 10:32 AM
    Edited by: Pete Hall on May 6, 2012 11:12 AM
    Edited by: Pete Hall on May 6, 2012 11:13 AM

    >
    That's true, and I did construct the truth table. It's equally true, if I substitute a literal 'N' in place of NVL ('N', UID), so what subtle difference does it make if the NVL function is used instead of the literal 'N'? I suppose it's possible that the TOAD optimizer just pulled that out of the air for no reason, but it seems unlikely.
    >
    For this example the use of NVL appears to be unnecessary. Can't tell for certain since the example that uses NVL also uses 'UID' which isn't explained anywhere; where did TOAD come up with 'UID'?
    The most likely explanation is that the template that TOAD uses includes NVL to handle cases where the NVL actually is necessary. And for cases where NVL isn't needed, and doesn't alter the results, it doesn't matter if it is left in. That could allow TOAD to use one template for all use cases rather than add code to determine the use cases where NVL isn't needed.
    Note that your original example
    (NOT (sites.pay_site_flag = 'N' AND sites.purchasing_site_flag = 'Y'))is often misinterpreted as meaning the NEGATION of the inner AND condition but testing will show that it is not. You should always use a truth table and full testing to make sure you get exactly what you want.
    Since there are two variables and they can each have three values there are nine possible combinations
    with q as (SELECT 1 TEST, 'N' PFLAG, 'Y' SFLAG FROM DUAL
               UNION ALL
               SELECT 2 TEST, 'Y' PFLAG, 'Y' SFLAG FROM DUAL
               UNION ALL
               SELECT 3 TEST, NULL PFLAG, 'Y' SFLAG FROM DUAL
               UNION ALL
               SELECT 4 TEST, 'N' PFLAG, 'N' SFLAG FROM DUAL
               UNION ALL
               SELECT 5 TEST, 'Y' PFLAG, 'N' SFLAG FROM DUAL
               UNION ALL
               SELECT 6 TEST, NULL PFLAG, 'N' SFLAG FROM DUAL
               UNION ALL
               SELECT 7 TEST, 'N' PFLAG, NULL SFLAG FROM DUAL
               UNION ALL
               SELECT 8 TEST, 'Y' PFLAG, NULL SFLAG FROM DUAL
               UNION ALL
               SELECT 9 TEST, NULL PFLAG, NULL SFLAG FROM DUAL
    SELECT * FROM Q WHERE
       (NOT (PFLAG = 'N' AND SFLAG = 'Y'))
    TEST,PFLAG,SFLAG
    2,Y,Y
    4,N,N
    5,Y,N
    6,,N
    8,Y,
                  The inner AND condition
       (PFLAG = 'N' AND SFLAG = 'Y')is TEST #1 of 9 possible combinations.
    It is natural to think that if you negate that with the NOT condition that you should get records that correspond to the other 8 conditions.
    But if you look at the above results you can see that you only get results matching tests 2, 4, 5, 6 and 8.
    Those DO NOT include tests 3 (PFLAG IS NULL and SFLAG = 'Y'), 7 (PFLAG = 'N' but SFLAG IS NULL) or 9 (both flags are NULL).
    That is the way NULLs can affect things.
    If you really need the NEGATION of the inner AND condition you need to specifically code for the null value combinations.
    to mean 'include all records with pay_site_flag IN (null, 'Y') OR purchasing_site_flag IN (null, 'N') but that is NOT what your condition does.
    The example provides
    If you did the truth table and testing

Maybe you are looking for

  • Customer Coversion Using Interface Table - Error during update

    I need to import customers from legacy applicatiion and is planning to use standard customer interface for that. For testing, I am able to create customers with hardcoded values. But while I try to update the same customer record (again using hard co

  • Oracle 8.1.5  - Where is libclntsh.so.8.0 ?

    I just installed Oracle 8.1.5 (MacMillan edition) on RedHat Linux 7.1. When I attempted to run SQL*Plus, the dynamic linker returned an error because it couldn't find the runtime library "libclntsh.so.8.0". I checked in $ORACLE_HOME/lib and sure enou

  • Need JDeveloper Exact Version for 11.5.9

    Hi All, I would like to develop the new pages by using OA Framework. To develop the page in 11.5.9 version what is the exact compatible JDeveloper version? See below for my OAInfo details.... OA Framework Version --> 5.7.H.V6 MDS Version --> 9.0.3.6.

  • Total of calculated fields

    In a page-detail table report, there are several numeric fields which must be totalled at the end of the report. Some of the fields are calculated ones, i.e. a dollar amount multiplied by a conversion rate. The total of the calculated fields are alwa

  • Download To Excel in Web BEx.

    Hello, As per requirement, I have built one BW report on Web, which encapsulates 3 sub reports i.e. I am displaying 3 reports on the same page. As the 3 reports have sources from different cubes, I am not able to provide the "Download To Excel" capab