Variable to use as list of numbers for "in" clause

Hello.
I am writing a proc that needs to dequeue an unknown number of messages from an advanced queue, and then query a standard table, returning a cursor. I have coded most of it, but I run into trouble when there is more than one message to be dequeued (which is the most likely scenario). Here is the code as it stands:
CREATE OR REPLACE PROCEDURE prc_get_actv_updts_ac(vConsumerName IN VARCHAR2,
vQueueName IN VARCHAR2,
vMaxIdCount IN INTEGER,
v_retrc OUT SYS_REFCURSOR) IS
obj consolidated_updt_msg_t;
deq_msgid RAW(16);
queueopts dbms_aq.dequeue_options_t;
msgprops dbms_aq.message_properties_t;
vIdList VARCHAR2(32767);
vIdCount INTEGER;
-- As we are dequeuing with the wait flag set to no_wait, an exception
-- will be thrown when there are no messages to dequeue. This will be used to
-- exit the loop (see below)
no_messages EXCEPTION;
PRAGMA EXCEPTION_INIT(no_messages, -25228);
BEGIN
queueopts.consumer_name := vConsumerName;
queueopts.dequeue_mode := dbms_aq.remove;
queueopts.navigation := dbms_aq.next_message;
queueopts.wait := dbms_aq.no_wait;
queueopts.visibility := dbms_aq.immediate;
vIdCount := 0;
-- Loop through the contents of the queue
WHILE vIdCount <= vMaxIdCount LOOP
dbms_aq.dequeue(queue_name => vQueueName,
dequeue_options => queueopts,
message_properties => msgprops,
payload => obj,
msgid => deq_msgid);
vIdCount := vIdCount + 1;
IF (vIdCount = 1) THEN
vIdList := obj.id;
ELSE
vIdList := vIdList || ',' || obj.id;
END IF;
END LOOP;
-- This will be thrown when there are no messages left to dequeue
EXCEPTION
WHEN no_messages THEN
-- Do nothing
NULL;
COMMIT;
DBMS_OUTPUT.put_line('vIdList: ' || vIdList);
OPEN v_retrc FOR
SELECT * FROM t_table t WHERE t.id IN (vIdList);
END prc_get_actv_updts_ac;
You may be wondering why we are trying to do this in the first place. It's a long story, but the plan was to have a c++ app dequeue messages from the queue, but the developer of that piece has run into issues, and because we are under time pressure, we decided to write this proc instead (he knows he can call procs and pull results out of cursors without difficulty). As I said, it works fine when there is only one row to dequeue, but once we have more than one, I get an error during the select statement saying vIdList is an invalid number (and example value of vIdList when I get that error is "6977418,12290358" (without the quotes!)).
Any thoughts?!

Hi OP,
There was another thread about splitting comma-separated numbers lately where a pipelined function solution looked pretty good (well I thought so anyway :) ). I applied a similar approach to your problem, but I obviously couldn't test it (except I tested a similar subselect for the syntax). It means a small re-design whereby the client uses this static select, with binds set appropriately:
SELECT *
  FROM t_table t
WHERE t.id IN (
SELECT COLUMN_VALUE
  FROM TABLE (prc_get_actv_updts_ac (?, ?, ?))
);and the pipelined function looks like this:
CREATE OR REPLACE FUNCTION prc_get_actv_updts_ac (
        vConsumerName       VARCHAR2,
        vQueueName          VARCHAR2,
        vMaxIdCount         INTEGER) RETURN SYS.OdciNumberList PIPELINED IS
  obj           consolidated_updt_msg_t;
  deq_msgid     RAW(16);
  queueopts     DBMS_AQ.dequeue_options_t;
  msgprops      DBMS_AQ.message_properties_t;
  no_messages   EXCEPTION;
  PRAGMA        EXCEPTION_INIT (no_messages, -25228);
BEGIN
  queueopts.consumer_name := vConsumerName;
  queueopts.dequeue_mode := DBMS_AQ.remove;
  queueopts.navigation := DBMS_AQ.next_message;
  queueopts.wait := DBMS_AQ.no_wait;
  queueopts.visibility := DBMS_AQ.immediate;
-- Loop through the contents of the queue
  FOR i IN 1..vMaxIdCount LOOP
    DBMS_AQ.Dequeue(
        queue_name          => vQueueName,
        dequeue_options     => queueopts,
        message_properties  => msgprops,
        payload             => obj,
        msgid               => deq_msgid);
    PIPE ROW (obj.id);
  END LOOP;
