Case statement does not work

Dear all,

We have the database oracle 11g r2 on windows.

I created under function: -.

SQL > CREATE OR REPLACE FUNCTION FUNC_TEST (P_TEST VARCHAR2)

2 RETURN VARCHAR2

3 AS

4 V_TEST VARCHAR2 (20);

5

6 BEGIN

7

8 V_TEST: = P_TEST;

9

10

11 CASES

12. WHEN V_TEST = UPPER ('%UU%') THEN V_TEST: = REPLACE (V_TEST, 'UU', 'U');

13. WHEN V_TEST = UPPER ('%OO%') THEN V_TEST: = REPLACE (V_TEST, 'OO', 'O');

14. WHAT V_TEST = UPPER ('%NN%') THEN V_TEST: = REPLACE(V_TEST,'NN','N');

15 ELSE V_TEST: = "CHANCHAL";

END 16 CASES;

17

18

19 V_TEST RETURN;

20 EXCEPTION SO THAT OTHERS THEN

21 DBMS_OUTPUT. PUT_LINE (' THERE IS AN ERROR ');

22 END;

23.

The function is created.

SQL > SHOW ERR

No errors.

SQL > SELECT FUNC_TEST('toon') FROM DUAL;

FUNC_TEST ('TOON')

--------------------------------------------------------------------------------

CHANCHAL

above function should show 'YOUR' build 'Toon' but its display "CHANCHAL";

I train hard get the result OK but could not get it.

Any suggestions would be very helpful.

Kind regards
Chanchal wankhade.

Hello

Chanchal Wankhade wrote:

Dear all,

We have the database oracle 11g r2 on windows.

I created under function: -.

SQL > CREATE OR REPLACE FUNCTION FUNC_TEST (P_TEST VARCHAR2)

2 RETURN VARCHAR2

3 AS

4 V_TEST VARCHAR2 (20);

5

6 BEGIN

7

8 V_TEST: = P_TEST;

9

10

11 CASES

12. WHEN V_TEST = UPPER ('%UU%') THEN V_TEST: = REPLACE (V_TEST, 'UU', 'U');

13. WHEN V_TEST = UPPER ('%OO%') THEN V_TEST: = REPLACE (V_TEST, 'OO', 'O');

14. WHAT V_TEST = UPPER ('%NN%') THEN V_TEST: = REPLACE(V_TEST,'NN','N');

15 ELSE V_TEST: = "CHANCHAL";

END 16 CASES;

17

18

19 V_TEST RETURN;

20 EXCEPTION SO THAT OTHERS THEN

21 DBMS_OUTPUT. PUT_LINE (' THERE IS AN ERROR ');

22 END;

23.

The function is created.

SQL > SHOW ERR

No errors.

SQL > SELECT FUNC_TEST('toon') FROM DUAL;

FUNC_TEST ('TOON')

--------------------------------------------------------------------------------

CHANCHAL

above function should show 'YOUR' build 'Toon' but its display "CHANCHAL";

I train hard get the result OK but could not get it.

Any suggestions would be very helpful.

Kind regards
Chanchal wankhade.

I think you meant:

CASE

WHEN SUPERIOR (V_TEST) LIKE "% UU" THEN V_TEST: = REPLACE (UPPER (V_TEST), 'UU', 'U');

WHEN SUPERIOR (V_TEST) LIKE '% OO %' THEN V_TEST: = REPLACE (UPPER (V_TEST), 'OO', 'O');

...

'%' is a wildcard character only on the right-hand side of the LIKE operator. '%' has no particular meaning when you use the = operator.

You can also use a CASE expression, rather than a CASE statement to this:

v_test: = UPPER (p_test);

v_test: = BOX

WHEN v_test LIKE "% UU" THEN REPLACE (v_test, 'UU', 'U')

WHEN v_test LIKE "% UU" THEN REPLACE (v_test, 'OO', 'o')

...

END;

Whatever it is, if v_test contains different models (for example "HOOVER VACUUM"), only 1 of them will be changed.  Is that what you want?

If this isn't the case, after a few examples of data (CREATE TABLE and INSERT statements) and the results desired from these sample data.  Explain how you get these results from these data.

See the FAQ forum: https://forums.oracle.com/message/9362002#9362002

Tags: Database

