Home » SQL & PL/SQL » SQL & PL/SQL » query doubt (hp unix, oracle 10g)
query doubt [message #653412] Mon, 04 July 2016 21:24 Go to next message
arun888
Messages: 100
Registered: June 2015
Location: INDIA
Senior Member
Hi ,

Input will be changed dynamically everytime in the input file. I am not sure how to write a script reading the input from the text file.
Any help would be appreciated.

Input :
shome/klos>cat input.txt
100
150
200
600


select * from employee where employee_no in ( 100,150,200,600).

Re: query doubt [message #653413 is a reply to message #653412] Mon, 04 July 2016 21:37 Go to previous messageGo to next message
arun888
Messages: 100
Registered: June 2015
Location: INDIA
Senior Member
i have tried the below is this correct.

args="$( cat input.txt )"
sqlplus -s user/pass@inst << EOF
select *from employee
where employee_in IN ( $args );
exit
EOF

[Updated on: Mon, 04 July 2016 21:37]

Report message to a moderator

Re: query doubt [message #653415 is a reply to message #653413] Tue, 05 July 2016 00:38 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9088
Registered: November 2002
Location: California, USA
Senior Member
If the input.txt file is on your server, or you can move it there, then you can create an external table and use that. You only need to create the external table once, then any time that you overwrite the data in the input.txt file, the data in the table changes. The external table is just a pointer to whatever is in the file. Please see the demonstration below.

-- contents of c:\my_oracle_files\input.txt
SCOTT@orcl_12.1.0.2.0> host type input.txt
100
150
200
600

-- oracle directory object:
SCOTT@orcl_12.1.0.2.0> create or replace directory my_dir as 'c:\my_oracle_files'
  2  /

Directory created.

-- external table:
SCOTT@orcl_12.1.0.2.0> create table input_tab
  2    (input_col  number)
  3  organization external
  4    (type oracle_loader
  5     default directory my_dir
  6     access parameters
  7       (records delimited by newline
  8        fields terminated by whitespace
  9          (input_col))
 10     location ('input.txt'))
 11  reject limit unlimited
 12  /

Table created.

-- query:
SCOTT@orcl_12.1.0.2.0> select employee_id, first_name, last_name
  2  from   hr.employees
  3  where  employee_id in (select input_col from input_tab)
  4  /

EMPLOYEE_ID FIRST_NAME           LAST_NAME
----------- -------------------- -------------------------
        100 Steven               King
        150 Peter                Tucker
        200 Jennifer             Whalen

3 rows selected.
Re: query doubt [message #653416 is a reply to message #653415] Tue, 05 July 2016 00:43 Go to previous messageGo to next message
arun888
Messages: 100
Registered: June 2015
Location: INDIA
Senior Member
i have tried the below.

Only problem is i am not getting proper csv format in email.

Any help would be appreciated.

#!/bin/ksh
rm sqlout.txt
args="$( cat input.txt )"
sqlplus -s syora/syora@testdb <<ENDSQL
set trimout on
set trimspool on
set feedback off
set linesize 255
set heading off
spool sqlout.csv
select employee_id, first_name, last_name  from   hr.employees where  employee_id in ($args)
spool off;
exit
ENDSQL
uuencode sqlout.csv sqlout.csv | mailx -m -s "output" ramesh@xxx.com
Re: query doubt [message #653417 is a reply to message #653416] Tue, 05 July 2016 00:43 Go to previous message
arun888
Messages: 100
Registered: June 2015
Location: INDIA
Senior Member
Thanks for your reply barbara.

Your feedback helps me to learn new thing today.
Previous Topic: SQL problem - variation on top-n-of-group. DDL and DML supplied.
Next Topic: Oracle reports
Goto Forum:
  


Current Time: Fri Apr 19 17:21:29 CDT 2024