Oracle SQL to extract Directory from filename

Recently, I had a requirement to extract just the directory name from a file name. The code snipped provided below does just that.

 select substr(:1,1,instr(:1,:2,-1)) FROM DUAL; 

where :1 is the full file name(along with the path)

:2 is the directory separator

For instance,

 select substr('D:\Sample\Mani.txt',1,instr('D:\Sample\Mani.txt','\',-1)) FROM DUAL; 

This code would strip off the file name and return just the directory


Have fun. 🙂


About Manikandan Surendren

A PeopleSoft Techno-functional Consultant. An engineering graduate in Computer Science. Technology Enthusiast. Movie freak. Gadget geek.
This entry was posted in Code, Oracle, SQL and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s