How to switch OR logic in DECODE function?

There is somewhere in my PL/SQL code as embedded in other SQL code. SELECT SUM (DECODE(COL1,'AB',COL2,'AC',COL2,'AD',COL2,'AF',COL2)) FROM DUAL you can see if COL1 is AB, AC, AD, or AF it returns COL2. I was worrying if it takes more execution time. Is there a better way to do this. We can pass the OR logical operator in DECODING so that all objects to check can be passed at any given time? I'm on Oracle 10 g.

I'd not concerned that such internal function has a performance impact unless you have encountered a specific situation and have evidence to support.

As others have shown, the other option to DECODE (which is specific Oracle) is to use the CASE (which is ANSI standard), and the CASE is also more flexible in terms of test conditions.

Performance wise, however, there is little difference between the two.

Tags: Database

Similar Questions

  • Logical operations in SQL decode function?

    Hello
    Is it possible to perform logical operations in SQL decode function

    as
    ' > '
    ' < '
    ' > ='
    ' < ='
    '<>'.
    not in
    in
    non-null
    a null value

    for example...

    Select col1, order_by, decode (col1, > 10, 0, 1)
    tab;

    Select col1, order_by, decode (col1, <>0, 10, 1)
    tab;

    Select col1, order_by, decode (col1, not in (10,11,12), 0, 1)
    tab;

    Select col1, order_by, decode (col1, is set to null, 0, 1).
    tab;




    Kind regards

    infantry

    Published by: user780731 on April 30, 2009 12:07 AM

    Published by: user780731 on April 30, 2009 12:07 AM

    Published by: user780731 on April 30, 2009 12:08 AM

    Published by: user780731 on April 30, 2009 12:08 AM

    Published by: user780731 on April 30, 2009 12:09 AM

    example:

    select col1 ,order_by,case when col1 > 10 then 0 else 1 end
    from tab;
    
    select col1 ,order_by,case when col1 <> 10 then 0 else 1 end
    from tab;
    
    select col1 ,order_by,case when col1 not in (10,11,12) then 0 else 1 end
    from tab;
    

    Regarding testing for null, decode the handles which, by default, anyway, so that you can get decode or case easily...

    select col1 ,order_by,decode (col1, null , 0 , 1)
    from tab;
    
    select col1 ,order_by,case when col1 is null then 0 else 1 end
    from tab;
    
  • How to switch between two keyboards (Japanese keyboards have the double function of "direct entry"

    I have a laptop with keys 'English' and 'Japanese' on the same key board.  For example "A" key is also 'CHI' in Japanese, 'B' is also "KO" in Japanese.  How to switch between the two.  It changes itself.  This seems to happen after the mail in Hotmail changed in Outlook.

    Thank you

    Tomoko

    Hello

    Please go to the Microsoft Community Forums.

    From the description of the question, we understand that you want to switch between two keyboards entries.

    Let me go ahead and help you with the issue.

    Here are some steps you can follow to resolve the problem:

    Step 1:

    To change the default language, follow these steps:

    a. Click Start and then click Control Panel.
    b. double-click regional and Language Options.
    c. click on the languages tab, click details and then click Add.
    d. under input language, add the language that you want to use.
    e. under Configuration keyboard/IME, click the keyboard layout that you want, and then click OK.
    Note: Only users who have permissions on the local computer can configure the following options on the languages tab in the regional and Language Options.

    Step 2:

    To resolve this problem, change the hot key settings in your computer system. To do this, follow these steps:

    a. right click on the language bar and then click settings.
    b. in the Text Services and input languages window, click the Advanced Settings button select an action and then click Change Key Sequence.
    c. set keys and then save the settings.

    Hope that answers your query. You can write back to us for other queries/problems related to windows and we will be happy to help you further.

  • I no longer get suggested words when composing a message text on my iphone 5.  How to get back to get this function works

    I no longer get suggested words when composing a message text on my iphone 5.  How to get back to get this function works

    Make sure that the text is on. You can do this on the keyboard (if you have several) by pressing and holding down the button to change between them.

    Alternatively you can go to settings > general > keyboard and make sure predictive is turned on (the switch must be green).

    If you see the image below, press the small white bar above the buttons T and Y and slide upward slightly.

  • Decode function in the Update statement

    Hi all

    I'm writing a query where I can update a pastdue_fees column in a table of book_trans based on a difference between the return_dte and due_dte columns.

    I use Oracle SQL. That's what I have so far for my decoding function:

    SQL > SELECT
    2 DECODE (SIGN ((return_dte-due_dte) * 2),)
    3 '-1 ', ' 0',
    4 '1', '12', 'Null')
    5 FROM book_trans;

    DECO
    ----
    Null value
    12
    Null value
    0

    If the logic is that, if the sign is - 1, the value in the return_dte column must be 0; If it is + 1, then it has 12 and everything else is Null.

    So now, I have to conclude my function of decoding of the update statement to update the columns. However, I get the error messages.

    The logic should be:
    UPDATE book_trans SET PastDue_fees = decode (expression)

    I gave him a few different tests with the following results:

    SQL > UPDATE book_trans
    2 SET pastdue_fees = SELECT
    3 DECODE (SIGN ((return_dte-due_dte) * 2),)
    4 '-1 ', ' 0',
    5 '1', '12', 'Null')
    6 FROM book_trans.
    SET pastdue_fees = SELECT
    *
    ERROR on line 2:
    ORA-00936: lack of expression


    SQL > UPDATE book_trans
    2 SET pastdue_fees =
    3 DECODE (SIGN ((return_dte-due_dte) * 2),)
    4 '-1 ', ' 0',
    5 '1', '12', 'Null')
    6 FROM book_trans.
    OF book_trans
    *
    ERROR on line 6:
    ORA-00933: SQL not correctly completed command.

    Any help or advice would be greatly appreciated I got SQL for about six weeks and not very competent!

    Thank you!

    882300 wrote:
    Hi all

    I'm writing a query where I can update a pastdue_fees column in a table of book_trans based on a difference between the return_dte and due_dte columns.

    I use Oracle SQL. That's what I have so far for my decoding function:

    SQL > SELECT
    2 DECODE (SIGN ((return_dte-due_dte) * 2),)
    3 '-1 ', ' 0',
    4 '1', '12', 'Null')
    5 FROM book_trans;

    DECO
    ----
    Null value
    12
    Null value
    0

    If the logic is that, if the sign is - 1, the value in the return_dte column must be 0; If it is + 1, then it has 12 and everything else is Null.

    So now, I have to conclude my function of decoding of the update statement to update the columns. However, I get the error messages.

    The logic should be:
    UPDATE book_trans SET PastDue_fees = decode (expression)

    I gave him a few different tests with the following results:

    SQL > UPDATE book_trans
    2 SET pastdue_fees = SELECT
    3 DECODE (SIGN ((return_dte-due_dte) * 2),)
    4 '-1 ', ' 0',
    5 '1', '12', 'Null')
    6 FROM book_trans.
    SET pastdue_fees = SELECT
    *
    ERROR on line 2:
    ORA-00936: lack of expression

    SQL > UPDATE book_trans
    2 SET pastdue_fees =
    3 DECODE (SIGN ((return_dte-due_dte) * 2),)
    4 '-1 ', ' 0',
    5 '1', '12', 'Null')
    6 FROM book_trans.
    OF book_trans
    *
    ERROR on line 6:
    ORA-00933: SQL not correctly completed command.

    Any help or advice would be greatly appreciated I got SQL for about six weeks and not very competent!

    Thank you!

    If you really really really want to update the entire table, the syntax would be...

    UPDATE book_trans
       SET
          pastdue_fees  = DECODE(SIGN((return_dte - due_dte)*2), -1, 0, 1, 12, Null);
    

    I took out all the single quotes. If you actually have a string column and store all numbers in there so it must be reported as a NUMBER column and not a column of type character (varchar2).

    ALWAYS use the appropriate data type, it will save you a ton of headaches in the future.

    Also, since you are new to the forum, please read the FAQ to learn etiquette and what not.

    http://wikis.Sun.com/display/Forums/Forums+FAQ

  • How to switch to safari 9.1 without internet connection

    I've recently upgraded to El Capitan on my 2009 mac. Fine, except that now, I find my version of safari (6.6) is not compatible with El Capitan and I have no internet connection. How to switch to safari 9.1 without being able to download it? Can I get a disk with on or something?

    Safari is upgraded when you upgrade your system. There is no installer for stand-alone for Safari. If you run El Capitan your Safari should be version 9.1.2. Otherwise apply the OS X Combo Update 10.11.6.

    The Combo update is a complete installation, as opposed to an incremental "delta" update, so you have to overwrite all files are damaged or missing. It does not matter if you have previously applied. All your data and settings must be kept, but that said, you should always have a backup.

    https://support.Apple.com/downloads/MacOS

  • In number. How do I lock you in a function such as highlighting a cell so it does not disappear when you move to another cell.

    In number. How can I lock you in a function such as highlighting a cell so that it does not disappear when you move to another cell.

    Hi Philil,

    Do you mean pointing out the contents of a cell, or "stressing" the cell itself (by placing an on bottom border)?

    Formatting content will transfer to another cell if you fill in the other cell content, or copy from a single cell and pasting it into another.

    Borders applied to a cell or group of cells may be applied to another cell or group of cells by selecting the first cell (single click), the format of this cell or a group of cells copy (Format (menu) or option + command + C > copy Style), and then selecting one or more other cells and stick to the format (Format (menu) or command-option-v > paste Style.)

    'Format' in the case of cells includes the color fill, color text and other text attributes, content, format (text, number, date & time, duration...), borders...

    When you copy the style, all format attributes are copied.

    Kind regards

    Barry

  • How not to use the squint no functionality?

    I forgot how not to use the squint no functionality. Can anyone help?

    18.0 Firefox was released last Tuesday, you need to update.

    See if this FAQ for NoSquint answers your questions.

    https://urandom.ca/NoSquint/#FAQ

  • How to switch to Firefox 7 after installing Firefox 8?

    IAM having problems with access to ancestry.com.au since I installed Firefox 8. I checked with the ancestors, and they said that they are not configured to work with Firefox 8. They work well with Firefox 7. How to switch to Firefox 7. I'm very tired of having to enter all the ID and password everywhere wherever I'm going while navigation or go to my accounts. I'm too frustrated to continue with Firefox 8. Please give me simple instructions on how to return to Firefox 7.

    You can get Firefox here 7

  • How to switch between Intel and ATI GPU on Satellite L50 - B

    Hello

    I bought a L50 - B - 1LR PSKTAE Satellite.
    Is there a graphics card Intel on the motherboard, but also a second for better 3D AMD Radeon.
    Now, I plugged on a second screen on the HDMI output, but still using the Intel graphics card.
    How can I change this?

    I made a button in the radeon software which says that when I start the sketchup program that he would take the graphics card from AMD. But it's still the Intel graphics adapter.

    Thank you

    Bart Slosse

    {quote} How can I change this? {quote}

    You can configure the unique application of each graphics chip.
    Please check this thread how to switch to external ATI GPU
    http://forums.computers.Toshiba-Europe.com/forums/thread.jspa?threadID=78781

    Some nice youtube videos also show detailed step by step instructions how to:
    https://www.YouTube.com/watch?v=DCh9Eob0mNY

  • How to install the compatible DVD decoder on Equium M50?

    My laptop is model Equium M50-164 PSM57E-002004AV

    After format, I lost DVD decoder.
    How can I install compatible DVD decoder?

    Can you please explain how you mean exactly and what OS do you have?
    You have reinstalled Windows using the Toshiba Recovery disk?

    Normally, you can play DVDs with Windows media player and so you n t need additional software or driver.
    Also, I prefer VLC media player. This little player can play audio and video files more and its freeware.

    If you need a codec pack that you should search with Google K-Lite Mega Codec Pack. It is very good ;)

    Good luck!

  • Switch from Logic 9 to new iMac

    I plan to buy a new iMac and I have Logic 9 on my old iMac and want as well on the new. I have the Logic 9 discs and the activation code. Can I install Logic 9 on the new iMac? I can run on both computers, or only one? If it is absolutely necessary, I do not fear the uninstall of the old, but I would have it on both. I didn't want to re-buy Logic 9.

    Additional question: if I end up buying logic X, is compatible with loops and Logic 9 files? How to import sounds Logic 9 in Logic X?

    Hello

    johnreidsteenkamp wrote:

    Can I install Logic 9 on the new iMac?

    Yes, but you will need to factor in the new iMacs is not an optical drive. You can connect the 2 Macs and use the Remote Disc feature

    Use the CD or DVD drive from another computer with your Mac - Apple Support

    Or you could make the installers disk images and copy the images.

    A new Mac is likely to have an OS El Capitan on it, so you must update LP9 to the latest version (9.1.8) immediately after installation.

    If I remember correctly, there are two different versions of the installation discs: there may be problems with the earlier mark of 2?

    johnreidsteenkamp wrote:

    Can I run it on computers or just one?

    Both.

    johnreidsteenkamp wrote:

    Additional question: if I end up buying logic X, is compatible with loops and Logic 9 files? How to import sounds Logic 9 in Logic X?

    LPX is generally compatible with the files LP9. If you install the legacy and compatibility content of LPX, you should have all the material provided with LP9.

    Note additional applications provided with LP9:

    WaveBurner (discontinued)

    Soundtrack Pro (discontinued)

    Compressor (purchase)

    etc etc.

    TDC

  • How to switch on and Switch Off LED using lab view

    How to switch on and Switch Off LED using lab view, I need to Switch on and off material LED, not the soft LED.

    I need to know the different ways to Switch On and Off the LED

    Hello

    I need to control the LED on my laptop which is to have labview, kindly tell the different ways that my laptop a serial port, is possible to control using that.

  • How can I download a dvd decoder

    How can I download a dvd decoder

    Hi Nancy,.

    If you try to download the Windows Media Player DVD decoder, you can check the link and try to download the DVD decoder.

    Plug-ins and Add-ons for Windows Media Player

    You can also use your favorite search engine to search for third-party DVD decoders.

    Note: The use of third-party software, including hardware drivers can cause serious problems that may prevent your computer from starting properly. Microsoft cannot guarantee that problems resulting from the use of third-party software can be solved. Software using third party is at your own risk.

    Hope the helps of information. Let us know if you need help with Windows related issues. We will be happy to help you.

  • How to switch to Hotmail which is 10 x faster?

    How to switch to Hotmail which is 10 x faster?

    Go to Outlook and use it. You can transfer you Hotmail to the new site.

Maybe you are looking for