0

I want to delete some tables and wrote this procedure:

    set serveroutput on
    declare
        type namearray is table of varchar2(50);
        total integer;
        name namearray;
    begin
        --select statement here ..., please see below
        total :=name.count;
        dbms_output_line(total);

        for i in 1 .. total loop
        dbms_output.put_line(name(i));
        -- execute immediate 'drop table ' || name(i) || ' purge';
    End loop;
    end;
    /

The idea is to drop all tables with table name having pattern like this:

ERROR_REPORT[2 digit][3 Capital characters][10 digits]
example: ERROR_REPORT16MAY2014122748

However, I am not able to come up with the correct regexp. Below are my select statements and results:

select table_name bulk collect into name from user_tables where regexp_like(table_name, '^ERROR_REPORT[0-9{2}A-Z{3}0-9{10}]');

The results included all the table names I needed plus ERROR_REPORT311AUG20111111111. This should not be showing up in the result.

The follow select statement showed the same result, which meant the A-Z{3} had no effect on the regexp.

select table_name bulk collect into name from user_tables where regexp_like(table_name, '^ERROR_REPORT[0-9{2}0-9{10}]');

My question is what would be the correct regexp, and what's wrong with mine?

Thanks,

Alex

2 Answers 2

1

Correct regex is

'^ERROR_REPORT[0-9]{2}[A-Z]{3}[0-9]{10}'
Sign up to request clarification or add additional context in comments.

Comments

0

I think this regex should work:

^ERROR_REPORT[0-9]{2}[A-Z]{3}[0-9]{10}

However, please check the regex101 link. I've assumed that you need 2 digits after ERROR_REPORT but your example name shows 3.

2 Comments

Thanks! I see. What about \d? Is \d the same as [0-9]?
Please ignore the question on \d.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.