Help in CURSOR when pass parameter for the IN

Hi,
Need some help I have CURSOR that takes a VARCHAR2 and NUMBER but when I run my Procedure it gives invalid number. Here is the CURSOR
CURSOR get_count (p_list VARCHAR2, p_id NUMBER)
      IS
         SELECT COUNT (*) total_rows,
                NVL
                   (SUM (CASE
                            WHEN UPPER (cdcode) = 'PASS'
                               THEN 1
                            ELSE 0
                         END
                    0
                   ) tot_returned,
                  COUNT (*)
                - NVL (SUM (CASE
                               WHEN UPPER (cdcode) = 'PASS'
                                  THEN 1
                               ELSE 0
                            END
                       0
                      ) diff
           FROM testtable
          WHERE plistcol IN (p_list)
            AND pidcol = p_id;
plistcol is of datatype NUMBER
In my procedure I am building a list to comma separated numbers that goes in p_list parameter of type VARCHAR2 to the cursor i.e.
I have a for loop to build that list e.g.
loop
-- num is of datatype NUMBER
p_list := p_list || num || ',';
end loop
IF (p_list IS NOT NULL)
THEN
p_list := SUBSTR (p_list, 1, LENGTH (p_list) - 1);
END IF;here is how my p_list looks when i pass it on to the cursor
*12,345,678*
and here is how open the cursor
OPEN get_count (p_list, 99999);
and here is the error I get
SQLERRM ORA-01722: invalid number
Now when I hard *12,345,678* in my CURSOR SELECT it works fine, it's only when I pass this as parameter it fails. For example I hard code the values in my CURSOR select it works fine
CURSOR get_count (p_list VARCHAR2, p_id NUMBER)
      IS
         SELECT COUNT (*) total_rows,
                NVL
                   (SUM (CASE
                            WHEN UPPER (cdcode) = 'PASS'
                               THEN 1
                            ELSE 0
                         END
                    0
                   ) tot_returned,
                  COUNT (*)
                - NVL (SUM (CASE
                               WHEN UPPER (cdcode) = 'PASS'
                                  THEN 1
                               ELSE 0
                            END
                       0
                      ) diff
           FROM testtable
          WHERE plistcol IN (12,345,678) -- even '12','345','678' works when hardcoded
            AND pidcol = p_id;I even tried passing the values in the format *'12','345','678'* but still get the above error. So how can I pass the values to cursor IN clause.
So wondering what might be the issue.
Thanks

Why this kind of coding needs to be avoid - here is one demonstration of one aspect ->
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE    10.2.0.3.0      Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
Elapsed: 00:00:00.22
satyaki>
satyaki>select * from emp;
     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
      9999 SATYAKI    SLS             7698 02-NOV-08      55000       3455         10
      7777 SOURAV     SLS                  14-SEP-08      45000       3400         10
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
      7566 JONES      MANAGER         7839 02-APR-81       2975                    20
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
      7782 CLARK      MANAGER         7839 09-JUN-81       4450                    10
      7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
      7839 KING       PRESIDENT            17-NOV-81       7000                    10
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
      7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
      7900 JAMES      CLERK           7698 03-DEC-81        950                    30
      7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
13 rows selected.
Elapsed: 00:00:01.90
satyaki>
--Your query works and here is the slightly modified version of your query
satyaki>
satyaki>
satyaki>declare
  2  
  3   type t_ref_cursor is ref cursor;
  4   l_cursor t_ref_cursor;
  5   l_count number;
  6   l_list varchar2(1000) := '10,20';
  7   v_sql varchar2(1000);
  8  
  9  begin
10  
11  v_sql := '';
12  v_sql := v_sql||'select count(*) as tot_count ';
13  v_sql := v_sql||'from emp ';
14  v_sql := v_sql||'where deptno in ('||l_list||')';
15  
16  open l_cursor for v_sql;
17  loop
18    fetch l_cursor into l_count;
19    exit when l_cursor%notfound;
20    dbms_output.put_line('count: '||l_count);
21  end loop;
22  close l_cursor;
23  
24  end;
25  /
count: 8
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.09
satyaki>
--Now, modifying the input i can sniff into the entire data
satyaki>
satyaki>declare
  2  
  3   type t_ref_cursor is ref cursor;
  4   l_cursor t_ref_cursor;
  5   l_count number;
  6   l_list varchar2(1000) := '10,20) or (1=1';
  7   v_sql varchar2(1000);
  8  
  9  begin
10  
11  v_sql := '';
12  v_sql := v_sql||'select count(*) as tot_count ';
13  v_sql := v_sql||'from emp ';
14  v_sql := v_sql||'where deptno in ('||l_list||')';
15  
16  open l_cursor for v_sql;
17  loop
18    fetch l_cursor into l_count;
19    exit when l_cursor%notfound;
20    dbms_output.put_line('count: '||l_count);
21  end loop;
22  close l_cursor;
23  
24  end;
25  /
count: 13
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.10
satyaki>Got me?
Regards.
Satyaki De.

Similar Messages

  • Passing parameter for the bean function that deletes record from DB

    I need to delete some record from the DB without updating the reset of the user screen.
    I use commandButton with immediate attribute as true, because validation should be skipped.
    So, I can't rely on backing bean values being updated, but need to pass a param to the function that does the delete (deleteTemplate) function below.
    The value of this param is selected value in another comboBox called "template".
    Code below is not parsing. Could you advise how to do it?
    <a4j:commandButton id="deleteTemplate" value="Delete"
                             action="#{qtBeanParam.deleteTemplate(param['piPerformanceReturnsForm:template'])}" immediate="true" reRender="template,templateList,templateOwner,templateOwnerList"
                             styleClass="blue-button">
                        </a4j:commandButton>Error Parsing: #{qtBeanParam.deleteTemplate(param['piPerformanceReturnsForm:template'])}

    Thank you for your reply.
    Could I pass the value that is entered in some other field as a "parameter" though?
    <f:param name="anyName" value="parameter" />
    For example the value from the following comboBox?
    <rich:comboBox id="template" width="250" value="#{qtBeanParam.templateName}" enableManualInput="true"
                                  converter="#{templateConverter}" valueChangeListener="#{qtBeanParam.changeTemplate}" >
                                  <a4j:support event="onselect" reRender="template,templateList" ajaxSingle="true" />
                                  <a4j:support event="onchange" reRender="template,templateList" ajaxSingle="true" />
                             <f:selectItems id="templateList" value="#{qtBeanParam.templateList}" />
                        </rich:comboBox>

  • My cursor stays in function when i click for the slideshow

    my cursor remains in function when i click for the slidshow
    nothing works so i have to restart the computer

    You can view the contents of the Unsorted Bookmarks folder in the sidebar view of bookmarks, or in the Library window.
    You need to re-arrange your bookmarks and move that "Newspapers" folder into the Bookmarks Menu folder. The Unsorted folder is meant for quick temporary storage of a bookmark until you take the time to move it to the appropriate folder in the Bookmarks Menu folder. <br />
    http://kb.mozillazine.org/Sorting_and_rearranging_bookmarks_-_Firefox

  • Hi when I try to connect some bluetooth devices I get asked for my pass code for the mac air .  I never had 1 is there a default code

    hi
    when I try to connect some bluetooth devices I get asked for my pass code for the mac air .
      I never had 1 is there a default code
    thanks
    rob

    the shaker wrote:
    is there a default code
    no.

  • On my iPod touch it says on the settings I have wifi but when I look for the 3 bars there is no wifi please help

    On my iPod touch it says on the settings i am connected to my home wifi but when I look for the 3. Bars beside the time they are not there this therefore stops me from using internet please help

    Does the iOS device connect to other networks?
    Does the iOS device see the network?
    Any error messages?
    Do other devices now connect?
    Did the iOS device connect before?
    Try the following to rule out a software problem:                 
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears. already suggested
    - Power off and then back on the router
    - Reset network settings: Settings>General>Reset>Reset Network Settings
    - iOS: Troubleshooting Wi-Fi networks and connections
    - Wi-Fi: Unable to connect to an 802.11n Wi-Fi network
    - iOS: Recommended settings for Wi-Fi routers and access points
    - Restore from backup. See:
    iOS: How to back up
    - Restore to factory settings/new iOS device.
    If still problem make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar

  • I just made the switch to mac. I am have installed all the new PS6 CC and bridge and I am now trying to add some presets to my  ACR but when I search for the folder to place them it is not there.  From what I researched it says it should be under camera l

    I just made the switch to mac. I am have installed all the new PS6 CC and bridge and I am now trying to add some presets to my  ACR but when I search for the folder to place them it is not there.  From what I researched it says it should be under camera library/application support/adobe/camera raw/settings but I can only get to library/application support/adobe/ and then there are two different camera raw options I have checked both and there are not settings folder. If anyone can help me please thanks

    Apple most likely has the same poor taste that Microsoft does when it come to defaults.  Microsoft likes to hide things like  settings, preset, folders etc from normal users  think the dumb or something else.  If Apple also hide things you will have to  make some system setting changes that will allow Finder to do it job and find it for you.

  • How to pass parameter for table name in  form6i.

    Hi ,
    I am facing the problem to pass parameter for table name in form6i.
    If any solution please infirm me earliest to my mail id.
    ([email protected])
    example:
    begin
    select ename into :ename
    from :tab_name
    where empno =7788;
    end;
    It gives error as bad bind variable 'tab_name'
    *** where :ename and :tab_name are form fields
    Thanking you,
    Balasaheb

    object name not taken as table --> what do u mean by
    this?
    Please be more clear..
    Regards
    PriyaI have two block. First block I am displaying all the table using user_objects table. Another block I want display, user which table selected, corresponding table all the records.

  • How to pass parameter to the Query String of the Named Queries'SQL

    Firstly to say sorry,I'm a beginner and my English is very little.
    Now I want to know
    How to pass parameter to the Query String of the Named Queries'SQL in the Map editor.
    Thanks.

    benzi,
    Not sure if this is on target for your question, but see #5 in the link below for some web screencasts that show how to pass an input text form field value to the bind variable of a view object. If you're looking for something different, maybe provide some more details such as what you are trying to accomplish and what technology stack you are using - for example, ADF BC, JSF, etc.
    http://radio.weblogs.com/0118231/stories/2005/06/24/jdeveloperAdfScreencasts.html
    Also see section 5.9 and chapter 18 in the developer's guide.
    thanks

  • How can I delete photos from my ipad that came in when I connected for the first time to my pc?

    how can I delete photos from my ipad that came in when I connected for the first time to my pc? HELP

    Photos that were synced from your computer using iTunes can only be deleted by de-selecting them from the folder from where they were synced -  and then re-syncing.
    Connect the iPad to the PC and launch iTunes.
    Click on the iPad name on the left side under devices.
    Click on the Photos Tab on the right.
    If you want to remove all of the Photos - uncheck the Sync Photos from Heading
    Click on Apply in the lower right corner of iTunes
    If you are using iTunes 11 - this will be helpful, Setting up syncing in Windows.
    http://support.apple.com/kb/PH12313

  • I downloded iphoto 11 9.2 and when opened it for the first time and the program started to update my iPhoto library the file got corrupted. That has happened in the two macs I have (both of them rather new and updated to last Lion version 10.7.2).

    I downloaded Iphoto 11 9.2 from the apps store (was on iphoto '09 before version 8.x) and when opened it for the first time it tried to update my photo librery and ended up corupting it to the extreme that I had to get a backup from time capsule and downgrade my iphoto version. I spent yesterday 6 hours at the genius bar in an apple store and they were not able to provide me with any other solution. In the emantime, I have to forget about about photo streaming... Any idea, is this a bug that somebody knows how tp fix?

    In fairness, this isn't an issue in iPhoto 11 but one in your Library. Some file or other in there is damaged and that's what causes the crash during the upgrade.
    Download iPhoto Library Manager and use its rebuild function. This will create a new library based on data in the albumdata.xml file. Not everything will be brought over - no slideshows, books or calendars, for instance - but it should get all your albums and keywords back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one.  

  • How stop PS6 from removing the DPI value from an image when using "save for the web"?

    How stop PS6 from removing the DPI-value from an image when using "save for the web"?
    Example:
    - Open a tif image, that contains a dpi value (resolution).
    - Use the splice tool in PS6.
    - Export the slices with "Save for web", as gif-files.
    Then the dpi value is removed, the gif files has no dpi value (it's empty).
    How can we stop PS6 from removing the dpi value when using "save for web"?
    OR:
    When using the slice tool, how can we save the sliced pieces without PS removing the dpi value?

    you can make your art go a little bit over the bounds. or you can make sure your artboart and art edges align to pixels

  • When they ask for the gateway address on the Tv what number is that or what number should I be looking for?

    When they ask for the gateway numbers on the TV, what number is that or what should I be looking for? I am trying to connect my wifi network on my Samsung smart TV.

    The "Gateway" address would be the Private (LAN-side) IP address of your Internet router. If you are using an AirPort base station for that router, the default gateway IP address would be: 10.0.1.1

  • I need help in activating apple id to for the find my iphone app

    i need help in activating apple id to for the find my iphone app

    What sort of help are you requesting from us, your fellow users? What exactly is the problem/issue?

  • TS1292 i have an itunes card that when scratching off for the code some of the numbers rubbed off.  This was a gift so i really dont want to ask for a receipt.  Any suggestions?

    i have an itunes card that when scratching off for the code some of the numbers rubbed off.  This was a gift so i really dont want to ask for a receipt.  Any suggestions?

    Click here and ask the iTunes Store staff for assistance. Supply them with as much of the code as you can.
    (97364)

  • What type of license should the user be assigned when passing transactions through the DI Server?

    What type of license should the user be assigned when passing transactions through the DI Server?
    We used to assign indirect access licenses to users that were just using the DI Server.  We have one add-on developer that says that the user has to be a Profession license. Current environment is SAP B1 9.0 PL10.  My understanding was that you could have up to 10 users assigned to a single DI Server license.

    Hi,
    From the license guide,
    Indirect Access – has access to any SSP solutions (developed with the SAP Business One DI-API) only. The Indirect Access license is bundled with the DI server. Users who have an Indirect Access license can access a limited number of application forms, but cannot perform any functions with the SAP Business One application. Users who have an Indirect Access license can access an unlimited number of SSP solutions
    Thanks & Regards,
    Nagarajan

Maybe you are looking for

  • When I open my messages and tap on a message to read it in full, i get a blank screen. How do I fix this

    On my iphone 4s. When I tap on the messages icon, it opens my inbox with all the messages recieved. If I then want to read the message, and tap on it, I get a grey screen. It was'nt always like this, so I must have done something wrong somewhere. Can

  • Bank Reports

    Hi Experts, i want a report of banks when i choose a bank the following fields should come 'Posting Date', 'JE Transaction No', 'Payment Transaction No', 'BP Account ', 'BP Name ', 'Credit/ Debit Amount', Cumulative balance'. Please write the queery.

  • Any hints for preloading and classes?

    Hi all on forum. I have made a class that loads a website (pretty ordinary..) but since all of the site is generated as Childobjects and class-code, I was trying to make a preloader, but it wont work.Seems that the class loads first and then generate

  • My (potential) World of Pain --- what would you do?

    I have also posted this in the Creative Cow forums -- apologies if you read both forums and see this twice, but I wanted to make sure I hit both forums. I am starting to edit a project that will mix footage from Red Epic, Blackmagic Camera & Pana AF1

  • Is possible to pair magic mouse to one and only Mac?

    Question is in the title. I have two MBP and mac mini which i want to be permanently connected with magic mouse, problem is when mac mini is sleeping and somebody works with one of the MBPs it allways take connection of magic mouse, then i have probl