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

  • SEARCH
  • Home
  • 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 7930395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:24:26+00:00 2026-06-03T20:24:26+00:00

I want to iterate through all columns to find and replace a specific character.

  • 0

I want to iterate through all columns to find and replace a specific character. here is my pl/sql block:

 Declare
  match_count     Number:=0;
  v_search_string VARCHAR2(4000) := '%ي%';
BEGIN
 FOR t IN
 (SELECT owner,
  table_name,
column_name
FROM all_tab_columns
 WHERE (SUBSTR(table_name,1,2)='PN'
OR (SUBSTR(table_name,1,2)   ='CD'
AND owner                    ='PNET_USER' ))
AND (data_type               ='VARCHAR2'
OR data_type                 ='CLOB')
)
LOOP
BEGIN
  EXECUTE IMMEDIATE 'SELECT count(*) FROM '||t.owner || '.' || t.table_name|| ' WHERE '||t.column_name||' LIKE :1' INTO match_count USING v_search_string;
  IF match_count > 0 THEN
    dbms_output.put_line( t.owner || '.' || t.table_name ||' '||t.column_name||' '||match_count );
    --EXECUTE IMMEDIATE 'UPDATE '||t.table_name||' SET '||t.column_name||'=replace()'
  END IF;
END;
END LOOP;

It works fine and prints the name of columns that have the invalid characters. But I don’t know how to replace the characters. How can i get the value of t.column_name , replace the invalid character and then update the t.table_name ?

  • 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-06-03T20:24:28+00:00Added an answer on June 3, 2026 at 8:24 pm

    Well it was almost fine (and stevo’s answer also). I let you change v_from and v_to with your chars.

    Declare
      match_count     Number       :=0;
      v_from          varchar2(5)  := 'a';
      v_like          varchar2(5)  := '%'||v_from||'%';
      v_to            varchar2(5)  := 'b';
      v_sql           varchar2(1000);
      v_emesg         varchar2(1000);
    
      CURSOR s is
            (SELECT owner, table_name, column_name
            FROM    all_tab_columns
            where   SUBSTR(table_name,1,2)    IN ('PN', 'CD')
            AND     owner                     ='PNET_USER' 
            AND     data_type                 IN('VARCHAR2', 'CLOB'););
    begin       
    for t in s  LOOP
         begin
          EXECUTE IMMEDIATE 'SELECT count(*) FROM '||t.owner || '.' || t.table_name|| ' WHERE '||t.column_name||' LIKE :1' INTO match_count USING v_like;
          IF match_count > 0 THEN
                begin
                dbms_output.put_line( t.owner || '.' || t.table_name ||' '||t.column_name||' '||match_count );
                v_sql := 'UPDATE '||t.owner||'.'||t.table_name||' SET '||t.column_name||'= REPLACE('||t.column_name||', '''||v_from||''', '''||v_to||''') WHERE '||t.column_name||' LIKE '''|| v_like||'''';
                dbms_output.put_line(v_sql);
    
                EXECUTE IMMEDIATE v_sql;
                EXCEPTION WHEN OTHERS THEN
                   v_emesg := SQLERRM;
                   dbms_output.put_line(v_emesg);
                   dbms_output.put_line('Errow while trying to update '||t.owner||'.'||.t.table_name||' : column '||t.column_name||'.';
                END;
          END IF;
          end;
      END LOOP;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to iterate through all 5 character combinations of 0-9, a-z. I worked
I want to iterate through all loaded shared libraries and get their base addresses
At my template, I want to iterate through all form errors, including the ones
I want to iterate through store and make grid columns dynamically. When I use
I want to iterate through all nodes in an XML file and print their
I want to iterate through all the equipment in a drawing and get the
I want to iterate through a table/view and then kick off some process (e.g.
I have written the following code in Perl. I want to iterate through a
I have a grouped UITableView with many sections, however, I want to iterate through
I have a FormCollection and I just want to only iterate through the keys

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.