how are you trying to use it?
That sql you provided doesn't have any "line counts" .. so where do you want to use the line count in that query ?
Edit:
oh wait ..
just noticed you changed your question part way through and I missed it
that gets a lot trickier ...
I'd probably use an external table pointing to the file, then just join with that table ... Are you using ORACLE ? or some other DB ? External tables are Oracle, other DB may have other tools for loading/peeking into files ...
Yes, look up SQL*Loader.
Again, Oracle related ... you should hop over to an Oracle forum to continue this question It's definitely an Oracle question, not unix.
Breakdown of:
ln_input number := nvl('&1',0);
'&1' ==> Captures the first parameter passed to the .sql script (ie the file count). Note, that this information is mostly useless to you, since you don't care how many rows are in the file, you just want to query a database table which matches each line in the file ...
nvl(<value>,0)
as mentioned by RudiC, if <value> is NULL or EMPTY (ie not provided), it uses the value "0" (numeric, not string).
Note that as written, it will then try to "convert" the string '&1' into a number.
If the input was "hello", then this will fail, since "hello" cannot convert to a number.
Again, however, after re-reading your original post ... this doesn't really help you at all You need External tables (preferred), or SQL*Loader if you can't use External Tables.
I am asking this question again here because seems like i am doing some mistake in unix part. please help me what i need to do now on this, why am facing issue, it is passing variable, but sqlplus is not executing it.
unix variables generally are not available within SQL.
You need to pass them in to use them ...
Again, I'd definitely handle this using SQLloader, or external tables, not via unix. Might work, but it'll be very difficult to maintain going forward. Using SQLloader or such will give you a very clean/robust solution.
regarding that paste command, I don't think that command is setup properly .. it doesn't look right. However, not being familiar with the paste command myself, I'm not sure how to suggest changing it.
Have you tried to do this via SQL*loader yet? I think you'll find it very very simple:
1) create a table to hold the incoming data in Oracle.
2) create a .ctl file mapping the data file to the table.
3) invoke sql*loader.
There, your data is in the database, run your query.
Well, that's why I suggested external tables first
But from a DB standpoint, I see the data as needed in the database, hence the load. Agreed, he didn't explicitly ask how to load it, but it's implied on how he wants to use the data.
As a learning experience, I tried playing with paste a bit based on those earlier posts, and couldn't get it working in Oracle, hence my comments on "still not sure about this"
Just going by what I know is a basic, and robust solution:
1) load data into a table.
2) use data in table in query.
since in Oracle, it's very "odd" to use data in a query "Directly" from a file (other than perhaps an external table).