Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Hiroki.

Asked: January 22, 2024 - 11:19 pm UTC

Last updated: January 23, 2024 - 8:02 am UTC

Version: Unknown

Viewed 1000+ times

You Asked

I would like to copy an existing package and create a new package.

copy RPT and create RPT2.

Can you please show me how to do that?

Thank you for your support.

Hiroki

and Connor said...

There is not native copy facility, but it is easy to do.

DBMS_METADATA can give you the original source, and you just change the name to whatever you want

SQL> select DBMS_METADATA.GET_DDL('FUNCTION','REMOVE_CONSTANTS')
  2  from dual;

DBMS_METADATA.GET_DDL('FUNCTION','REMOVE_CONSTANTS')
---------------------------------------------------------------------------------------------------------------

  CREATE OR REPLACE EDITIONABLE FUNCTION "MCDONAC"."REMOVE_CONSTANTS" ( p_query in varchar2 ) return varchar2
as
    l_query long;
    l_char  varchar2(1);
    l_in_quotes boolean default FALSE;
begin
    for i in 1 .. length( p_query )
    loop
        l_char := substr(p_query,i,1);
        if ( l_char = '''' and l_in_quotes )
        then
            l_in_quotes := FALSE;
        elsif ( l_char = '''' and NOT l_in_quotes )
        then
            l_in_quotes := TRUE;
            l_query := l_query || '''#';
        end if;
        if ( NOT l_in_quotes ) then
            l_query := l_query || l_char;
        end if;
    end loop;
    l_query := translate( l_query, '0123456789', '@@@@@@@@@@' );
    for i in 0 .. 8 loop
        l_query := replace( l_query, lpad('@',10-i,'@'), '@' );
        l_query := replace( l_query, lpad(' ',10-i,' '), ' ' );
    end loop;
    return upper(l_query);
end;



Rating

  (1 rating)

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library