CASE Statement error in function -- Please help!

Hi All,
I created a function in my report.
It has a SQL query similar to the one below. The query works fine in SQL plus.
It has a CASE statement. I am getting error at line4 at the select statement. Error is: "Encountered symbol 'SELECT'....."
Can we use CASE statements like this in reports that use SELECT statements for RETURN EXPRESSIONS. Do we have to do any special?
Can someone help me out of this trouble?
THanks in advance.
SELECT PARENT_id,
     CASE WHEN EXISTS (SELECT PARENT_id FROM CHILD CH1 WHERE CH1.PARENT_id = PARENT.PARENT_id AND UPPER(CH1.description) LIKE '%ABC%') THEN
          (SELECT CH2.MOD_id FROM CHILD CH2 WHERE CH2.PARENT_id = PARENT.PARENT_id AND UPPER(CH2.description) LIKE '%ABC%')
     ELSE
          (SELECT MOD_id FROM
          (SELECT MOD_id,PARENT_id FROM CHILD CH3 ORDER BY started) MOD2 WHERE MOD2.PARENT_id = PARENT.PARENT_id AND ROWNUM = 1
     END
) MOD_ID
FROM PARENT;

take out the parentheses after the PARENT_ID and see
like below
SELECT parent_id,
       CASE
          WHEN EXISTS (
                 SELECT parent_id
                   FROM CHILD ch1
                  WHERE ch1.parent_id = PARENT.parent_id
                    AND UPPER (ch1.description) LIKE '%ABC%')
             THEN (SELECT ch2.mod_id
                     FROM CHILD ch2
                    WHERE ch2.parent_id = PARENT.parent_id
                      AND UPPER (ch2.description) LIKE '%ABC%')
          ELSE (SELECT mod_id
                  FROM (SELECT   mod_id, parent_id
                            FROM CHILD ch3
                        ORDER BY started) mod2
                 WHERE mod2.parent_id = PARENT.parent_id AND ROWNUM = 1)
       END AS mod_id
  FROM PARENT;       

