Monday, September 10, 2012

File Name from Folder Path

How do you retrive the file name from the folder Name from Folder path:

flname := 'C:\Folder1\SubFolder1\SubFolder3\MyTest.xls';
SELECT substr(flname, instr(flname, '\', -1) + 1) FROM dual;

Output will be
MyTest.xls

Thursday, September 6, 2012

SQL Loader

All you need is CTL file, data file and the table to put in the data

Control File (Test.ctl)

LOAD DATA
TRUNCATE
INTO TABLE EMP
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS
(
emp_id "trim(:emp_id)",
emp_name "trim(:emp_name)",
emp_dept "trim(:emp_dept)"
)

Data file would be (Test.csv)

emp_id,emp_name,emp_dept
1,John,10
2,Jane,30

Go to the command Prompt and type

C:\ >sqlldr.exe userid=scott/tiger@oradb control=c:\sqldrtest\TEST.ctl log= c:\sqldrtest\20110922.LOG bad= c:\sqldrtest\20110922.BAD data= c:\sqldrtest\Test.csv errors=1000

SQL*Loader: Release 10.2.0.4.0 - Production on Thu Sep 22 11:08:02 2011

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

Commit point reached - logical record count 2

It is always a good practice to have Errors=0, so that the file does not get processed even if there is one error