Variable to use as a list of numbers for 'in' clause

Hello.

I write a proc that should remove a unknown number of messages in a queue advanced and then query a standard table, return a cursor. I've coded most of it, but I have problems when there is more than one message to be removed (which is the more likely scenario). Here is the code as it is:

CREATE OR REPLACE PROCEDURE prc_get_actv_updts_ac (vConsumerName IN VARCHAR2,
vQueueName IN VARCHAR2,
vMaxIdCount in FULL,
v_retrc OUT SYS_REFCURSOR) IS
consolidated_updt_msg_t obj;
deq_msgid RAW (16);
queueopts dbms_aq.dequeue_options_t;
msgprops dbms_aq.message_properties_t;
vIdList VARCHAR2 (32767).
vIdCount INTEGER.

-As we queue with the wait flag set to no_wait, an exception
-will be thrown when there is no message to dequeue. This will serve to
-the output of 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;
ON THE OTHER
vIdList: = vIdList | ',' || obj.ID;
END IF;

END LOOP;

-It will be lifted when there is no message left to dequeue
EXCEPTION
WHEN no_messages CAN
-Do nothing
NULL;
COMMIT;

Dbms_output.put_line ('vIdList: ' | vIdList);

OPEN FOR V_retrc
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 in the first place. It's a long story, but the plan was to have a c application ++ dequeue messages from the queue, but the developer of that piece ran into problems, and because we are under pressure of time, we decided to write this proc rather (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 line to dequeue, but as soon as we have more than one, I get an error in the select statement, saying: vIdList is an invalid number (and the value of example of vIdList when I get that error is "6977418,12290358" (without the quotes!)).

Any thoughts?

Then use the table/varray:

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 sys.OdciNumberList := sys.OdciNumberList();

-- 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);

vIdList.extend;
vIdList(vIdList.count) := obj.id;

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 member of vIdList;
END prc_get_actv_updts_ac;

Or you can use:

V_retrc OPEN to SELECT * t_table t WHERE t.id in (select * from table (vIdList));

SY.

Published by: Solomon Yakobson on November 23, 2011 11:41

Tags: Database

