Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

The Good 'ol How do I read an OS filename into SQL question?

819570Jan 25 2011 — edited Jan 26 2011
Hi,

We're using Oracle 11.1.0.7.

I need to load a file into a variable and insert it into an Oracle db.

We want to capture the OS file name with the date in it (eg. 'fillename_12152010.txt'), parse out the date in the file name and load that in to an oracle table using a shell script.

I'm looking for the easiest way to do this using SQL.

This is the best I came up with was the following. It's just a proof of concept script.

I'm just trying to pass a variable value into SQL from the shell script.
I can't get it to work.
As you can see I've 'rigged' it from an example I've copied.

I'm having problems with storing the file name I found into a variable that can be passed into SQL*.

How can I manipulate the 'var' variable to read the 'ls' data?

Anybody?
echo $PROGRAM_NAME - get

export user="scott"
export pass="tiger"

export var="$1"

ls *tcebbx1.sh > var

echo $var
#> var

sqlplus -S $user/$pass@ARAD1 <<EOF

   SELECT $var FROM dual;
   SELECT 'Chicago' FROM dual;
 --SELECT * FROM tableName WHERE username=$var;
 exit;
 
EOF
* All logins, passwords and database names have been changed because it's just plain common sense.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 23 2011
Added on Jan 25 2011
5 comments
469 views