EXCEPTION
  WHEN no_messages THEN NULL;
END prc_get_actv_updts_ac;
/Edited by: BrendanP on 23-Nov-2011 11:36
I did actually test a similar subselect but I used positional parameter-passing there - as you have to in SQL, so updated to do same here.

Similar Messages

  • SELECT LIST throws error for WHERE CLAUSE

    Hi All
    I am struck with, what looking like a trivial error, but I don't know how to settle it down. I am new to Apex (3.1). I am experimenting with. I have Oracle 10g running on Windows.
    I have a dropdown item in one of my pages (SELECT list). I am trying to display few items there dynamically (depends on the user who logged in). I set it as SELECT LIST and entered the following query in "List of Values".
    select enrolled_course display_value, course_id return_value
    from COMP_LIST
    where stu_id = :APP_USER
    order by 1I got the following error.
    1 error has occurred
    LOV query is invalid, a display and a return value are needed, the column names need to be different. If your query contains an in-line query, the first FROM clause in the SQL statement must not belong to the in-line query.Then, I tried the step by step instruction from "Oracle® Application Express - Advanced Tutorials -Release 3.1.2 -E10497-02". Using creating list of values creation as seperately. That too, I got the same error.
    I am doing it wrong I suppose. Please correct me. Thanks in advance
    With Regards
    Guru
    Edited by: guru paran on Oct 16, 2008 5:12 PM

    Thanks Andy
    When I hardcoded, it worked.
    select enrolled_course display_value, course_id return_value
    from COMP_LIST
    --where-- --emp_id-- = --100--
    where stu_id = 100
    order by 1
    {code}
    :APP_USER is not working then, Now, I should be using v('APP_USER')? When I tried v('APP_USER'), I got the same error back! The COMP_LIST is a view. Is there some problem with the view then?
    But again, I am able to select from it without WHERE (now with hardcoded value also)....
    Edited by: guru paran on Oct 16, 2008 6:26 PM
    Added [code] tags
    Edited by: guru paran on Oct 16, 2008 6:42 PM
    It is STU_ID and not EMP_ID
    Edited by: guru paran on Oct 16, 2008 6:43 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Can't we use function to derive value for NEXT clause in MV ?

    Hi Friends,
    I have a requirement like below
    I need to derive the schedule (Value for NEXT clause in the create MV command) for a MV to run it
    e.g., Value from a date column : 03-JUL-2012 10:00 AM, VALUE for NEXT clause in CREATE MV statement should be 03-JUL-2012 04:45 AM (It is -5.45 hrs from the above date column value )
    So I wrote a function (GET_DATE) to derive schedule for NEXT clause and tried to call it from NEXT caluse, but it is giving error message as mentioned below
    ORA-04044: procedure, function, package, or type is not allowed here
    CREATE MATERIALIZED VIEW child_mv
    PARALLEL 16
    INITRANS 16
    STORAGE (
    FREELISTS 16
    FREELIST GROUPS 4
    BUILD IMMEDIATE
    REFRESH COMPLETE
    NEXT GET_DATE('PARENT_MV')
    AS
    SELECT * from xxmdme_party_stage where rownum<101;
    Could you please help to give some light on how this can be done ?

    942661 wrote:
    Hi Friends,
    I have a requirement like below
    I need to derive the schedule (Value for NEXT clause in the create MV command) for a MV to run it
    e.g., Value from a date column : 03-JUL-2012 10:00 AM, VALUE for NEXT clause in CREATE MV statement should be 03-JUL-2012 04:45 AM (It is -5.45 hrs from the above date column value )
    So I wrote a function (GET_DATE) to derive schedule for NEXT clause and tried to call it from NEXT caluse, but it is giving error message as mentioned below
    ORA-04044: procedure, function, package, or type is not allowed here
    CREATE MATERIALIZED VIEW child_mv
    PARALLEL 16
    INITRANS 16
    STORAGE (
    FREELISTS 16
    FREELIST GROUPS 4
    BUILD IMMEDIATE
    REFRESH COMPLETE
    NEXT GET_DATE('PARENT_MV')
    AS
    SELECT * from xxmdme_party_stage where rownum<101;
    Could you please help to give some light on how this can be done ?you must (ab)use EXECUTE IMMEDIATE

  • Using apex item for list of number for 'IN' clause

    Greetings,
    I have a computation that looks like this:
    select count(mr.mr_id)
    from ds_moriver mr
    where mr.approved = 0 OR mr.approved IS NULL
    and mr.mr_id NOT IN (:P62_MRID)
    I am looking to enter numbers in the NOT IN clause like '123,234,...'
    I have a text field item (P62_MRID) where the user can enter IDs for the NOT IN clause.  So for example, 13578,182.  If the user enters one number it works fine.  If the user enters 2 numbers with a comma (13578,182) then I get this error when the computation is run:
    ORA-01722: invalid number
    So substituting 13578,182 for P62_MRID the SQL statement should compute as:
    select count(mr.mr_id)
    from ds_moriver mr
    where mr.approved = 0 OR mr.approved IS NULL
    and mr.mr_id NOT IN (13578,182)
    Why am I getting the error, 'ORA-01722: invalid number'?
    Thanks in advance!
    John

    Glad to help. Don't know how long you've been using APEX, but thought I'd caution you against "going wild" with the item substitution syntax. In general, if you can do it with bind variable syntax, that's better. The use of item substitution syntax can contribute to SQL injection attacks. But, if you have suitable control over the contents of the items being substituted, the risk is mitigated. Just don't create an APEX process like this:
    begin
       &P10_TEXT_DIRECTLY_FROM_USER.
    end;
    That'll get you into trouble.

  • Merging variable data using data merge plug-ins for In-Design

    Has anyone had any experience with merging variable data (such as articles for a newsletter) with either of these plug-ins:
    DesignMerge, www.meadowsps.com/site/marketing/productinfo/designmerge.htm
    or Pageflex Studio ID, www.bitstream.com/publishing/products/studioid/index.html

    Only Pageflex Persona (cut down version of Studio - doesn't require InDesign Server).
    Variable stuff is extremely customisable, but design stuff is !@##%. Like Quark 3 simplicity... Customer support is poor in my experience. Program is clunky - they've only just added keyboard shortcuts to access tools... woohoo. Spot colours aren't fully supported - you have to specify them as CMYK and tell your printer to substitute later... you can't design across a spread at all - any two-page graphics have to be placed twice... I could go on!
    For a newsletter, I'd just find a way with InD CS5. Maybe with the Copyfit plugin if you want more functionality, but not with standalone software. For complex variable areas in InD, I just create pdfs or separate InD files of the variable area, and list these as you would images in the csv file. The free LayoutZone addon (Thanks Martinho!) makes region exporting very simple - beware of some occasional bugs with strokes changing.
    I did a job recently with 36 variables per entry, including 2 embedded InD files. The layout was a 3-fold A4 double-sided flyer, with each 3rd page being a few mm shorter to allow for the fold-in. CS5 multi-page size and 3-page spreads made this quite simple to set up.

  • Is there a way to insert a drop-down list in Numbers for iOS?

    I created a spreadsheet in Numbers on my iMac and then transferred it to my iPad, but the iPad version gives me a message stating that drop-down lists are not supported? Is there any way around this?

    a] Yes.
    b] No.
    There is nothing in Rh but there is a method on my site and on htttp://wvanweelden.eu The same scripts, just different explanations.
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • How to use two different port numbers for a single OC4J container

    Hi,
    I have a container OC4J_System running in 7998 port, now I want to add one more port for the same container.
    Is it feasible?
    Kindly help me out.
    Regards
    Vicky

    It's quite complicated, see
    Two Page Numbering Schemes in the Same Document.
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

  • Where can I download Premier and Photoshop Elements 10.0?  Or can I use my old serial numbers for the new versions?

    I have changed computers since purchasing these programs in 2012 and want to install them on my new machine.

    You should deactivate them on the old machine if you no longer intend to use them there.  Serial numbers are version specific so yours will only work with version 10.
    PSE 10, 11, 12 - http://helpx.adobe.com/photoshop-elements/kb/photoshop-elements-10-11-downloads.html
    PE 10, 11, 12 - http://helpx.adobe.com/premiere-elements/kb/premiere-elements-10-11-downloads.html

  • My wifes iPhone is listing two numbers for one contact in iMessage but she only has one number for her in her contacts.

    My wife was playing with her iPhone 5 today and decided she wanted to text one of her friends. Upon typing in their name she noticed that it listed them twice and the second one had another number she hadn't put into contacts. I checked her contacts and there is only one entry for this person and only one number. It is linked to facebook but facebook's information is exactly what we already have. So the issue is, where did this other number coming from and why can't I find it anywhere in the phone to delete it..

    ACtually that's the problem. The friend she was going to text doesn't have an iPhone nor has she ever had an iPhone. She has a *sighs and shakes head* Samsung galaxy s3. So that wouldn't be the problem. The only thing that I can think of is that her friend changed her number on Facebook and its like a bad cookie or something that's causing the number to show up on her phone. I also wend to the finder from her home screen on her iPhone And searched for the incorrect number and it didn't return any results.

  • 3.1.1. doesn't list episode numbers for TV shows?

    What gives? It tells me all the seasons and episode names but not the episode number.
    This is not remotely helpful.

    bug reports: http://www.apple.com/feedback/ipodtouch.html

  • How to convert Character string to individual Numbers for IN clause?

    Hi,
    I'm using the following query but its throwing the error shown below. Please help.
    declare
    ln_UID VARCHAR2(200) := '21,24';
    ln_NUM NUMBER;
    begin
    dbms_output.put_line('ln_UID ' || ln_UID);
       SELECT COUNT(USAGE_RESOURCE_PERMISSION_ID)
          INTO ln_NUM
        FROM  S_USAGE_RESOURCE_PERMISSIONS SURP,
          S_USAGE_PROFILE SUP,
          S_RESOURCE_PERMISSIONS SRP,
          S_RESOURCE SR,
          S_RESOURCE_GROUP SRG
        WHERE SUP.USAGE_PROFILE_ID = SURP.USAGE_PROFILE_ID
          AND SURP.RESOURCE_PERMISSION_ID = SRP.RESOURCE_PERMISSION_ID
          AND SUP.USAGE_PROFILE_ID IN (ln_UID)
          AND SRP.RESOURCE_PERMISSION_VAL <> 3 --view
          AND SRP.RESOURCE_ID = SR.RESOURCE_ID
          AND SR.RESOURCE_GROUP_ID = SRG.RESOURCE_GROUP_ID
          AND SRG.PRODUCT_ID = (SELECT PRODUCT_ID FROM S_PRODUCTS WHERE PRODUCT_NAME='RBPS');
    dbms_output.put_line('ln_NUM ' || ln_NUM);
    end;
    error-
    Error starting at line 1 in command:
    declare
    ln_UID VARCHAR2(200) := '(21,24)';
    ln_NUM NUMBER;
    begin
    dbms_output.put_line('ln_UID ' || ln_UID);
       SELECT COUNT(USAGE_RESOURCE_PERMISSION_ID)
          INTO ln_NUM
        FROM  S_USAGE_RESOURCE_PERMISSIONS SURP,
          S_USAGE_PROFILE SUP,
          S_RESOURCE_PERMISSIONS SRP,
          S_RESOURCE SR,
          S_RESOURCE_GROUP SRG
        WHERE SUP.USAGE_PROFILE_ID = SURP.USAGE_PROFILE_ID
          AND SURP.RESOURCE_PERMISSION_ID = SRP.RESOURCE_PERMISSION_ID
          AND SUP.USAGE_PROFILE_ID IN ln_UID
          AND SRP.RESOURCE_PERMISSION_VAL <> 3 --view
          AND SRP.RESOURCE_ID = SR.RESOURCE_ID
          AND SR.RESOURCE_GROUP_ID = SRG.RESOURCE_GROUP_ID
          AND SRG.PRODUCT_ID = (SELECT PRODUCT_ID FROM S_PRODUCTS WHERE PRODUCT_NAME='RBPS');
    dbms_output.put_line('ln_NUM ' || ln_NUM);
    end;
    Error report:
    ORA-01722: invalid number
    ORA-06512: at line 6
    01722. 00000 -  "invalid number"
    *Cause:   
    *Action:Thanks.

    u cant use ln_UID like that in IN. when you do that it checks for SUP.USAGE_PROFILE_ID = '21,24'
    so you can try some thing like this.
    Note: Code not tested as i dont have the required data structure.
      WITH T AS
      (select to_number(substr(','||ln_UID||',',val,val1-val)) col
        from (select instr(','||ln_UID||',',',',1,level)+1 val, instr(','||ln_UID||',',',',1,level+1) val1
                  from dual
            connect by level <= length(replace(translate(ln_UID,'0123456789',' '),' ',''))+1))
      SELECT COUNT(USAGE_RESOURCE_PERMISSION_ID)
          INTO ln_NUM
        FROM  S_USAGE_RESOURCE_PERMISSIONS SURP,
          S_USAGE_PROFILE SUP,
          S_RESOURCE_PERMISSIONS SRP,
          S_RESOURCE SR,
          S_RESOURCE_GROUP SRG
        WHERE SUP.USAGE_PROFILE_ID = SURP.USAGE_PROFILE_ID
          AND SURP.RESOURCE_PERMISSION_ID = SRP.RESOURCE_PERMISSION_ID
          AND SUP.USAGE_PROFILE_ID IN (SELECT COL FROM T)
          AND SRP.RESOURCE_PERMISSION_VAL <> 3 --view
          AND SRP.RESOURCE_ID = SR.RESOURCE_ID
          AND SR.RESOURCE_GROUP_ID = SRG.RESOURCE_GROUP_ID
          AND SRG.PRODUCT_ID = (SELECT PRODUCT_ID FROM S_PRODUCTS WHERE PRODUCT_NAME='RBPS');Thanks,
    Karthick.

  • Applescript: how to 2 lists of numbers

    I want to update a variable (list of numbers for coordinates) by adding a second list.
    property winPosVar : {50, 100}
    property winOffsetVar : {50, 50}
    set winPosVar to winPosVar + winOffsetVar
    This gives me an error, but if it worked the way I wanted, it would give me winPosVar = {100,150}.
    Is it possible to add 2 lists without breaking out individiual variables for each item in the list?

    Use code such as:
    set list1 to {50, 100}
    set list2 to {50, 50}
    set list3 to {}
    repeat with this_num from 1 to (count list1)
    set list3 to list3 & ((item this_num of list1) + (item this_num of list2))
    end repeat
    (87577)

  • Anyone like to share their favorite custom EQ numbers for the Zen XT

    i was wondering what was a good EQ setting in the Zen XTRA, in the Custom Eaqualizer, could someone share their favorite settings? Like listing the numbers for each of the bands? thanks =) Jordan

    I would like to ressurect this topic since I was going to post a simular topic and question.
    I've learned that the output of the EQ settings depend on the volume level type of earphones you use with them. The Zen Xtra seems to have its own default EQ when the EAX is not enabled. I was wondering what were those settings? Because if you enable the EAX and set the EQ to 0000 the sound is different from just having the EAX turned off. It seems the Zen Xtra is pre EQed for its included Ear Buds I guess. And while it might sound ok, It leaves more high end earphones sounds really muddy.
    I 'm current using the Zen Xtra with the Weston UM2 earphones, and I'm experimenting with the EQ settings. Because of the low and high details the UM2s are capible of capturing, I have to adjust the EQ setting accordingly. I currently have the EQ at -3 -7 2 2 and the volume level at least has to be at the mid point around 4 or 5.
    Does anyone else use the UM2s with the Zen Xtra? If so what are your EQ settings?

  • In need of a report that will list all vendors for all parts in our plant.

    Can anyone tell me if there is a report in SAP that we can use to list all suppliers for a given material? We are operating in SAP ECC6.0 and need a report that will list all vendors that the company has used for a given part. Is there a standard report in SAP that pulls information from purchasing info records?  Woud this be  a custom report?     I have tried using MCE3. 
    Also does anybody know of any SAP consultants that can help us create custom reports

    For the list of vendors for the material - Me03 if source list is maintained
    For list of vendors with info record - Me1m
    For list of vendors with PO - Me2l
    If you can give the correct requirements then your Technical consultant will develop a report in the required format.

  • I am using Numbers on my iPhone5 and cannot get the app to do a simple (SUM) calculation.  It shows the formula correctly in the cell, but all I get for my long list of numbers to add is 0.  How can I get this to work?

    I am using Numbers on my iPhone5 and cannot get the app to do a simple (SUM) calculation.  It shows the formula correctly in the cell, but all I get for my long list of numbers to add is 0.  How can I get this to work?

    Oaky, at least we got that far.  Next step is to determine if all those "numbers" are really numbers.  Changing the format to "number" doesn't necessarily change the string to a number. The string has to be in the form of a number.  Some may appear to you and me as numbers but will not turn into "numbers" when you change the formatting from Text to Number. Unless you've manually formatted the cells to be right justified, one way to tell if it is text or a number is the justification. Text will be justified to the left, numbers will be justified to the right.
    Here are some that will remain as strings:
    +123
    123 with a space after it.
    .123

Maybe you are looking for