Similar Questions

  • SQL how to use a variable and use the result as a reference for the name of the table

    Hi all

    I have new in the declaration of Oracle, sorry in advance if something is easy for you all. BTW, I have this scenario:

    I have a table OL structured in this way:

    Date - it contains dates, for example 11/01/2015

    TableName - it contains strings, for example, OL1, OL2, OL3 and so on...

    Then I have a different table, the name of these tables are of the same name in the table of the OL, so I have table table, OL1, OL2, OL3 table and so on. The structure of these tables is the same. And Yes.

    table OL1

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

    ID LAST NAME FIRST NAME PHONE

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

    1 JOHN DOE 12345679

    2 PAUL 111111122 TIBBS

    table OL2

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

    ID LAST NAME FIRST NAME PHONE

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

    1 ANNA KRAIG (NULL)

    NATHAN FRESHMANN 111111133 2

    If the scenario is clear, I would like to retrieve the value (null), research in all the OL * tables by using the value of the OL table (tablename) max.

    If I'm going to do these simple steps, I got the result:

    Select max (TableName) OL

    the result will be OL2

    # I know not how to use the option set to avoid changing the table name in the sql statement all the time.

    set mytable = 'OL2.

    Select Name, family name

    of & mytable

    When the phone is null

    Any idea?

    Thank you very much in advance.

    Hello

    run immediately "select dt.log_id, obj.presentation_name, dl.begin_time

    bulk collect into v_result_set

    of ' | v_ol |' dt join internal ol_object obj on

    DT.object_type_id = obj.object_type_id

    inner join ol_chunk_log dl on

    DT.log_id = DL.log_id

    where dt.data_value is null';

    dbms_output.put_line (v_ol);

    end;

    Correct the code such as:

    run immediately "select dt.log_id, obj.presentation_name, dl.begin_time

    of ' | v_ol |' dt join internal ol_object obj on

    DT.object_type_id = obj.object_type_id

    inner join ol_chunk_log dl on

    DT.log_id = DL.log_id

    where dt.data_value is null' bulk collect into v_result_set;


    for i in v_result_set.first ... v_result_set. Last

    loop

    dbms_output.put_line ('LOG ID: ' | ) ( v_result_set.log_id (i)) ;

    dbms_output.put_line (' NAME CLOSELY: ' |) v_result_set.presentation_name (i));

    dbms_output.put_line (' START TIME: ' |) ( v_result_set.begin_time (i)) ;

    end loop;

    end;

    Kind regards.

  • Using the variable obtained using JavaScript in a widget

    Hi again

    I found this useful bit of JavaScript code that gets the name of active users of an LMS and sets it to a variable in a Captivate course.  [the link below for anyone interested]
    I have seen that variables can be used in the Widgets but I can't make it work.

    I have defined the variable as ActiveUserName ($$ActiveUserName$ $ in list dropdown widget) but it shows that $$ActiveUserName$ $ if I'm the test or on a LMS System.  Same result with an entry box.

    Someone has already tried this before or know a way to do this please?

    Thank you

    As promised, the JavaScript link on behalf of active users of traction: display name of your LMS using Adobe Captivate to the 6.x - CaptivateDev.com student

    Captivate 7 and 8, the Captivate defined variable user cpQuizInfoStudentName made for you.

    With regard to the drop-down list widget, you cannot use a variable in the comma delimited list to display to the user. The result when the user makes a selection in the list can be assigned to a variable.

  • Works with dynamic sql and list of numbers as return value

    Hello.

    Problems:

    1. How can I insert the USERNAME variable in the string so it will be replaced over time.
    2. I intend to return a list of IDS as 1,4,6,7,2 I want to use later in an IN clause.

    How to complete the return function with the dynamic sql output variable?
    I have no preference to dynamic sql but it was just something that came into my mind
    When I thought that the implementation of the obligation to choose a list of offices for specific user groups.
    (select statements from the sample are cut short, they're actually really big and I want to reuse this function in my)
    BI Publisher data model for multiple modells).


    CREATE or REPLACE FUNCTION F_OFFICES (-input parameters)
    USERNAME IN VARCHAR2
    USERGROUP IN VARCHAR2,
    )
    -Output parameter
    RETURN VARCHAR2 AS
    dynSQL VARCHAR2 (1000);
    BEGIN

    IF USERGROUP = "local" THEN

    dynSQL: = 'xxx SELECT FROM CO_B WHERE Userid = username';

    ELSIF USERGROUP = "regional" THEN

    dynSQL: = "SELECT...". » ;

    ELSIF USERGROUP 'federal' = THEN
    dynSQL: = "SELECT...". » ;

    END IF;

    EXECUTE IMMEDIATE dynSQL;

    -RETURN?;

    END F_OFFICES;


    Thanks for any help.

    As you have presented essentially pseudo-code we can only give you a Pseudo-solution :)

    But the principle is:

    ...
    --Output parameter
    RETURN VARCHAR2 AS
        dynSQL VARCHAR2(1000);
        return_value varchar2(30):
    BEGIN
    
      IF USERGROUP = 'local' THEN
        dynSQL:= 'SELECT xxx FROM CO_B WHERE userid = :1'; -- placeholder for parameter
    
       ...
      END IF;
    
      EXECUTE IMMEDIATE dynSQL
         using USERNAME -- pass parameters in placeholder order
         into return_value;   -- obviously this must match the projection of the dynamic query 
    
      RETURN return_value; 
    
    END F_OFFICES ;
    

    This approach is not good if you want to vary the dynamic query projection. In this case, you can use a REF CURSOR or maybe DBMS_SQL.

    Cheers, APC

  • the list of numbers between two columns

    Hello

    I need the list of numbers between two columns.

    My source table contains the intervals with different ranges and I'm currently thinking dividing them by size.

    I was able to get a solution following the information contained in the Web page:
    http://StackOverflow.com/questions/3971981/get-list-of-numbers-in-between-two-columns

    The solution I've used is based on the following example:
    with t as (   
      select 10 startnum, 15 endnum from dual   
      union all   
      select 18, 22 from dual   
      union all   
      select 10000, 19999999999 from dual   
    )   
    select lvl   
      from (select level lvl  
               from dual  
            connect by level <= (select max(endnum) from t)) a  
      where exists (  
         select 1  
           from t  
          where lvl between t.startnum and t.endnum ) 
    But this doesn't work in my table if I have few and modest intervals (maximum 5 digits range).
    In the example, I was trying to understand why this might be failing, but I do not have a conclusion yet.
    There is something I noticed and that I try to understand, that is:
    If I change this query to:
    with t as (   
      select 10 startnum, 15 endnum from dual   
      union all   
      select 18, 22 from dual   
      union all   
      select 19999999990, 19999999999 from dual   
    )   
    select lvl   
      from (select level lvl  
               from dual  
            connect by level <= (select max(endnum) from t)) a  
      where exists (  
         select 1  
           from t  
          where lvl between t.startnum and t.endnum ) 
    It will increase from 2 to 3 seconds to return results to a few minutes at least (canceled after a few minutes!)

    Thus, using this example to understand if my problem is related to having many between start and end number or if it is linked with having small intervals between large numbers.

    Can someone explain to me why I have this speed of different treatment depending on the value of the interval? And why it takes longer with the small interval?

    I need to apply it to different beaches (from 2 ranges of numbers to 16 range) and in all ranges, I will have small intervals to check.

    For example:
    endnum startnum
    7341 7342
    7422-7423
    7439 7456

    2522200050 2522200054
    2522200146 2522200150

    4216969839880 4216969839884
    4216969839893 4216969839897

    Having this problem I can only ask the first values I have in the picture!

    Best regards
    Ricardo Tomas

    Hi, Ricardo,

    Here's one way:

    WITH       cntr     AS
    (
         SELECT     LEVEL - 1     AS n
         FROM     (
                  SELECT  MAX ( endnum - startnum)     AS max_diff
                  FROM    t
              )
         CONNECT BY     LEVEL <= max_diff + 1
    )
    SELECT  startnum + c.n
    FROM     t
    JOIN     cntr  c      ON   t.endnum  >= t.startnum + c.n
    ;
    

    In your original query, you generate all the numbers from 1 to the highest endnum. You only need enough numbers to cover the range of startnum to endnum. (This method also works if startnum is less than 1).
    Joins are usually faster than EXISTS subqueries.

  • I used numbers for a long time, but only make spreadsheets base.  With the latest updates, I couldn't change my information.  What Miss me?

    I used numbers for a long time, but only make spreadsheets base.  For about a year and with the latest updates, I couldn't change my information.  What Miss me?

    Hi Deb,

    There not really enough information in your message to help you. How things don't work, exactly? Is there any alerts or messages?

    Quinn

  • How to locate where the shared Variables are used in the project.

    I'm looking everywhere where a shared Variable is used in my project. Right-clicking does not provide a find. The display hierarchy does not help. In the Project Explorer, the appellants find displays only the names of the screw called, not the many places where the call is made.

    Does anyone know how to find the location where a shared Variable is used?

    Edit-> find and replace. For "Select object" click and access features-> Structures-> shared Variable.

  • Download DataServer User/Pass/host with ODI Variable to use in the ODI tools

    Hi guys.


    I was thinking about a way to dynamically modify the ODI tool based on the parameters of a root.


    So I created a dummy DataServer with host that the IP address of the server I want to reach and define the user/pass I will use to authenticate.


    Data_Server_DMZ.png

    Then I coded a variable with odiRef.getInfo to obtain this information, but the two results return nothing because this API based on the execution of an interface works. I've not found an API to get these values from a package.

    ODIVariable_HOST.png

    Is there a way to get this base only in a logical schema, such as: odiRef.getDataServerInfo ("LS_OF_THE_DATASERVER", "DSERV_NAME") so that I can use it like this:

    ODI_PKG.png

    Thanks for the help, Giampaoli.

    I've made a few changes based on the post you sent.

    Basically, I used only the tip of the game from the source as the topology I wanted settings and coded the target with this:

    Command on the target

    Command on the Source

  • Can I use * and the list of the column names in a select query

    PLSQL again.  Can I use * and the list of the column names in a select query, i.e. Select *, col1, col2 from Mytable.  When I do that my questions tend to the bomb.  Can do in other databases.

    Thank you

    Mike

    Hi, Mike,.

    If there is something else in the more SELECT clause *, then * must be qualified with a table name or alias.

    For example:

    SELECT Mytable. *, col1, col2

    FROM MyTable;

  • List of numbers start with a number other than 1?

    Hi all


    I supervised two side by side (since I can't do 1 column 2 text box).

    I need the list numbering from 1 to 5 on the left and 6-10 on the right.

    I can't find a way to change the starting number of the list of numbers. Any ideas how I can do?

    Any help appricated!

    Ordered lists support different numbering schemes and start numbers shifts. Unfortunately Muse doesn't expose all this kind of things, so you need to change the published HTML. Refer to this:

    Ol HTML tag

    Mylenium

  • List of numbers

    I need to strip the numbers manual and replace them with the automatic paragraph numbers.

    1 1.     text

    2 2.     Text2

    Is this possible via the script. It can be applied only in the list of numbers

    You need to escape the backslashes: ' ^ \\d+?\\.\\t+ ';

    But the way you did, without defining a replacement string, applies only to the paragraph style NL, it does not remove the manual numbering. To apply the style and remove the number, follow these steps:

    app.findGrepPreferences=null;
    app.changeGrepPreferences=null;
    app.findGrepPreferences.findWhat="^\\d+?\\.\\t+(.)";
    app.changeGrepPreferences.changeTo="$1";
    app.changeGrepPreferences.appliedParagraphStyle="NL";
    app.activeDocument.changeGrep();
    

    Peter

  • Safe fonts Web does not support the Norwegian letters æ, o and a. when published. We do not want to use the fonts listed, because the quality is not good published wen.  Any tips?

    Safe fonts Web does not support the Norwegian letters æ, o and a. when published. We do not want to use the fonts listed, because the quality is not good published wen.  Any tips?

    Hello

    Please try to use the glyphs Panel available with Muse.

    Adobe help Muse | Use of text

    It will be useful,

    Sonam

  • How do I know where a variable was used?

    How can I tell where a variable is used in a procedure of interface/package /?

    Should I check using internal tables from the repository?

    Thank you

    Hello

    You must do some queries to find the variable used in ODI object.

    as he retrieves the variable with the name of the scenario and scénarion can meet your need.

    Select v.i_var, v.var_name, s.scen_name of

    ODEV91119_ODI_WORK.snp_var v, ODEV91119_ODI_WORK.snp_scen s

    where

    s.i_var = v.i_var

    and s.scen_NAME = 'V_BTCH_NAME'

    and agree with the answer SH

    Thank you

  • to install Indesign on my new computer, but can't. First bought CS2 in 2009 and upgraded to 7.5 in 2011. I have the serial numbers for the two and was able to use it on my last computer. Where should I start?

    to install Indesign on my new computer, but can't. First bought CS2 in 2009 and upgraded to 7.5 in 2011. I have the serial numbers for the two and was able to use it on my last computer. I use Indesign that often but there are some projects that it is good for. Where should I start?

    Lchrichton123 what version of InDesign are specifically keen to install?  You can find links to the installation files for the majority of Adobe Creative software titles of other downloads

  • How to use the alternative list template during the rendering of elements of web application to a page?

    I need to be able to use the main list on some pages, but then use the different tag for other pages - is there a way I can specify the alternative list within the tag module template?

    Hi Matt, you should read on web apps here:

    STOM.html http://helpx.adobe.com/content/Help/en/Business-Catalyst/Partner/Web-Apps-module-Create-Cu

    And reference module here:

    http://helpx.Adobe.com/business-catalyst/KB/modules-quick-reference.html

    If you insert in the admin, and then click Customize you will see the option to use listbackup. You will also see this provision availible via FTP and in admin or DW.

    Here you can see where in the module settings, the ability to choose the listbackup occurs:

    http://helpx.Adobe.com/business-catalyst/KB/modules-quick-reference.html#id_65138

Maybe you are looking for