how do you write sql queries using shell script
for eg:- we have databae table like EMPNO,ENAME,SAL,DEPTNO
columns in EMP table how you display EMPNO,SAL FIELDS from emp
in SHELL SCRIPT please explain with an example

Answer Posted / krishna

create a variable for your query like

sql1='select empid,empname,.... from emp;' in your script

then call sqlplus in your shell script as

slplus user/password@sql1

you can redirect the output or format it as you like.

you can pass userid pwd as parameters as arguments to your
shell script and use them as parameters $1 and $2. you can
check if all the parameters are given with Usage [$# eq. 2 ]
etc.

Is This Answer Correct ?    8 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the different types of variables used in shell script?

555


Write a shell script to get current date, time, user name and current working directory.

638


What is the difference between scripting and coding?

541


How to redirect both standard output and standard error to the same location?

635


How to calculate the number of passed arguments?

556






Calculate a real number calculation directly from the terminal and not any shell script.

659


How do I debug a shell script?

568


Given a file find the count of lines containing the word "abc".

961


How to get the last line from a file using just the terminal?

672


What are the various stages of a linux process it passes through?

627


How can you find out how long the system has been running?

530


How do you find out What is your shell?

592


What are the advantages of shell script?

524


What does it mean to debug a script?

573


What does $$ mean in shell script?

588