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 7899907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:49:52+00:00 2026-06-03T08:49:52+00:00

I am still working on cleaning up Oracle files, having to replace strings in

  • 0

I am still working on cleaning up Oracle files, having to replace strings in files where the Oracle schema name is prepended to the function/procedure/package name within the file, as well as when the function/procedure/package name is double-quoted. Once the definition is corrected, I write the correction back to the file, along with the rest of the actual code.

I have code written to replace simple declarations (no input/output parameters) Now I am trying to get my regex to operate on (Note: This post is a continuation from this question) Some examples of what I’m trying to clean up:

Replace:

CREATE OR REPLACE FUNCTION "TRON2000"."DC_F_DUMP_CSV_MMA" (
p_trailing_separator IN BOOLEAN DEFAULT FALSE,
p_max_linesize IN NUMBER DEFAULT 32000,
p_mode IN VARCHAR2 DEFAULT 'w'
)
RETURN NUMBER
IS

to

CREATE OR REPLACE FUNCTION DC_F_DUMP_CSV_MMA (
p_trailing_separator IN BOOLEAN DEFAULT FALSE,
p_max_linesize IN NUMBER DEFAULT 32000,
p_mode IN VARCHAR2 DEFAULT 'w'
)
RETURN NUMBER
IS

I have been trying to use the following regex to separate the declaration, for later reconstruction after I’ve cleaned out the schema name / fixed the name of the function/procedure/package to not be double-quoted. I am struggling with getting each into a buffer – here’s my latest attempt to grab all the middle input/output into it’s own buffer:

\b(CREATE\sOR\sREPLACE\s(PACKAGE|PACKAGE\sBODY|PROCEDURE|FUNCTION))(?:\W+\w+){1,100}?\W+(RETURN)\s*(\W+\w+)\s(AS|IS)\b

Any / all help is GREATLY appreciated!

This is the script that I’m using right now to evaluate / write the corrected files:

#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
use Data::Dumper;

# utility to clean strings
sub trim($) {
    my $string = shift;
    $string = "" if !defined($string);

    $string =~ s/^\s+//;
    $string =~ s/\s+$//;

    # aggressive removal of blank lines
    $string =~ s/\n+/\n/g;
    return $string;
}

sub cleanup_packages {
    my $file = shift;
    my $tmp  = $file . ".tmp";
    my $package_name;

    open( OLD, "< $file" ) or die "open $file: $!";
    open( NEW, "> $tmp" )  or die "open $tmp: $!";

    while ( my $line = <OLD> ) {

  # look for the first line of the file to contain a CREATE OR REPLACE STATEMENT
        if ( $line =~
m/^(CREATE\sOR\sREPLACE)\s*(PACKAGE|PACKAGE\sBODY)?\s(.+)\s(AS|IS)?/i
          )
        {

            # look ahead to next line, in case the AS/IS is next
            my $nextline = <OLD>;

            # from the above IF clause, the package name is in buffer 3
            $package_name = $3;

             # if the package name and the AS/IS is on the same line, and
             # the package name is quoted/prepended by the TRON2000 schema name
            if ( $package_name =~ m/"TRON2000"\."(\w+)"(\s*|\S*)(AS|IS)/i ) {
                # grab just the name and the AS/IS parts
                $package_name =~ s/"TRON2000"\."(\w+)"(\s*|\S*)(AS|IS)/$1 $2/i;
                trim($package_name);
            }
            elsif (    ( $package_name =~ m/"TRON2000"\."(\w+)"/i )
                    && ( $nextline =~ m/(AS|IS)/ ) )
            {

# if the AS/IS was on the next line from the name, put them together on one line
                $package_name =~ s/"TRON2000"\."(\w+)"(\s*|\S*)/$1/i;
                $package_name = trim($package_name) . ' ' . trim($nextline);
                trim($package_name);    # remove trailing carriage return
            }

            # now put the line back together
            $line =~
s/^(CREATE\sOR\sREPLACE)\s*(PACKAGE|PACKAGE\sBODY|FUNCTION|PROCEDURE)?\s(.+)\s(AS|IS)?/$1 $2 $package_name/ig;

            # and print it to the file
            print NEW "$line\n";
        }
        else {

            # just a normal line - print it to the temp file
            print NEW $line or die "print $tmp: $!";
        }
    }

    # close up the files
    close(OLD) or die "close $file: $!";
    close(NEW) or die "close $tmp: $!";

    # rename the temp file as the original file name
    unlink($file) or die "unlink $file: $!";
    rename( $tmp, $file ) or die "can't rename $tmp to $file: $!";
}

# find and clean up oracle files
sub eachFile {
    my $ext;
    my $filename = $_;
    my $fullpath = $File::Find::name;

    if ( -f $filename ) {
        ($ext) = $filename =~ /(\.[^.]+)$/;
    }
    else {

        # ignore non files
        return;
    }

    if ( $ext =~ /(\.spp|\.sps|\.spb|\.sf|\.sp)/i ) {
        print "package: $filename\n";
        cleanup_packages($fullpath);
    }
    else {
        print "$filename not specified for processing!\n";
    }
}

MAIN:
{
    my ( @files, $file );
    my $dir = 'C:/1_atest';

    # grab all the files for cleanup
    find( \&eachFile, "$dir/" );

    #open and evaluate each
    foreach $file (@files)
    {
        # skip . and ..
        next   if ( $file =~ /^\.$/ );
        next if ( $file =~ /^\.\.$/ );
          cleanup_file($file);
      };
}
  • 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-03T08:49:53+00:00Added an answer on June 3, 2026 at 8:49 am

    Assuming the entire content of a file is stored as scalar in a var, the following should do the trick.

    $Str = '
    CREATE OR REPLACE FUNCTION "TRON2000"."DC_F_DUMP_CSV_MMA" (
        p_trailing_separator IN BOOLEAN DEFAULT FALSE,
        p_max_linesize IN NUMBER DEFAULT 32000,
        p_mode IN VARCHAR2 DEFAULT w
    )
    RETURN NUMBER
    IS
    
    CREATE OR REPLACE FUNCTION "TRON2000"."DC_F_DUMP_CSV_MMA" (
        p_trailing_separator IN BOOLEAN DEFAULT FALSE,
        p_max_linesize IN NUMBER DEFAULT 32000,
        p_mode IN VARCHAR2 DEFAULT w
    )
    RETURN NUMBER
    IS
    ';
    
    $Str =~ s#^(create\s+(?:or\s+replace\s+)?\w+\s+)"[^"]+"."([^"]+)"#$1 $2#mig;
    
    print $Str;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we have a J2EE app on which we're still working. It runs on Oracle
Hey i'm new to c++ and still working out its perticularities. I'm having the
Still working my way around this, but is there any function/command I can use
Still working on a problem that started from here Calling C++ dll function from
Still working through JQuery to get data and repopulate portions of a page. Right
Still working on lisp recipes and idioms. I have a list like this: ((a
I'm still working on my leaks problem and I don't know how to solve
I'm still working my way through some pretty basic Actionscript programming (in Flex), and
I'm still working on my little Tkinter project which is simple a logging console
I am still working with securing my web app. I decided to use PDO

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.