(1st Method)
set colsep ','
set pagesize 0
set feedback off
set trimspool on
set linesize 1000
spool myfile.csv
select * from mytable;
spool off
(2nd Method)
create or replace function dump_csv( p_query in varchar2,
p_separator in varchar2
default ',',
p_dir in varchar2 ,
p_filename in varchar2 )
return number
AUTHID CURRENT_USER
is
l_output utl_file.file_type;
l_theCursor integer default dbms_sql.open_cursor;
l_columnValue varchar2(2000);
l_status integer;
l_colCnt number default 0;
l_separator varchar2(10) default '';
l_cnt number default 0;
begin
l_output := utl_file.fopen( p_dir, p_filename, 'w' );
dbms_sql.parse( l_theCursor, p_query, dbms_sql.native );
for i in 1 .. 255 loop
begin
dbms_sql.define_column( l_theCursor, i,
l_columnValue, 2000 );
l_colCnt := i;
exception
when others then
if ( sqlcode = -1007 ) then exit;
else
raise;
end if;
end;
end loop;
dbms_sql.define_column( l_theCursor, 1, l_columnValue,
2000 );
l_status := dbms_sql.execute(l_theCursor);
loop
exit when ( dbms_sql.fetch_rows(l_theCursor) <= 0 );
l_separator := '';
for i in 1 .. l_colCnt loop
dbms_sql.column_value( l_theCursor, i,
l_columnValue );
utl_file.put( l_output, l_separator ||
l_columnValue );
l_separator := p_separator;
end loop;
utl_file.new_line( l_output );
l_cnt := l_cnt+1;
end loop;
dbms_sql.close_cursor(l_theCursor);
utl_file.fclose( l_output );
return l_cnt;
end dump_csv;
/
You would use that for example like this:
create or replace procedure test_dump_csv
as
l_rows number;
begin
l_rows := dump_csv( 'select *
from all_users
where rownum < 25',
',', '/tmp', 'test.dat' );
end;
/
Having 17 year of experince in variety of field including 14 year as IT and As a Oracle DBA Having 7 year of Experince With PT , Backup and Recovery , Database Migration (sql to ORACLE ),Creating Stand By Database. New Projects Installation. Have experice in any kind of Trouble shooting in Database. Knowledge of RAC and Dataguard. Financial prospective of projects and cost reduction
Friday, September 11, 2009
Wednesday, June 24, 2009
To Calculate Diff. Shared memory by Oracle Process
SELECT
'PGA: pid '||p.spid pid,p.pga_alloc_mem bytes,
p.username ps_user,p.program ps_program,
s.logon_time,s.sid,s.serial#,s.username,s.machine,s.osuser,s.program
FROM v$session s ,v$sesstat pcur,v$process p WHERE pcur.statistic#=20 AND s.paddr=p.addr AND pcur.sid=s.sid
UNION ALL SELECT 'SGA: '||name pid,value bytes,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL FROM v$sga
ORDER BY 2 DESC
'PGA: pid '||p.spid pid,p.pga_alloc_mem bytes,
p.username ps_user,p.program ps_program,
s.logon_time,s.sid,s.serial#,s.username,s.machine,s.osuser,s.program
FROM v$session s ,v$sesstat pcur,v$process p WHERE pcur.statistic#=20 AND s.paddr=p.addr AND pcur.sid=s.sid
UNION ALL SELECT 'SGA: '||name pid,value bytes,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL FROM v$sga
ORDER BY 2 DESC
Thursday, April 23, 2009
How to Create RMAN Catalog
To create the recovery catalog schema in the recovery catalog database:
Start SQL*Plus and then connect with administrator privileges to the database containing the recovery catalog. For example, enter:
1) sql> CONNECT SYS/oracle@catdb AS SYSDBA
Create a user and schema for the recovery catalog. For example, enter:
sql > CREATE USER rman IDENTIFIED BY cat
TEMPORARY TABLESPACE temp
DEFAULT TABLESPACE tools
QUOTA UNLIMITED ON tools;
*************************************
Grant the Permission as mention below.
**************************************
sql> GRANT RECOVERY_CATALOG_OWNER TO rman;
sql> grant connect , resource to rman;
**************************************
Now Create Catalog
**************************************
RMAN> CONNECT CATALOG rman/cat@catdb
RMAN> CREATE CATALOG TABLESPACE cat_ts;
**************************************
SQL> SELECT TABLE_NAME FROM USER_TABLES;
Start SQL*Plus and then connect with administrator privileges to the database containing the recovery catalog. For example, enter:
1) sql> CONNECT SYS/oracle@catdb AS SYSDBA
Create a user and schema for the recovery catalog. For example, enter:
sql > CREATE USER rman IDENTIFIED BY cat
TEMPORARY TABLESPACE temp
DEFAULT TABLESPACE tools
QUOTA UNLIMITED ON tools;
*************************************
Grant the Permission as mention below.
**************************************
sql> GRANT RECOVERY_CATALOG_OWNER TO rman;
sql> grant connect , resource to rman;
**************************************
Now Create Catalog
**************************************
RMAN> CONNECT CATALOG rman/cat@catdb
RMAN> CREATE CATALOG TABLESPACE cat_ts;
**************************************
SQL> SELECT TABLE_NAME FROM USER_TABLES;
Thursday, April 9, 2009
Oracle Database Upgrade Path Reference List
Note ID = 730365.1
https://metalink.oracle.com/CSP/main/article?cmd=show&type=NOT&id=730365.1#aref43
https://metalink.oracle.com/CSP/main/article?cmd=show&type=NOT&id=730365.1#aref43
Thursday, March 19, 2009
Window Backup Deletion script will delete when Database is open only
test.sql=
spool test.txt
set head off
set term off
set feed off
select status from v$instance;
spool off
exit
=
test.bat=
sqlplus/********@DBNAME @test.sql
TIMEOUT 4
IF EXIST test.txt (
FOR /F " skip=1 delims== " %%i in (test.txt) do (set t1=%%i)
del test.txt
SET DIRPATH=I:\TEST_BACKUP
) ELSE (exit)
IF %t1% EQU OPEN (
I:
cd %DIRPATH%
del DB_NAME_export_old.dmp
del DB_NAME_export_old.log
rename DB_NAME_export.dmp DB_NAME_export_old.dmp
rename DB_NAME_export.log DB_NAME_export_old.log
exp/********@DBNAME file=%DIRPATH%\DB_NAME_export.dmp log=%DIRPATH%\DB_NAME_export.log owner=ABC
)
=
spool test.txt
set head off
set term off
set feed off
select status from v$instance;
spool off
exit
=
test.bat=
sqlplus
TIMEOUT 4
IF EXIST test.txt (
FOR /F " skip=1 delims== " %%i in (test.txt) do (set t1=%%i)
del test.txt
SET DIRPATH=I:\TEST_BACKUP
) ELSE (exit)
IF %t1% EQU OPEN (
I:
cd %DIRPATH%
del DB_NAME_export_old.dmp
del DB_NAME_export_old.log
rename DB_NAME_export.dmp DB_NAME_export_old.dmp
rename DB_NAME_export.log DB_NAME_export_old.log
exp
)
=
Monday, February 9, 2009
Spfile & pfile lost : How to recreate this
1) show spfile will give if you started with a spfile or a init.ora file. You can't know which init.ora was used.
2) Here's a script:
Set linesize 1000
Set feedback off
Set pagesize 0
Col instance_name noprint new_value inst_
Set termout off
Select instance_name from v$instance;
Set termout on
Spool init&inst_..ora
select '
'||'######################################################################
'||'#
'||'# file : init&inst_..ora
'||'# date : '||to_char(sysdate,'DD/MM/YYYY HH24:MI:SS')||'
'||'#
'||'######################################################################
'||'
' from dual
/
Select '# '||name||': '||description||'
'||decode(update_comment,NULL,'','# '||update_comment||'
')||name||' = '||decode(sign(instr(value,' ')),
1,'("'||replace(value,', ','", "')||'")',
value)||'
'||'
'
from v$system_parameter
where isdefault = 'FALSE'
order by name
/
Spool off
2) Here's a script:
Set linesize 1000
Set feedback off
Set pagesize 0
Col instance_name noprint new_value inst_
Set termout off
Select instance_name from v$instance;
Set termout on
Spool init&inst_..ora
select '
'||'######################################################################
'||'#
'||'# file : init&inst_..ora
'||'# date : '||to_char(sysdate,'DD/MM/YYYY HH24:MI:SS')||'
'||'#
'||'######################################################################
'||'
' from dual
/
Select '# '||name||': '||description||'
'||decode(update_comment,NULL,'','# '||update_comment||'
')||name||' = '||decode(sign(instr(value,' ')),
1,'("'||replace(value,', ','", "')||'")',
value)||'
'||'
'
from v$system_parameter
where isdefault = 'FALSE'
order by name
/
Spool off
Wednesday, February 4, 2009
Audit Trail
Auidt trail details from drop any table .
and
Audit table;
http://www.dbasupport.com/forums/showthread.php?t=20054
and
Audit table;
http://www.dbasupport.com/forums/showthread.php?t=20054
Subscribe to:
Posts (Atom)