Thursday, March 30, 2006

Insert from list of values

The following link from asktom has a beautiful way of inserting a list of values direclty into a table with just one insert statement

Click Here


In this technique rownum column is used to restrict the number of output rows retrived.

Wednesday, March 22, 2006

Date in Sqlldr

When loading date formats through sqlldr you can use to_date function. See the example below
LOAD DATA
INFILE data.csv
BADFILE data.bad
DISCARDFILE data.dsc
TRUNCATE INTO TABLE external_id_equip_map
Fields terminated by "," Optionally enclosed by '"'
TRAILING NULLCOLS
(EXTERNAL_ID, SUBSCR_NO, SUBSCR_NO_RESETS, EXTERNAL_ID_TYPE, ACCOUNT_NO, SERVER_ID,
ACTIVE_DATE "to_date(:active_date , 'dd/mm/yyyy')",
INACTIVE_DATE)
BEGINDATA
55349067007,77815573,0,1,77810573,7,31/05/2002
vw-audi-special,77815573,0,3,77810573,7,31/05/2002
77815573,77815573,0,2,77810573,7,31/05/2002

If there are multiple formats in the input data then you can define a custom function and use that function instead of to_date.
Refer to the following link for more details

http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:1365403168188

Thursday, March 09, 2006

Unable to connect 10g database from 8i clinet.

I had oracle 8i client already installed on my machine and then i installed 10g database on my machine and then tried to connect to the 10g database but couls not connect to it. Before that i set my 8i bin folder in the system path variable prior to the 10g bin folder in. After this i was not able to connect through SQL PLUS(though Oracle cleint not command prompt) and through TOAD to the local database. When i tried to reconfigure my tnsnames through tnsnames it hanges. Then i replaced the existing tnsnames with one from a different machine and tries to reconfigure it. -- Lesson "Dont ever try to reconfigure tnsnames manually. Go through Net Configuration Assistant".
Even after configuring through Net configuration Assistant and the connection test being successfull there i was not able to connect.
Then befoer connecting though cmd i set the variable as -- set ORACLE_SID = XE. Then it worked on cmd.
Then i created a new system variable ORACLE_SID and then assigned a value of the SID to it. Idea from this site http://www.cryer.co.uk/brian/oracle/ORA12560.htm
then it worked for sqlplus. For toad i had to give a differnt connet sting to the database similar to the one in the tnsnames file.