Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Answers were Sorted based on User's Feedback



how do you write sql queries using shell script for eg:- we have databae table like EMPNO,ENAME,SA..

Answer / 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

how do you write sql queries using shell script for eg:- we have databae table like EMPNO,ENAME,SA..

Answer / nitesh bhope

sqlplus username/userpassword@oracle<<eof
>select * from emp;
>select empno,ename,sal,deptno;
........what ever commands u wanna execute of sql u can
write here
>hit ctrl+d

these are called as here documents

Is This Answer Correct ?    11 Yes 10 No

how do you write sql queries using shell script for eg:- we have databae table like EMPNO,ENAME,SA..

Answer / alpkumar

Do you mean something like this .. how do you use queries
in conjunction with shell scripts..If so, usually the
general practice which goes on is that -- write a query on
what ever database you are working with with the relevant
sql syntax.. call this query from the shell script.
For this, in our program we should start using the commands
that the database company will be providing to use in unix
environement.. So use these unix commands for connecting to
the database, calling the specific query which we had
created..,.etc ...So look out for the commands which will
be available from database provider..to use in unix/linux
flavours and accomplish your script to perform the action
automating in generating reports and mailing them (or what
ever you wanna do.. )

Is This Answer Correct ?    6 Yes 9 No

how do you write sql queries using shell script for eg:- we have databae table like EMPNO,ENAME,SA..

Answer / vikas

U can use .
Database coumns are : Emp.No, Emp. Name, Salary, Dept.No.
$ cut -f 1,3 <filename> > temp.txt

This will print two columns: emp/ No and salarya and store
it in fiile temp.txt in same directory.

If u want to sort them:
$ cut -f 1,3 <filename> > temp.txt
$ sort -otemp.txt temp.txt

Is This Answer Correct ?    5 Yes 9 No

Post New Answer

More Shell Script Interview Questions

Print the 10th line without using tail and head command.

0 Answers  


How do scripts work?

0 Answers  


Is shell scripting a language?

0 Answers  


What is the default ubuntu terminal?

0 Answers  


How are shells born?

0 Answers  


A file has multiple records each having three 30-bit long fields(field1,field2,field3).There is also a lookup file,LOOK_UP.dat.Now, we need to consider only the last ten digits of field1 and lookup the file LOOK_UP.dat. If there a match then field2 and field3 should replaced with corresponding data from the lookup file. otherwise that particular record,for which there is no match, should be stored in a seperate file.

2 Answers   Wipro,


write a shell script to check whether all the directories in the path exist has read and write permission

1 Answers  


What is a command line shell?

0 Answers  


Can shell script run on windows?

0 Answers  


How many prompts are available in a UNIX system?

1 Answers  


How do I read a .sh file?

0 Answers  


What is a shell script in windows?

0 Answers  


Categories