Similar Messages

  • Case Statement ....please help :)

    Hi Guys\Gals,
    Just wondering if anyone can tell me the correct usage of the case statement:)
    I want to select counts for particular date ranges to come out as seperate columns.
    Is the Sql Server Case appliable in oracle circumstances?
    This is what im doing:
    select count(case when to_char(logtime,'MM') = '01' then source else 0 end) as January
    from messagetransactionlog
    SQL Error: ORA-00932: inconsistent datatypes: expected CHAR got NUMBER
    Then im getting something like from keyword not found!!
    Plz help :)
    Thanks
    Robert

    Hopefully im not boring people now :)
    can the case statement, as follows:
    count(case when logtime = '07-07' then UNIQUES else null end) as Jul
    be changed to only count distinct rows?
    count distinct (case when logtime = '07-07' then UNIQUES else null end) as Jul
    #SQL Error: ORA-00923: FROM keyword not found where expected
    count (case when logtime = '07-07' then distinct UNIQUES else null end) as Jul
    #SQL Error: ORA-00923: FROM keyword not found where expected

  • Case statement and Decode function both are not working in Select cursor.

    I have tried both the Case statement and Decode function in Select cursor, but both the things are not working. On the other hand both the things work in just select statement.
    See the first column in select (PAR_FLAG), I need to have this evaluated along with other fields. Can you please suggest some thing to make this work. And also I would like to
    know the reason why decode is not working, I heard some where Case statement do not work with 8i.
    Author : Amit Juneja
    Date : 06/20/2011
    Description:
    Updates the Diamond MEMBER_MASTER table with the values from
    INC.MEM_NJ_HN_MEMBER_XREF table.
    declare
    rec_cnt number(12) := 0;
    commit_cnt number(4) := 0;
    cursor select_cur is
    Select DECODE(1,
    (Select 1
    from hsd_prov_contract R
    where R.seq_prov_id = PM.seq_prov_id
    and R.line_of_business = H.line_of_business
    and R.PCP_FLAG = 'Y'
    and R.participation_flag = 'P'
    and SYSDATE between R.EFFECTIVE_DATE AND
    NVL(R.TERM_DATE,
    TO_DATE('31-DEC-9999', 'DD-MON-YYYY'))),
    'Y',
    'N') PAR_FLAG,
    H.SEQ_ELIG_HIST,
    H.SEQ_MEMB_ID,
    H.SEQ_SUBS_ID,
    H.SUBSCRIBER_ID,
    H.PERSON_NUMBER,
    H.EFFECTIVE_DATE,
    H.TERM_DATE,
    H.TERM_REASON,
    H.RELATIONSHIP_CODE,
    H.SEQ_GROUP_ID,
    H.PLAN_CODE,
    H.LINE_OF_BUSINESS,
    H.RIDER_CODE_1,
    H.RIDER_CODE_2,
    H.RIDER_CODE_3,
    H.RIDER_CODE_4,
    H.RIDER_CODE_5,
    H.RIDER_CODE_6,
    H.RIDER_CODE_7,
    H.RIDER_CODE_8,
    H.MEDICARE_STATUS_FLG,
    H.OTHER_STATUS_FLAG,
    H.HIRE_DATE,
    H.ELIG_STATUS,
    H.PREM_OVERRIDE_STEP,
    H.PREM_OVERRIDE_AMT,
    H.PREM_OVERRIDE_CODE,
    H.SEQ_PROV_ID,
    H.IPA_ID,
    H.PANEL_ID,
    H.SEQ_PROV_2_ID,
    H.SECURITY_CODE,
    H.INSERT_DATETIME,
    H.INSERT_USER,
    H.INSERT_PROCESS,
    H.UPDATE_DATETIME,
    H.UPDATE_USER,
    H.UPDATE_PROCESS,
    H.USER_DEFINED_1,
    H.SALARY,
    H.PEC_END_DATE,
    H.REASON_CODE,
    H.PEC_WAIVED,
    H.BILL_EFFECTIVE_FROM_DATE,
    H.BILLED_THRU_DATE,
    H.PAID_THRU_DATE,
    H.SUBSC_DEPT,
    H.SUBSC_LOCATION,
    H.USE_EFT_FLG,
    H.BENEFIT_START_DATE,
    H.SEQ_ENROLLMENT_RULE,
    H.MCARE_RISK_ACCRETION_DATE,
    H.MCARE_RISK_DELETION_DATE,
    H.MCARE_RISK_REFUSED_DATE,
    H.COMMENTS,
    H.USER_DEFINED_2,
    H.USER_DEFINED_3,
    H.RATE_TYPE,
    H.PCPAA_OCCURRED,
    H.PRIVACY_ON,
    H.PCP_CHANGE_REASON,
    H.SITE_CODE,
    H.SEQ_SITE_ADDRESS_ID,
    PM.seq_prov_id rendered_prov
    from hsd_member_elig_history H,
    INC.PCP_REASSIGN_RPRT_DATA P,
    hsd_prov_master PM
    where P.subscriber_id = H.subscriber_id
    and P.rendered_pcp = PM.provider_ID
    and H.elig_status = 'Y'
    and (H.term_date is NULL or H.term_date >= last_day(sysdate))
    order by H.Seq_memb_id;
    begin
    for C in select_cur loop
    rec_cnt := rec_cnt + 1;
    update hsd_member_elig_history
    set term_date = TRUNC(SYSDATE - 1),
    term_reason = 'PCPTR',
    update_datetime = SYSDATE,
    update_user = USER,
    update_process = 'TD33615'
    where seq_elig_hist = C.seq_elig_hist
    and seq_memb_id = C.seq_memb_id;
    INSERT INTO HSD_MEMBER_ELIG_HISTORY
    (SEQ_ELIG_HIST,
    SEQ_MEMB_ID,
    SEQ_SUBS_ID,
    SUBSCRIBER_ID,
    PERSON_NUMBER,
    EFFECTIVE_DATE,
    TERM_DATE,
    TERM_REASON,
    RELATIONSHIP_CODE,
    SEQ_GROUP_ID,
    PLAN_CODE,
    LINE_OF_BUSINESS,
    RIDER_CODE_1,
    RIDER_CODE_2,
    RIDER_CODE_3,
    RIDER_CODE_4,
    RIDER_CODE_5,
    RIDER_CODE_6,
    RIDER_CODE_7,
    RIDER_CODE_8,
    MEDICARE_STATUS_FLG,
    OTHER_STATUS_FLAG,
    HIRE_DATE,
    ELIG_STATUS,
    PREM_OVERRIDE_STEP,
    PREM_OVERRIDE_AMT,
    PREM_OVERRIDE_CODE,
    SEQ_PROV_ID,
    IPA_ID,
    PANEL_ID,
    SEQ_PROV_2_ID,
    SECURITY_CODE,
    INSERT_DATETIME,
    INSERT_USER,
    INSERT_PROCESS,
    UPDATE_DATETIME,
    UPDATE_USER,
    UPDATE_PROCESS,
    USER_DEFINED_1,
    SALARY,
    PEC_END_DATE,
    REASON_CODE,
    PEC_WAIVED,
    BILL_EFFECTIVE_FROM_DATE,
    BILLED_THRU_DATE,
    PAID_THRU_DATE,
    SUBSC_DEPT,
    SUBSC_LOCATION,
    USE_EFT_FLG,
    BENEFIT_START_DATE,
    SEQ_ENROLLMENT_RULE,
    MCARE_RISK_ACCRETION_DATE,
    MCARE_RISK_DELETION_DATE,
    MCARE_RISK_REFUSED_DATE,
    COMMENTS,
    USER_DEFINED_2,
    USER_DEFINED_3,
    RATE_TYPE,
    PCPAA_OCCURRED,
    PRIVACY_ON,
    PCP_CHANGE_REASON,
    SITE_CODE,
    SEQ_SITE_ADDRESS_ID)
    values
    (hsd_seq_elig_hist.nextval,
    C.SEQ_MEMB_ID,
    C.SEQ_SUBS_ID,
    C.SUBSCRIBER_ID,
    C.PERSON_NUMBER,
    trunc(SYSDATE),
    C.TERM_DATE,
    C.TERM_REASON,
    C.RELATIONSHIP_CODE,
    C.SEQ_GROUP_ID,
    C.PLAN_CODE,
    C.LINE_OF_BUSINESS,
    C.RIDER_CODE_1,
    C.RIDER_CODE_2,
    C.RIDER_CODE_3,
    C.RIDER_CODE_4,
    C.RIDER_CODE_5,
    C.RIDER_CODE_6,
    C.RIDER_CODE_7,
    C.RIDER_CODE_8,
    C.MEDICARE_STATUS_FLG,
    C.OTHER_STATUS_FLAG,
    C.HIRE_DATE,
    C.ELIG_STATUS,
    C.PREM_OVERRIDE_STEP,
    C.PREM_OVERRIDE_AMT,
    C.PREM_OVERRIDE_CODE,
    C.SEQ_PROV_ID,
    C.IPA_ID,
    C.PANEL_ID,
    C.SEQ_PROV_2_ID,
    C.SECURITY_CODE,
    SYSDATE,
    USER,
    'TD33615',
    SYSDATE,
    USER,
    'TD33615',
    C.USER_DEFINED_1,
    C.SALARY,
    C.PEC_END_DATE,
    C.REASON_CODE,
    C.PEC_WAIVED,
    C.BILL_EFFECTIVE_FROM_DATE,
    C.BILLED_THRU_DATE,
    C.PAID_THRU_DATE,
    C.SUBSC_DEPT,
    C.SUBSC_LOCATION,
    C.USE_EFT_FLG,
    C.BENEFIT_START_DATE,
    C.SEQ_ENROLLMENT_RULE,
    C.MCARE_RISK_ACCRETION_DATE,
    C.MCARE_RISK_DELETION_DATE,
    C.MCARE_RISK_REFUSED_DATE,
    C.COMMENTS,
    C.USER_DEFINED_2,
    C.USER_DEFINED_3,
    C.RATE_TYPE,
    C.PCPAA_OCCURRED,
    C.PRIVACY_ON,
    C.PCP_CHANGE_REASON,
    C.SITE_CODE,
    C.SEQ_SITE_ADDRESS_ID);
    commit_cnt := commit_cnt + 1;
    if (commit_cnt = 1000) then
    dbms_output.put_line('Committed updates for 1000 records.');
    commit;
    commit_cnt := 0;
    end if;
    end loop;
    commit;
    dbms_output.put_line('Total number of MEMBER_ELIG_HISTROY records inserted : ' ||
    rec_cnt);
    exception
    when others then
    raise_application_error(-20001,
    'An error was encountered - ' || sqlcode ||
    ' -error- ' || sqlerrm);
    end;

    user10305724 wrote:
    I have tried both the Case statement and Decode function in Select cursor, but both the things are not working. Please define what you mean by not working even if your computer screen is near the internet we can't see it.
    You should also look at the FAQ about how to ask a question
    SQL and PL/SQL FAQ
    Particularly *9) Formatting with {noformat}{noformat} Tags* and posting your version.
    know the reason why decode is not working, I heard some where Case statement do not work with 8i.
    Does this mean you are using 8i? Then scalar sub queries - selects within the select list, are not supported, along with CASE in PL/SQL.
    Select DECODE(1,
    * (Select 1
    from hsd_prov_contract R
    where R.seq_prov_id = PM.seq_prov_id
    and R.line_of_business = H.line_of_business
    and R.PCP_FLAG = 'Y'
    and R.participation_flag = 'P'
    and SYSDATE between R.EFFECTIVE_DATE AND
    NVL(R.TERM_DATE,
    TO_DATE('31-DEC-9999', 'DD-MON-YYYY')))*,
    'Y',
    'N') PAR_FLAG,
    >
    exception
    when others then
    raise_application_error(-20001,
    'An error was encountered - ' || sqlcode ||
    ' -error- ' || sqlerrm);
    http://tkyte.blogspot.com/2008/01/why-do-people-do-this.html                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • I backed up my movies and rebuild my computer, and after making sure i'm using the latest version of itunes and quicktime and and making sure i still had spare computer authorizations, i still get error 23132.  Please help.

    I backed up my movies and rebuild my computer, and after making sure i'm using the latest version of itunes and quicktime and and making sure i still had spare computer authorizations, i still get error 23132.  Please help.

    I had this exact issue.  Spent over an hour on the phone with apple support, they couldn't resolve.  Here is what I ended up doing, that worked.
    1.  Turned iTunes match off on all my iOS devices
    2.  Deleted the offending playlists from the iOS device they originated on
    3.  Started iTunes, let it run (literally) for an hour before it became responsive.  First thing I did, before clicking anywere else was disable iTunes match.  If I clicked anywhere, it would clock for another hour.
    4.  Let iTunes run overnight, by morning it had cleaned out the repeating play lists.  This got my Mac/iTunes back to an operable state.
    5.  Restore iPhones from backup in iTunes.
    What was causing my issue was a single playlist that was created on an iPhone, then suddenly showed up with several thousand duplicates on my other iPhone.  The culprit playlist did not, for some reason, duplicate itself on my two iPads.  Apple support seemed to think it was because the problem iPhone tried to sync the playlist to iCloud over and over again unsuccessfully, then it finally went through and populated the thousands of blank/failed playlists which then tried to propigate to iTunes and my other iOS devices.  Seems like a reasonable theory.
    I have not yet re-enabled iTunes match.  So, no idea what will happen if I decide to go back down that rabbit hole.

  • TS3694 How can I fix this type of error in iphone 4?"The iphone could not be restored. An unknown error occurred (3194) "please help me.

    Hi everybody !
    AT&T company is unlocked (factory)my iphone4 before 3 days ago so i want to restore to unlock iphone 4 with itunes but it is not restore.
    How can I fix this type of error in iphone 4?- "The iphone could not be restored. An unknown error occurred (3194) "
    please help me in nepali language(if posible) or english. thank you.

    http://support.apple.com/kb/TS3694#error3194
    This means that either your firewall/antivirus is blocking access to Apple's servers, or you have used your computer to jailbreak an iDevice in the past. The link above tells you how to resolve this issue.

  • Photoshop CS6 could not update successfully.  Error codes Adobe Photoshop 13.0.1.3 Installation failed. Error Code: U44M1P7  Extension Manager 6.0.8 Update Installation failed. Error Code: U44M1P7  Please help me figure out how to call customer service. 

    Photoshop CS6 could not update successfully.  Error codes Adobe Photoshop 13.0.1.3 Installation failed. Error Code: U44M1P7  Extension Manager 6.0.8 Update Installation failed. Error Code: U44M1P7  Please help me figure out how to call customer service.  I would prefer to talk to someone directly.

    Are you using any disk cleaner or optimization tools like CleanMymac or Mackeeper?
    Regards,
    Ashutosh

  • TS2865 when i export movie from final cut pro to quicktime , something happened. it says error quicktime -50. please help.

    when i export movie from final cut pro to quicktime , something happened. it says error quicktime -50. please help.
    i need to submit this movie for uni project tomorrow.
    any help/advice will help . thanks.

    According to Crash Analyzer
    -50 (QuickTime)
    This error occurs when there is corrupt or invalid media in your timeline. Check that the codec used by the file is recommended for use in your editing application.
    good luck

  • TS3694 hi, I was trying to update my iPhone 3gS but when I turn it on again iTunes send me a message that says error 3194 occurs, please help me!!

    hi, I was trying to update my iPhone 3gS but when I turn it on again iTunes send me a message that says error 3194 occurs, please help me!!

    If the screen shows a plug going to itunes, then you have no choice,  It's in recovery mode.  You'll be given the chance to restore from a backup either from itunes or icloud.
    I assume when you got the message to update (was this for the ios or update some apps?), that was before the device when dead.  At any rate, doing a restore does not change the ios.

  • HT201413 Whenever i try to sync my ipod a message keeps coming up saying "1 or more items could not be synced", apparently its error -69. Please help, i've tried rebooting my laptop, installing the latest itunes and turning off the wifi but nothing seems

    Whenever i try to sync my ipod a message keeps coming up saying "1 or more items could not be synced", apparently its error -69. Please help, i've tried rebooting my laptop, installing the latest itunes and turning off the wifi but nothing seems to work.

    Are you using security software on your PC? If yes, try to disable the software or check the settings. More info here: http://support.apple.com/kb/TS3125

  • My ipad mini 2 is not turning on. I tried to reset with the power/home buttons but it didnt work. I tried to restore it in DFU mode but it didnt work, i get error 4004. Please help me!

    My ipad mini 2 is not turning on. I tried to reset with the power/home buttons but it didnt work. I tried to restore it in DFU mode but it didnt work, i get error 4004. Please help me!

    I also tried the ol' whacking 3 times trick...Didn't work to my surprise

  • Cannot restore my brand new iphone 4s ,got stuck in DFU mode and itunes shows error code (-1) please help?

    Cannot restore my brand new iphone 4s ,got stuck in DFU mode and itunes shows error code (-1) please help?
    repeatedly tried from diffierent computers and the same error code pops up (error -1)

    That's a hardware problem which will require a trip to the Apple store for evaluation, unless your phone has been jailbroken, then it's a corrupt hosts file (and we can't help you with that here as it is against the forum's terms of use).

  • I cannot restore my Iphone 4, I keep getting the error code 1611, please help and the Iphone keeps displaying the "Plug-In Itunes Symbol!??

    I cannot restore my Iphone 4, I keep getting the error code 1611, please help and the Iphone keeps displaying the "Plug-In Itunes Symbol!??

    http://tinyurl.com/nyj36v

  • ýesterday  my iphone 5c screen  suddendly  shows connect to itune and i try to restore it using itune but halfway i got a message error occured (14). please help me in solving this problem.

    ýesterday  my iphone 5c screen  suddendly  shows connect to itune and i try to restore it using itune but halfway i got a message error occured (14). please help me in solving this problem.

    what did you learn when you search the internet for iPhone error 14?

  • I am not able to sync some videos and apps onto my iphone 3gs. it shows a sync error: 0xe8008001.i updated it but still i am getting the same sync error problem..please help.

    i am not able to sync some videos and apps onto my iphone 3gs. it shows a sync error: 0xe8008001.i updated it but still i am getting the same sync error problem..please help.
    aman

    Are you using Windows...?

  • My dear during i update my iphone 4s 16 giga  to ios 7 itis not responde and error 4005  wasfound please help me

    dear sir during updating my iphone 4s 16 giga error 4005 found please help me

    http://lmgtfy.com/?q=iPhone+error+code+4005

Maybe you are looking for

  • White background is shown when a psd file is inserted in illustrator

    A psd file with transparent background is inserted into a AI file, I found that a white background is shown when printing. Afterwards, I checked this problem occurs on true postscript printer only. All other type of printers are not affect.What's the

  • Photo Stream Delay Issues

    Photo Stream Delay. When I take pictures on my iPhone 4s or ipad3 it take 8 hours   or even days to reach my other devices. How do you fix this delay is awful. I have the same isse even when on WIFI?

  • Multiple recepients in an e-mail

    Is there a limit on how many addresses I can have in my "to" list.  My recent attempt to reply-all to a message wil only pick 5 of the addresses.

  • Install complete - how to run elements on my mac

    install complete - how to run elements on my mac?

  • Active window switches to finder

    I can be in any application eg:mail or typing this post on the web site and while typing the my cursor will disappear and the active window will change to the desktop. I don't have to be doing anything, I could be just reading a page in any applicati