reading files of exceuting and different directories them

D:\ > cd PROC_PKG_FUNC
Mkdir FUNCTION
Mkdir PACKAGES
mkdir PACKAGES_BODY
mkdir PROCEDURES
TYPES of mkdir
mkdir TYPES_BODY

SQL > create directory as "D:\PROC_PKG_FUNC\FUNCTIONS" FEATURES

Created directory.

SQL > create PACKAGES directory as 'D:\PROC_PKG_FUNC\PACKAGES ';

Created directory.

SQL > create directory as "D:\PROC_PKG_FUNC\PROCEDURES" PROCEDURES

Created directory.

SQL > create directory PACKAGES_BODY as 'D:\PROC_PKG_FUNC\PACKAGES_BODY ';

Created directory.

SQL > create new TYPES of directory as 'D:\PROC_PKG_FUNC\TYPES ';

Created directory.

SQL > create directory TYPES_BODY as 'D:\PROC_PKG_FUNC\TYPES_BODY ';

Created directory.

Suppose that,
There is a directory D:\PROC_PKG_FUNC in my local computer where the database server exists.
And in this directory there are different directories such PACKAGES, PACKAGES_BODY, PROCEDURES, TYPES, FUNCTIONS, TYPES_BODY, now, I created all remote objects to diagrams in these folders with utl_file, with the help of the following package

SQL > CREATE or REPLACE PROCEDURE Get_Db_Ddl_Scripts as
2 v_file Utl_File.FILE_TYPE;
3 v_file_dir VARCHAR2 (50);
4 i_first_line NUMBER: = 1;
5 BEGIN
6
7 v_file_dir: = "PROC_PKG_FUNC";
8
9. FOR REC_OBJ IN
10 (SELECT DISTINCT NAME, TYPE, DECODE (TYPE, 'FUNCTION', 'FEATURES, 'PACKAGE' ', PA))
CKAGES', 'PACKAGE BODY', 'PACKAGES_BODY', 'PROCEDURE', ' PROCEDURES, 'TYPE', 'TYPES ', '.
BODY of TYPE ',' TYPES_BODY') v_file_dir
11. FROM ALL_SOURCE@FRISKDEVI41B_ORCL WHERE OWNER = 'FRISKDEVI41B. '
12 AND TYPE ('FUNCTION, PROCEDURE, 'PACKAGE ', ' PACKAGE BODY', ' TYPE'))
LOOP 13
14 v_file: = Utl_File.FOPEN (card = > REC_OBJ.v_file_dir,)
15 filename = > REC_OBJ.NAME | ".sql",.
16 open_mode = > 'w ',.
max_linesize 17 = > 32767);
18 i_first_line: = 1;
19. FOR REC IN (SELECT TEXT FROM ALL_SOURCE@FRISKDEVI41B_ORCL WHERE NAME = REC_
OBJ.NAME AND TYPE = REC_OBJ. TYPE AND OWNER = 'FRISKDEVI41B' ORDER BY LINE)
LOOP 20
21 IF i_first_line = 1 THEN
22 Utl_File.PUT_LINE (v_file, "CREATE or REPLACE" |) REPLACE (REC. TEXT, CHR (10), N)
ULL));
23 ELSE Utl_File.PUT_LINE (v_file, REPLACE (REC. TEXT, CHR (10), NULL));
24 END IF;
25 i_first_line: = i_first_line + 1;
26 END OF LOOP;
27 Utl_File.FCLOSE (v_file);
28
29 END LOOP;
30
ENDS 31;
32.

Created procedure.

SQL > exec Get_Db_Ddl_Scripts;

PL/SQL procedure successfully completed.

So the files are created in the location.

now I want to do, is I want to read each file and run in my current schema to create these objects in my local, is - scehma it possible? Help needed. _

ORCHYP wrote:
Once these files are written in the respective folders, you can open them with utl_file('read') in the current schema, and very well you can run.
Try it once

Try as many times as you want, you will not run files with utl_file, that's for sure. ?:|

Using something like DBMS_SCHEDULER you a one off job for each script, issue that this package can call commands of the o/s.

However, what is the point?

In the code above, you can only accumulate your DDL commands or anyone within your code and, rather than write scripts, use the EXECUTE IMMEDIATE command to run the DDL on the database.

Of course may not be the best thing to do, but we have very little information about what it is that is trying to achieve, and no reason why all functions, packages etc. are not just put together in a single script that is run from the command line in the first place. Why try and write PL/SQL to do?

Tags: Database

Similar Questions

Maybe you are looking for