Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Dynamic pattern quantifier usage in match_recognize clause

Sample query:

select * from table
match_recognize (
  order by column1
  pattern (anything {**3**,}) 
  define
    anything as column1 = 'col'
);

Considering I have a table and I want to locate consecutive rows which follow the pattern as defined.
But for the above example, I am looking for a way to dynamically pass a number instead of passing a static value 3.

I have tried to use bind variable, subquery and nothing seems to work. Is there any approach where I can use the same match recognize query with a dynamic quantifier?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If any non-numeric literal is entered it is throwing this error.
SQL Error: ORA-62501: invalid value specified for bounded quantifier in MATCH_RECOGNIZE clause
62501. 00000 - "invalid value specified for bounded quantifier in MATCH_RECOGNIZE clause"

Oracle version: 19c

Request you to please help me with this if anyone has come across such situation. Thanks in advance.

>Solution :

MATCH_RECOGNIZE does not allow you to use dynamic values in the pattern matching clause; instead you can write the query as:

SELECT *
FROM   (
  SELECT t.*,
         COUNT(*) OVER () AS num_rows
  FROM   table_name
  WHERE  column1 = 'col'
)
WHERE  num_rows >= :required_rows
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading