28 April 2010

Renaming an Oracle database

The following log shows how a database name was renamed from ORA9 to CAT.
SQL> select name from v$database;

19 April 2010

Oracle hash function

use of function
select dbms_utility.get_hash_value('your string', 999999, 32768) from dual

05 April 2010

Oracle read/write into file

Write to file
declare
  output utl_file.file_type;
  line   varchar2(20000);
begin
--  execute immediate 'alter session set NLS_CHARACTERSET = CL8MSWIN1251';
  output := utl_file.fopen(location => 'directory_name', filename => to_char(sysdate, 'file_name', open_mode => 'A');
  for rec in
    ()
  loop
    line := rec.field1|| '|' || rec.field2 || '|' || rec.field3 || '|' || rec.field4 || '|' || rec.field5;
    utl_file.put(output, line); 
    utl_file.new_line(file => output);
  end loop;
  utl_file.fclose(file => output);
end;


12 March 2010

Tkprof

TKPROF: Yes, it is still used but the FOREGROUND_DUMP_DEST is no longer
used. There is info in the Oracle docs on this. Here is the syntax:

04 March 2010

Восстановить удаленную процедуру в Oracle и т.п.
select text
from dba_source as of timestamp (systimestamp - interval '3' hour) -- interval '5' minute)
where owner =
   and name =
   and type = 'PACKAGE' --'FUNCTION', 'PROCEDURE'
order by name
        , type
        , line;

01 March 2010

Example of how to trace a session and use tkprof

Enable trace for a user session:
SQLPLUS> exec sys.dbms_system.set_sql_trace_in_session(SID, SERIAL, true);
Use tkprof to analyze the trace file:
tkprof [TRACE FILE] [OUTPUT FILE] explain=/ sort=prsela,exeela,fchela
table=ops\$oracle.plan_table 
 

26 February 2010

DB Link
create link on db1 side to db2
If global_name = true then let's db1 has global_name='db1' and db2 has global_name='db2' then dblink name = 'db2'.

alter system set global_names=True
ALTER DATABASE RENAME GLOBAL_NAME TO db_name