Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7446231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:16:07+00:00 2026-05-29T12:16:07+00:00

I have a column, which stores a 4 character long string with 4 or

  • 0

I have a column, which stores a 4 character long string with 4 or less wild characters (for eg. ????, ??01‘, 0??1 etc). For each such string like 0??1 I have to insert into another table values 0001 to 0991; for the string ??01, values will be be 0001 to 9901; for string ???? values will be 0000 to 9999 and so on.

How could I accomplish this using PL/SQL and string functions?

EDIT

The current code is:

declare 

  v_rule varchar2(50) := '????52132'; 
  v_cc varchar2(50); 
  v_nat varchar2(50); 
  v_wild number; 
  n number; 

begin 

  v_cc := substr(v_rule,1,4); 
  v_nat := substr(v_rule,5); 

  dbms_output.put_line (v_cc || ' '|| v_nat); 

  if instr(v_cc, '????') <> 0 then 
    v_wild := 4; 
  end if; 

  n := power(10,v_wild); 

  for i in 0 .. n - 1 loop 
    dbms_output.put_line(substr(lpad(to_char(i),v_wild,'0' ),0,4)); 
  end loop; 

end;
/
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T12:16:08+00:00Added an answer on May 29, 2026 at 12:16 pm

    Would something like the following help?

    BEGIN
      FOR source_row IN (SELECT rule FROM some_table)
      LOOP
        INSERT INTO some_other_table (rule_match)
          WITH numbers AS (SELECT LPAD(LEVEL - 1, 4, '0') AS num FROM DUAL CONNECT BY LEVEL <= 10000)
          SELECT num FROM numbers WHERE num LIKE REPLACE(source_row.rule, '?', '_');
      END LOOP;
    END;
    /
    

    This assumes you have a table called some_table with a column rule, which contains text such as ??01, 0??1 and ????. It inserts into some_other_table all numbers from 0000 to 9999 that match these wild-carded patterns.

    The subquery

    SELECT LPAD(LEVEL - 1, 4, '0') AS num FROM DUAL CONNECT BY LEVEL <= 10000)
    

    generates all numbers in the range 0000 to 9999. We then filter out from this list of numbers any that match this pattern, using LIKE. Note that _ is the single-character wildcard when using LIKE, not ?.

    I set this up with the following data:

    CREATE TABLE some_table (rule VARCHAR2(4));
    
    INSERT INTO some_table (rule) VALUES ('??01');
    INSERT INTO some_table (rule) VALUES ('0??1');
    INSERT INTO some_table (rule) VALUES ('????');
    COMMIT;
    
    CREATE TABLE some_other_table (rule_match VARCHAR2(4));
    

    After running the above PL/SQL block, the table some_other_table had 10200 rows in it, all the numbers that matched all three of the patterns given.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table which has column of descr which stores string values. Some
I have a table with a binary column which stores files of a number
I have an xml column which contain data like this: <AuthorList CompleteYN=Y> <Author ValidYN=Y>
I have an order table in MySQL database, having a field/column which stores the
i have a table with a column named CustomerName which stores a customer's full
I have a dataset which stores dates in a DataColumn (datatype of this column
I have a table, and there is no column which stores a field of
I have a DateTime which I want to store in a Date MySQL column.
I have a column which is of type nvarchar(max). How do I find the
I have a column which has a datatype : datetime. But now i want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.