Thursday, September 6, 2012

'WRAP' function with 'EXECUTE IMMEDIATE'

1) Suppose My procedure name is vnk_proc. Anybody can paste this in toad and press f4    and  can view the code(No security for the code).

2) In Sqlplus,the code will be stored in user_source table. IF I write this sql statement it will  display my code
         
        SELECT text FROM USER_SOURCE WHERE TYPE='PROCEDURE' AND NAME LIKE 'VNK_PROC'

3) In order to hide our code both in toad and sqlplus, we use the overloaded ‘WRAP’ function with ‘EXECUTE IMMEDIATE’.

DECLARE
vnk_procedure VARCHAR2(32767);
BEGIN
vnk_procedure := 'CREATE OR REPLACE PROCEDURE wrap_test54 '
||'IS '
||' v_airport_codes AIRPORT_LIST.AIRPORT_CODE%TYPE; '
||' '
||' CURSOR emp_cur IS '
||' SELECT empno''
||' FROM emp'
||' ORDER BY empno;'
||' '
||'BEGIN '
||' FOR y IN emp_cur LOOP '
||' DBMS_OUTPUT.PUT_LINE('Employee Number: ''||y.empno);'
||' END LOOP;'
|| 'END;';
EXECUTE IMMEDIATE DBMS_DDL.WRAP(vnk_procedure);
END;
/

4) TO see the wrapped procedure, select the text from the user_source view
SELECT TEXT FROM USER_SOURCE WHERE NAME = 'WRAP_TEST54';

5) DBMS_DDL.CREATE_WRAPPED works in a similar way. The following example
shows how it differs from the WRAP function.

DECLARE
VNK_PROCEDURE VARCHAR2(32767);
BEGIN
VVK_PROCEDURE := 'CREATE OR REPLACE PROCEDURE create_wrapped_test54 '
||'IS '
||' '
||' CURSOR emp_cur IS '
||' SELECT empno'
||' FROM emp'
||' ORDER BY empno;'
||' '
||'BEGIN '
||' FOR y IN emp_cur LOOP '
||' DBMS_OUTPUT.PUT_LINE(''Employee Number: ''||y.empno);'
||' END LOOP;'
|| 'END;';
SYS.DBMS_DDL.CREATE_WRAPPED(VNK_PROCEDURE);
END;

Export and Import Schemas

TO EXPORT

---------------
1     1)      In Command prompt:
                    C:\oraclexe\app>expdp SYSTEM/manager@XE  SCHEMAS=nani   DUMPFILE="xyz.dmp"

->It will store the dump file in ‘C:\oraclexe\app\oracle\admin\XE\dpdump’ location.

2      2)      In SQL Prompt
CREATE OR REPLACE DIRECTORY dmpdir AS 'c:\oraclexe\app\tmp';
GRANT READ,WRITE ON DIRECTORY dmpdir TO nani

C:\oraclexe\app>expdp SYSTEM/manager@XE SCHEMAS=nani DIRECTORY=dmpdir DUMPFILE="xyz.dmp"

->It will store the dump file in ‘C:\oraclexe\app\tmp’ location.


TO IMPORT

 --------------
Place the dump file in ‘C:\oraclexe\app\oracle\admin\XE\dpdump’ then
1    1)      In Command Prompt:
            C:\oraclexe\app>impdp system/manager@XE DUMPFILE=”XYZ.dmp”

Friday, May 4, 2012

SQL-LOADER:Loading TAB Delimited DATA which has null values

Loading TAB Delimited DATA which has null values

load data
infile *
append into table vnk_t11
fields terminated by X'09'
trailing nullcols
(
sno,
sname,
branch terminated by whitespace
)
BEGINDATA
1    nanikalyanvarasala    CSE
2        ECE
3    Johnny
4    Praveenkumar    EEE
    Bhadra    MECH

SQL-LOADER:Loading TAB Delimited DATA

Loading TAB Delimited DATA

load data
infile *
append into table vnk_t11
fields terminated by X'09'
trailing nullcols
(
sno,
sname,
branch terminated by whitespace
)
BEGINDATA
1    nanikalyanvar    CSE
2    kalyan    ECE
3    Johnny    IT
4    Praveenkumar    EEE
5    Bhadra    MECH

Friday, April 13, 2012

SQL-LOADER:Skip option

Skip

In order to skip the rows at the beginning of the flat file.We use skip option in the control file as shown below.
If I want to skip 5 rows i will give skip=5 in my control file then the first five rows of the flat file are skiped and remaining data will be loaded in the staging table.
 
FLAT FILE:
 1,"Nani","CSE","Final","A+"
2,"Indra Kanth","ECE","Final","B"
3,"Kalyan","CSE","Third","A"
4,"Praveen","IT","Third","B"
5,"Badra","ECE","Final","B+"
6,"Kali","EEE","Second","C"
7,"Giri","E&I","First","D"
8,"Sravan","MCA","Third","A"
9,"Pradeer","MCA","Second","D"
10,"Joe","CSE","Third","D+"

CONTROL  FILE:
Options (skip=n)    --First n rows will be skiped
load data
infile 'bin/flat_file_var.txt' --Give your flat file location
insert into table stu_data
fields terminated by ','
optionally enclosed by '"'
(
sno,
sname,
branch,
year,
grade
)

SQL-LOADER:Loading combined Physical Records

Loading Combined Physical Records

There may be chances that we get the data in which each row starts with a special character like '@','#','$' etc.Then we will have to use continueif to load the data from such kind of flat file into staging table.

There may be scenerios where we need to load two or three rows of the flat-file as a single row in the staging table then we will use Concatenate option to acheive that requirement.

USING CONTINUEIF:
load data
infile *
replace
continueif this (1)= '@'
into table vnk_emp
fields terminated by ','
optionally enclosed by '"'
trailing nullcols
(
c1,
c2,
c3,
c4 char terminated by whitespace
)
BEGINDATA
@1,2,
    3,4
@5,6,
    7,8

USING CONCATENATE:
load data
infile *
replace
concatenate 2
into table vnk_emp
fields terminated by ','
optionally enclosed by '"'
trailing nullcols
(
c1,
c2,
c3,
c4 
)
BEGINDATA
1,2,
3,4
5,6,
7,8

Staging table:
Create table vnk_emp(c1 number,
                                   c2 number,
                                   c3 number,
                                   c4 number
                                  )