15 February, 2010

Auto database backup from oracle (.bat)

set oracle_sid=orcl
setlocal
for /f "tokens=1-4 delims=/ " %%a in ('date /t') do set DATE=%%c-%%b-%%a
for /f "tokens=1-3 delims=: " %%a in ('time /t') do (
set hours=%%a
set minutes=%%b
set ampm=%%c
)
if {%ampm%}=={AM} if {%hours%}=={12} set hours=00
if {%ampm%}=={PM} (
for /f "delims=0 tokens=*" %%a in ("%hours%") do set hours=%%a
set /a hours+= 12
)
exp atlms2/atlms2@textilefac file=d:\atlmsfac_%date%_%hours%.%minutes%_%ampm%.dmp
log=d:\atlmsfac_%date%_%hours%.%minutes%_%ampm%.log full=y feedback=10000
buffer=2000000 statistics=none
exit

07 February, 2010

Function of String Split in Oracle

create or replace function str_split(the_list varchar2,the_index number,delim varchar2 := ',')
return varchar2
is
start_pos number;
end_pos number;
begin
if the_index = 1 then
start_pos := 1;
else
start_pos := instr(the_list, delim, 1, the_index - 1);
if start_pos = 0 then
return null;
else
start_pos := start_pos + length(delim);
end if;
end if;
end_pos := instr(the_list, delim, start_pos, 1);

if end_pos = 0 then
return substr(the_list, start_pos);
else
return substr(the_list, start_pos, end_pos - start_pos);
end if;
end str_split;
/

02 February, 2010

Extra Oracle command?

1.select *from tab;
---output all table name;
2.select OWNER,NAME,TYPE from dba_source
group by OWNER,NAME,TYPE order by OWNER,NAME,TYPE;
--owner=user name
--name= package name
--type=package type(TRIGGER, PROCEDURE, FUNCTION etc)