Skip to Main Content
  • Questions
  • How can we dequeue conditional data in dbms_aq.dequeue

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Shabuddin.

Asked: July 30, 2019 - 6:42 am UTC

Last updated: July 30, 2019 - 9:01 am UTC

Version: 11g

Viewed 1000+ times

You Asked

We are using dbms_aq.dequeue to dequeue Sales Orders. The problem is, all the Sales Orders Lines are dequeued. We want to put a condition that dbms_aq.dequeue should only dequeue such Sales Order Lines where ORG_ID is 82.

DECLARATION
l_message SYSTEM.ASO_Order_Feedback_Type;

CODE
dbms_aq.dequeue(
queue_name => l_queue_name,
dequeue_options => l_dequeue_options,
message_properties => l_message_properties,
payload => l_message,
msgid => l_msg_id);


Now, SYSTEM.ASO_Order_Feedback_Type is made up of many other types i.e. header_type ASO_Header_Type, line_varray ASO_Line_Var_Type etc.

Suppose, if I want to put a condition to retrieve rows conditionally from header_type, I am able to put the following condition before dbms_aq.dequeue
l_dequeue_options.deq_condition := 'tab.user_data.header_type.org_id=99';


But I do not know how to put a condition to retrieve rows conditionally from line_varray because

1. line_varray is of ASO_Line_Var_Type
2. type ASO_Line_Var_Type is defined AS VARRAY ( 1000000000 ) OF ASO_Line_Type
3. and ASO_Line_Type is defined AS OBJECT (accounting_rule_id NUMBER , actual_arrival_date DATE , .... , org_id NUMBER , ....)

Can I put the condition like this
l_dequeue_options.deq_condition := 'tab.user_data.line_varray.org_id=99';

and Connor said...

I think you'll be out of luck there.

See this link

https://asktom.oracle.com/pls/apex/asktom.search?tag=varray

for how you get access to varray elements, and then think how that would need to be transposed into a filter condition for a queue table, ie, just a WHERE clause really. You can't put the "table(my_varray)" into the expression that would be needed to complete the join.

But some concerns I'll also mention

1) Don't put stuff in SYSTEM...ever. Create your own schema for your own objects
2) VARRAY(1000000000) suggests a design issue to me. If I'm putting messages on a queue, I'm not sure why I'd want to embed potentially billions of fragments in with that message, especially if I'm then going to filter out just certain elements. Things I'd be looking at would be:

a) maybe a structure like JSON is a better option, or
b) putting just a key on the queue, and then using that key to query the source data (and then filter on org)

Hope this helps

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library