Archive for the 'Database' Category

How to add days, hours or minutes to a date

August 25th, 2010

Now
SYSDATE

Tomorow/ next day
SYSDATE + 1

Seven days from now
SYSDATE + 7

One hour from now
SYSDATE + 1/24

Three hours from now
SYSDATE + 3/24

An half hour from now
SYSDATE + 1/48

10 minutes from now
SYSDATE + 10/1440

1 minute from now
SYSDATE + 1/1440

Tomorrow at 12 midnight
TRUNC(SYSDATE + 1)

Tomorrow at 10 AM
TRUNC(SYSDATE + 1) + 10/24

Reset SYSTEM password

August 1st, 2010

For the ones who wants to reset the SYSTEM pwd:
operfcfg.exe -U SYSTEM -P password -D tns_entry_name

max(ROWID) => something to remember

April 22nd, 2010

Sometimes we forget some basic concepts. So do I (sometimes).
To retrieve the latest record of a table it’s not ALWAYS correct to use the max(rowid) of a table.
The rowid is an ID generated based on file/block/slot .
The only method to make sure we take the last record is a having a column with a timestamp [...]

SQL*LOADER control file generator

March 26th, 2010

set echo off ver off feed off pages 0
accept tname prompt ‘Enter Name of Table: ‘
accept dformat prompt ‘Enter Format to Use for Date Columns: ‘
spool &tname..ctl
select ‘LOAD DATA’|| chr (10) ||
‘INFILE ”’ || lower (table_name) || ‘.dat”’ || chr (10) ||
‘INTO TABLE ‘|| table_name || chr (10)||
‘FIELDS TERMINATED BY ”,”’||chr (10)||
‘TRAILING NULLCOLS’ || chr [...]

Select ‘X’ faster then Select 1

January 23rd, 2009

What somebody at Oracle Belgium told me once 10 years ago, I retested it on Oracle 10R2.
A Select ‘X’ is faster then a Select 1.
Stop dreaming because it’s only slightly faster.
see here the tests I did

SET time ON
SET timing ON
 
declare
v_n number;
v_c varchar2(1);
begin
FOR i IN 1..1000000 loop
SELECT ‘X’ INTO v_c FROM dual;
end loop;
end;
/
 
declare
[...]

direct path write temp

December 23rd, 2008

Had a query which took ages. After checking the session browser I noticed the query was doing a lot of “direct path write temp”. So I checked directly the sort_area_size. Big surprise it had a value of 64K!!!
After sending a mail to the DBA’s of my current project to ask to increase to 1GB, everything [...]

How to list the installed patches on Oracle?

October 21st, 2008

Use Opatch.
Look in the Opatch directory in Oracle Home.
‘opatch query -all’ will allow you to query detailed information about a patch.
‘opatch lsinventory’ will list all patches with the applied date chronologically.
‘opatch lsinventory -detail’ will list all patches and which files were modified.

Sql*plus doesn’t commit at end or does it?!?

July 29th, 2008

A collegue of mine had to debug all his code, twice, to try to find why one of his tables wasn’t populated.
Here is why: He asked to execute a script (script didn’t contained a commit statement) in sql*plus at someone of the production team. That guy opened sql*plus, executed the script and closed window (File>Exit) [...]