Similar Questions

  • Delete statement does not work properly

    Hello

    The following delete statement does not work correctly.
    If I press DELETE will delete everything in the table of categories
    I don't know whats wrong with it.
    -Delete category line if there is not the infrastructure to support-
    IF: P12_DFCY_SEQNO4 IS NOT NULL AND: P12_DFCY_CATG_C = "7" THEN
    REMOVE FROM DFCY_CATG
    IF NOT EXISTS (SELECT I.DFCY_SEQNO
    OF DFCY_CATG C, DFCY_CATG_INFRSTRCTR I
    WHERE C.DFCY_SEQNO = I.DFCY_SEQNO
    AND: P12_DFCY_SEQNO4 = I.DFCY_SEQNO);
    end if;

    Thank you
    Mary

    You probably the where more clause:

    DELETE FROM DFCY_CATG
    WHERE C.DFCY_SEQNO = :P12_DFCY_SEQNO4
    AND NOT EXISTS(SELECT I.DFCY_SEQNO
    FROM DFCY_CATG C, DFCY_CATG_INFRSTRCTR I
    WHERE C.DFCY_SEQNO = I.DFCY_SEQNO
    AND :P12_DFCY_SEQNO4 = I.DFCY_SEQNO);
    

    Not sure if this is the exact name of your column in the table, but that limit the scope of deleting just a record that you control.

    Hope it will be useful,

    Aaron

  • CASE STATEMENT DOES NOT HIERARCHY

    Hi Experts

    I have this case statement:

    BOX WHEN ' @{pvCalType} "="Cal1"THEN"Calendar Cal1"". "" Year. "

    WHEN ' @{pvCalType} "="Cal2"THEN"Calendar Cal2"". "" Year

    ANOTHER NULL

    END

    All the columns in the YEAR of different sizes have properties of the hierarchy.

    When I view my results of this statement, there is no hierarchy.

    I want the hierarchy in order to drill down of the YEAR > QUARTER > MONTHS

    Help, please.

    Hello

    do you have other possible values for "pvCalType"?

    If not try this formula: "@{pvCalType} schedule". " Year. "

    (not sure this is the right syntax, if it does not work after the return of the error and I get the right thing...)

  • Why this CASE statement would not work?

    If I use a CASE in my SELECT statement and met a strange thing and just need help to understand why he did it.

    When I type this, it does not work:

    CASE TRIM (Column1)
    WHEN NULL THEN Column2
    WHEN 'foo' THEN Column2
    Of ANOTHER Column1
    END AS NewColName

    I use this query in an Oracle procedure to insert data into another table. The data inserted in the column of NewColName end up being 4 empty spaces, located in Column1. In the logic of this, TRIM must remove all the empty spaces, and he should get mapped to the first statement WHEN, who must insert the value of Column2, but that does not occur. I tried the following versions of the first line as well:

    LTRIM (RTRIM (Column1)) CASE
    CASE of REPLACE (Column1, ' ', ")

    and they all produce the same result. I also tried to change WHEN NULL for WHEN " and it changed nothing. However, when I rewrite the statement in this way it works the way it should:

    CASE
    WHEN TRIM (Column1) IS NULL, Column2
    WHEN TRIM (Column1) = 'foo' THEN Column2
    Of ANOTHER Column1
    END AS NewColName

    In my mind, it seems that these two methods are trying the same thing, why we could work and the other not? Only, it has no sense to me.

    Thank you

    Hello

    Welcome to the forum.

    In your first statement, you have

    WHEN NULL THEN.

    This is the same as x = NULL.

    Nothing is never equal to NULL, if you find yourself in your ELSE clause.

    Concerning
    Peter

  • Master page with rollover menu, using States, does not work for all pages?

    Hello.

    I created my masterpage with a basic at the top menu. It has two States. The 1st State is normal and State 2 is a simple rollover behavior, just a different color.

    Why my menu would work perfectly on the page ' 01', but then the reversal function does not work for other pages? (portfolio 03 etc.). She has just the hoverover slider and the link, but the color does not change.

    I have something wrong?

    Thanks a lot for all the help on these forums

    Make sure that all the subpages have a second State added to them. You

    do not put any content on this State, but it must be present

    the transfer of work from the watch page.

    If you do not already have that second State, trying to link then cancelled

    the subpages of the master page. I came across this scenario recently

    because I had created a master page after some of my subpages have been

    already built.

    HTH

    Jim Babbage

  • If the else statement does not work... worked in AS2?

    Hello

    have a very common function that I use in educational quiz itself noted the user according to their score (from answering multiple choice questions). So I put in place a variable called score without problem... but when I apply my confidence "if else"heuristic of AS2... I have all these errors and my flash file does not work. "

    Is there a better way to code that I'm not aware of?

    Stop();

    If (score < = 5) {}
    endMsg.gotoAndStop ("score1");
    } Else if (score > 6 and score < = 11) {}
    endMsg.gotoAndStop ("score2");
    } else {}
    endMsg.gotoAndStop ("score3");
    }

    feedback video called "endMsg" - according to the function, navigates user to label that provides feedback.

    Any help would be awesome... coz this feature used to work! It doesn't work even in Flash CS4 when I retrograde Panel actionScript to version 2 to test!

    I missed using try IT...

    } Else if (score > = 6 & score)<=>

    I know they used to support the use of words for or, but never made a practice of it, so I can't say if they do not support in AS3.  In addition, as long as there will be a score of 5.5, you should be fine.

  • Widget API Find: regex case sensitive does not work

    I try to use the blackberry.find and the blackberry.pim.Contact Widget API to search for a contact.

    I need the contact can be found if the specified filter string is anywhere in the field, regardless of case.  (I need the query to be case insensitive).

    I have a contact, field firstName = 'Norman '.

    I use method REGEX (the only one that might work in this case, I think), with these expressions regex to match "Norman":

    «. * Norm.*' matches

    «. * norm.*"does not match

    So I tried the regex (? I) indicator in the expression, and the discovery does not at all.

    var fe = new blackberry.find.FilterExpression("firstName", "REGEX", ".*(?i)norm.*"); // causes blackberry.pim.Contact.find() to fail
    

    The API doc says "Please refer to java.lang.String.matches () API for more information on the creation of the regular expression correct... "Well, case has been there for some time.

    Case is not supported? If not, well... which sucks.

    I had asked one of the guys on the team who had some difficulty getting case capacity for work.  It came with a work around that is just a bit hacky, but did the trick

    var hack = "";
    var searchText = searchField.value;for (var i = 0; i < searchField.value.length; i++)
    {
      hack = hack + "[" + searchField.value[i].toLowerCase() + searchField.value[i].toUpperCase() + "]";
    }
    
    var fe = new blackberry.find.FilterExpression("firstName", "REGEX", hack + "[a-zA-Z_0-9_\\s]*");
    
    var contacts = blackberry.pim.Contact.find(fe, "firstName", null, null, true);
    

    They created a character set which contained both lowercase and uppercase letter.

  • If the statement does not work/be executed

    I have a button that makes a flip on the x axis 180 if his name is not in a table called "shutters", it determines this by running an if statement. If his name is in the table then the button to run the code to do the folding panels. However, it is not. He let the sign flip one way, but does not have the code for it folding. I was wondering if someone could take a look to see if they know why...

    Code is linked below.

    http://pastebin.com/mc7457

    Thank you

    I don't want to pretend that I understand what you try to do it with the code, but the last section to see ms to be a little hard to swallow.  I don't see any sense in declaring conditionally works, in the call to them.  If I had to guess at a rewrite of the code, it would be...

    photosPane.addEventListener (MouseEvent.CLICK, photoinout);

    function photoinout(e:MouseEvent):void {}
    If (panes.indexOf ("photos") =-1) {}
    addEventListener (Event.ENTER_FRAME, photosrotate);
    Panes.push ("photos");
    trace (Panes);
    } ElseIf (panes.indexOf ("photos") = 0) {}
    addEventListener (Event.ENTER_FRAME, photosrotateout);
    trace ("stuff");
    }
    }

    And insofar as these ENTER_FRAME listeners go, you should remove them in the functions they call as soon as they reached their goal.  Otherwise, they will continue to call these functions several times.  Example:

    function photosrotate(event:Event):void {}
    If (photos.rotationX<>
    photos.rotationX += 6;
    } else {}
    removeEventListener (Event.ENTER_FRAME, photosrotate);
    }
    }

    And, as I said, due to my lack understanding, if my remarks do not apply, I meant no harm.

  • Style in mobile application issues statement (does not work)

    Hello

    In a simple mobile Flex application, I have a simple view with a styleName assigned to a VGroup it contains. The decleration is in the same point of view (for the sake of trying to make this work, but it is in an external css, if I find a way to make it work).

    The padding, I assign just does NOT at all. Nothing. While if I specify in the VGroup directly is paddingTop or another style, it works very well

    Weird behavior.

    Here's the view:

    <? XML version = "1.0" encoding = "utf-8"? >

    " < = xmlns:fx s:View ' http://ns.Adobe.com/MXML/2009 "

    xmlns:s = "library://ns.adobe.com/flex/spark" title = "HomeView" >

    < fx:Declarations >

    <! - Place non-visual elements (e.g., services, items of value) here - >

    < / fx:Declarations >

    < fx:Style >

    {.myGroup}

    paddingTop:200;

    paddingLeft:300;

    paddingRight:30;

    }

    < / fx:Style >

    < s:VGroup styleName = "MyGroup" >

    < s:Label text = "Hello" / >

    < / s:VGroup >

    < / s:View >

    Anyone has any idea why?

    I use Flex 4.6/AIR 3.6 for the moment, he tried with Flex 3.4 4.9.1/AIR too, same behavior.

    Is this a bug? I'm doing something wrong? Y at - it a hack/trick to make this work that specify the styles directly in the MXML?

    Thank you.

    Just realized that the padding in the VGroup aren't styles more but is properties. Damn these spark components

    I guess that's why, and I think it's a disappointment. I know that I could hack this, but condemned me!

  • NOT IN clause in State of the CASE statement does not

    Dear friends,

    I want to use on the condition in the WHERE clause of my SELECT statement.

    WHERE <>...
    <>...
    AND eihf.exr_aip_asset_sid NOT IN
    (CASE when safa.fund_relation = 'C' and safa.fund_account_code! = vFundAccount)
    SO (37874,37909,43424,55040,59513,59598,58570,76148,75885,75927)
    ON THE OTHER
    (0)
    END
    )

    But it gives me an error like "missing of good parenthis."

    Help, please.

    Kind regards
    Jonathan

    You can not write a list of values within the case statement.

    try something like this,

     WHERE
    <------------->
       AND CASE WHEN safa.fund_relation = 'C' AND safa.fund_account_code != vFundAccount
             THEN eihf.exr_aip_asset_sid ELSE 1 END
           NOT IN (37874, 37909, 43424, 55040, 59513, 59598, 58570, 76148, 75885, 75927)
       AND CASE WHEN safa.fund_relation = 'C' AND safa.fund_account_code != vFundAccount
             THEN 1 ELSE eihf.exr_aip_asset_sid  END != 0;
    
  • Simple if statement does not work! Help!

    Did YOU get my first image on the timeline to control a movieclip. Look like this:

    If (mymovie._currentframe == 10) {}
    myMovie.Stop ();
    }


    If she has to stop on the frame of 10, but it doesn't. What is the problem with the script? Do I need some sort of function before?

    Thank you!

    > So there's no way to control the movieclip from another frame?
    # You can assign actionscript for objects that are available on the timeline. In your scenario, you try to assign a script to the object that does not exist. myMovie is unavailable on the first image. If Flash Player do not know the object names "mymovie" If the call fails silently. While on the second image, as the 'mymovie' object is available, the assignment of onEnterFrame works.

    Hope that answers the question.

  • using nested case statement does not get the right result

    Hello all;

    I have a sample of data similar to below
    create table t3
    ( 
           id varchar2(200),
           qty number(30),
           qty2 number(30)
    ); 
     insert into t3
       (id, qty, qty2)
     values
       ('A', 10, null);
     
      insert into t3
       (id, qty, qty2)
     values
       ('A', 20, null);
       
     insert into t3
       (id, qty, qty2)
     values
       ('B', null, 5);
       
    insert into t3
       (id, qty, qty2)
     values
       ('B', null, 5);
       
     insert into t3
       (id, qty, qty2)
     values
       ('C', null, -5);
       
    insert into t3
       (id, qty, qty2)
     values
       ('C', null, 5);
    
    
     insert into t3
       (id, qty, qty2)
     values
       ('D', -1, -2);
       
    insert into t3
       (id, qty, qty2)
     values
       ('D', 1, 4);
    This is what looks like data
    ID  QTY  QTY2
    A    10
    A    20
    B              5
    B              5
    C             -5
    C              5
    D    1        4
    D   -1       -2
    It is the output that I desired below
    ID    Status 
    A      Fail
    B      Fail
    C      Pass
    D      Fail
    A is a failure because the sum of the 2 has the value zero, where the summation of the qty was used to determine the State and because the sum of the quantity is not equal to zero, then, it is a failure
    D is a failure because even if the sum of the Qty 1 equals zero, we must make use of summation of the qty 2 instead because he is not null to determine the status and the summation of the qty is 2, where a failure
    etc.

    I tried write something but can not make it work
    select case when sum(v.qty) is not null
                and sum(v.qty) = 0 then 'Pass'
                when sum(v.qty) is not null
                and sum(v.qty) != 0 then 'Fail'
           else
             case when sum(v.qty2) is not null
               and sum(v.qty2) = 0 then 'Pass'
               else
                when sum(v.qty2) is not null 
                  and sum(v.qty2) != 0 then 'Fail'
                  end as status
              end as status
    
    
     from t3 v;
    any help is appreciated. Thank you.

    Try this,

    SELECT ID,
           CASE WHEN NVL(SUM (qty2),1) !=0 THEN 'fail'
                WHEN NVL(SUM (qty),0) != 0 THEN 'fail'
                ELSE 'pass'
           END
      FROM t3
    GROUP BY ID
    
    OUTPUT
    -------------
    
    ID RESULT
    -- ------
    A  fail
    B  fail
    C  pass
    D  fail
    Z  fail
    

    G.

  • Extended DateTimePicker State does not work in QML

    I want to use the date and time picker in the State developed during loading a
    new page or a journal. I use mode: DateTimePickerMode.DateTime. and all expanded
    property to true. But in date and time mode selector is not treated.

    I tested it with the following code:

    {Of the DateTimePicker
    extended: true
    mode: DateTimePickerMode.Timer
    }
    {Of the DateTimePicker
    extended: true
    mode: DateTimePickerMode.Date
    }
    {Of the DateTimePicker
    mode: DateTimePickerMode.DateTime
    extended: true
    }

    The result is that only the second datepicker (DateTimePickerMode.Date) is developed.
    The first and the last are not expanded.
    I tested the selector DateTime in C++ and works very well (it is extended). But it don't
    convenient for me to expose to QML C++ code.

    What is wrong in the code above? Maybe it's a mistake.

    Thanks in advance

    Yes, still a problem in NDK. Hope BlackBerry it will fix in the next update.

  • Still 'Away', the State does NOT work

    I recently registered in Skype for linux 4.3, and on a separate account under windows, even if Skype for linux said it was 'Online' on my separate account on windows and to all those who had this account as a contact, it was still 'Away', even if Skype for linux said it was "online". In line/Away status on the linux client Skype works do not is a HUGE problem, and I really hope this is addressed soon

    There is difficulty, type directly in a chat on any conversation window, restart your Skype and BAM, your status will be fixed!

    Awesome, finally. This command should run automatically whenever you connect to Skype for linux or something...

  • Help with the situation where a simple group by statement does not work

    There is a table with two columns, which is memo (varchar2), another is recording_date (date). This table is used to recode an every day event. Right now, I need to know how many events registered each day during the time period (between any of the given day and any given end day). the result by selecting should have two columns the numeration of the event, the recording_date. chances are one day it is not just any event, in this situation there not all inserted rows so far here, but the result by selecting must contain also that day with the column count is set to zero.
    between 2010-4-5 and 2010-4-8
    Count   recording_date
    2             2010-4-5
    0             2010-4-6
    1             2010-4-7
    9             2010-4-8
    Can anyone help with this? Thank you in advance!
    Kind regards!

    Hello
    See if this helps:

    I create a dummy cursor that contains one row for each day of the last year - I then outer join the result of the query against the log_table.

    Here are my RAW file
    Select * from log_data

    07/05/2010 1, TEST
    TEST 2 05/05/2010
    02/05/2010 3, TEST
    30/04/2010 4, TEST
    TEST OF 5 30/04/2010
    30/04/2010 6, TEST
    7-30/04/2010 TEST
    8 TEST 06/05/2010
    9 TEST 06/05/2010
    10 06/05/2010 TEST
    11 06/05/2010 TEST
    06/05/2010 12, TEST
    13 TEST 06/05/2010
    2010-05-06 14, TEST
    15 06/05/2010 TEST
    16 06/05/2010 TEST
    2010-05-06 17, TEST

    And here's the query

    with date_ranger as (select trunc (sysdate-) level datecol
    from dual connect by level<= 365="">
    RAW_DATA as)
    Select recording_date, count (*) numrows in log_data
    Group of recording_date)
    Select datecol, date_ranger numrows, raw_data
    where = date_ranger.datecol raw_data.recording_date (+)
    and datecol sysdate-10-sysdate
    order by 1

    And the result

    1 28/04/2010
    2 29/04/2010
    30/04/2010 3, 4
    4 01/05/2010
    02/05/2010 5, 1
    6 03/05/2010
    7 04/05/2010
    8 05/05/2010 1
    9 06/05/10/2010

    What you want?

    See you soon,.
    Harry

Maybe you are looking for