Sponsored Content
Top Forums Shell Programming and Scripting Shell script to execute sql query. Post 303019567 by cero on Monday 2nd of July 2018 08:32:47 AM
Old 07-02-2018
Hi,
I see 2 problems with your query:
1) When you define an alias for a column either use double quotes to make it case sensitive or do not use quotes at all.
2) You try to concatenate 2 columns and somehow throw the alias definition into the middle of that concatenation. The result of the query without the alias definition is a single column, which can be aliased, but you cannot alias just a part of it.

I'll dare a wild guess about your final goal: you try to create a report with comma separated columns with headings. For this you either have to create the headings yourself or drop the concatenation.

Creating the headings is quite simple and usually preferred over the other method if columns do not have to have a fixed width:
Code:
#!/bin/bash
sqlplus -s abc/abc@abc << EOF> bcd.csv
set trimspool on heading off
select 'ABC,LANGUAGE_CODE' from dual;
select zone_id || ',' || language_code from ZONE_VALUES;
exit
EOF

The other way is to tell sqlplus how to format your report:
Code:
#!/bin/bash
sqlplus -s abc/abc@abc << EOF> bcd.csv
set trimspool on colsep ','
select zone_id as 'ABC' , language_code from ZONE_VALUES;
exit
EOF

Try both methods and use what fits your needs best.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script to execute SQL's

Hi people, i need youre help on this. I need to create an Shell SCript to list in a directory some sql files and then execute them one by one . Also i need to have Logs from the executed Sql's to send to our costummers. Can anyone help me on this Regards, osramos (2 Replies)
Discussion started by: osramos
2 Replies

2. Shell Programming and Scripting

TO execute .sql 2005 query file in shell script

Hi, I know in oracle a .sql file is called by @ <path> /<filename>. But how to call in sql 2005, I am opening the sql sessionwith sqsh, is there any command to execute there a .sql file (query in sql 2005) in K shell script. (0 Replies)
Discussion started by: n2ekhil
0 Replies

3. Shell Programming and Scripting

query sql using shell script

query sql using shell script, is it possible? my friend told me to do a file.sql and link to my shell script, but can i query sql using shell script? thanks in advance! (2 Replies)
Discussion started by: kingpeejay
2 Replies

4. Shell Programming and Scripting

how to execute shell script in another server that contain sql.

hi all, how to execute shell script in another server that contain sql script. i tried using "ssh -l" option.. but i am unable to load the environment variable of the remote host. please suggest how execute the shell script contain sql part inside it. (2 Replies)
Discussion started by: sandeep909
2 Replies

5. Programming

how to execute the sql quires from shell script?

hi all, I'm new to shell scripting, i want to know how to use the sql statements from the shell script? is there any documents or pdf to learn from the begining? plese provide me some useful links on the same. Thanks all in advance..,:b: (3 Replies)
Discussion started by: vij_krr
3 Replies

6. Shell Programming and Scripting

Execute SQL query in unix script

Hi I am new in unix. oracle and unix are installed in my sytem.i need the script which could connect to the oracle using username ,password and schema and can run the select * from tab query. Thanks vijay (8 Replies)
Discussion started by: vijays3
8 Replies

7. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

8. Red Hat

Sql query through shell script

hey , i am using this code to store value of a sql query and and then use it in other query but after some time , but it is not working. please help #!/bin/bash val_1=$( sqlplus -s rte/rted2@rel76d2 << EOF setting heading off select max(stat_id) from cvt_stats; exit EOF ) nohup... (5 Replies)
Discussion started by: ramsavi
5 Replies

9. Shell Programming and Scripting

How to execute a sql querry from shell script?

hello forum , I am new to shell scripting. as part of my assignment i have to execute a sql querry from the shell script. please help me. example. sql queerry:db2 "select emp_id from tsble emp". i have to execute the above querry from the script. advance thanks to forum Siva ranganath (1 Reply)
Discussion started by: workforsiva
1 Replies

10. Shell Programming and Scripting

Help with shell script to execute a sql cursor

Hi All, I want some help in writing a shell script which will be in the below form: A logical representation of shell scripts: ->Shell scripts start ->Connect to database ->Execute a sql and store the output in a cursor(need to know is there any concept of cursor in unix) ->Using a loop... (2 Replies)
Discussion started by: Chitragupta
2 Replies
FS_NEWCELL(1)						       AFS Command Reference						     FS_NEWCELL(1)

NAME
fs_newcell - Changes the kernel-resident list of a cell's database servers SYNOPSIS
fs newcell -name <cell name> -servers <primary servers>+ [-linkedcell <linked cell name>] [-help] fs n -n <cell name> -s <primary servers>+ [-l <linked cell name>] [-h] DESCRIPTION
The fs newcell command removes the Cache Manager's kernel-resident list of database server machines for the cell specified by the -name argument and replaces it with the database server machines named by the -servers argument. Each time the machine reboots, the Cache Manager constructs the kernel list of cells and database server machines by reading the local /etc/openafs/CellServDB file. This command does not change the CellServDB file, so any changes made with it persist only until the next reboot, unless the issuer also edits the file. The output of the fs listcells command reflects changes made with this command, because that command consults the kernel-resident list rather than the CellServDB file. This command can introduce a completely new cell into the kernel-resident list, but cannot make a cell inaccessible (it is not possible to remove a cell's entry from the kernel-resident list by providing no values for the -server argument). To make a cell inaccessible, remove its entry from the CellServDB file and reboot the machine. If the -name argument names a DCE cell, then the -servers argument names DFS Fileset Location (FL) Server machines. The -linkedcell argument specifies the name of the AFS cell to link to a DCE cell for the purpose of DFS fileset location. CAUTIONS
Some commands, such as the aklog or klog.krb5 commands, work correctly only when the information is accurate for a cell in both the CellServDB file and the kernel-resident list. OPTIONS
-name <cell name> Specifies the fully-qualified cell name of the AFS or DCE cell. -servers <primary servers>+ Specifies the fully-qualified hostnames of all AFS database server machines or DFS Fileset Location (FL) Server machines for the cell named by the -name argument. If FL Server machines are specified, the local machine must be running the AFS/DFS Migration Toolkit Protocol Translator. -linkedcell <linked cell name> Specifies the name of the AFS cell to link to a DCE cell for the purpose of DFS fileset location. -help Prints the online help for this command. All other valid options are ignored. EXAMPLES
The following example changes the machine's kernel-resident list of database server machines for the ABC Corporation cell to include the machines "db1.abc.com" and "db2.abc.com": % fs newcell -name abc.com -servers db1.abc.com db2.abc.com The following example links the DCE cell "dce.abc.com" to the AFS cell "abc.com". The AFS client contacts the Fileset Location (FL) servers "db1.dce.abc.com" and "db2.dce.abc.com" for fileset location information as it interprets a DFS pathname. % fs newcell -name dce.abc.com -servers db1.dce.abc.com db2.dce.abc.com -linkedcell abc.com PRIVILEGE REQUIRED
The issuer must be logged in as the local superuser root. SEE ALSO
CellServDB(5), fs_listcells(1) COPYRIGHT
IBM Corporation 2000. <http://www.ibm.com/> All Rights Reserved. This documentation is covered by the IBM Public License Version 1.0. It was converted from HTML to POD by software written by Chas Williams and Russ Allbery, based on work by Alf Wachsmann and Elizabeth Cassell. OpenAFS 2012-03-26 FS_NEWCELL(1)
All times are GMT -4. The time now is 06:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy