12-17-2007
query to get a value from database
Hi friends,
I have written a script which retrieves one value from the database.
It takes time for the sql query to get the desired output. So the query runs fine from TOAD or from UNIX console.
However if I put this in a script it doesn't work. The script is as below.
#! /bin/ksh
DB_VALID_CDR=`sqlplus -s username/password<<!EOF | grep -v "^Connected" 2>&1
set termout off echo off feedback off pause off timing off time off
set pages 0
clear breaks
clear compute
set termout on
select a.VALUE_INTEGER from client_statistics a, statistic_type b where a.STATISTICS_TYPE=b.Statistic_type_id and a.STATISTICS_OBJECT like '%20071217102445_9673324_AG40_20071217101738_0000002118%' and b.STATISTIC_TYPE='valid_cdrs'
EXIT
!EOF`
echo $DB_VALID_CDR
I strongly believe that the issue is with the query taking time to return the value.
Please let me know how to tackle the issue.
Many thanks
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I am executing a SQL query in Unix Server:
select status,location from user_information where request_id='DS-43720'
In shell script I am writing this query in the below manner:
echo "select status,location from user_information where request_id='DS-43720' ;" >> $directory/info.sql
... (3 Replies)
Discussion started by: debu
3 Replies
2. Shell Programming and Scripting
Hi,
Am using informix database. When i give "isqlrf <database name> - " from the command prompt , i get connected to the database and i can run sql queries..
I am moving to freeBSD and when i give the same command at the prompt i get an error : Index already exists on column
Why is this... (0 Replies)
Discussion started by: jisha
0 Replies
3. Shell Programming and Scripting
Hi all,
I would want to spool file for a database query, however by using crontab, the file is not spooled. Below shows my script:
ORACLE_HOME="/u01/oraprod/perpdb/10.1.0/db_1"
OUTFILE="/tmp/invalid.out"
FILE="$HOME/admin/scripts"
$ORACLE_HOME/bin/sqlplus -s "/as sysdba"... (0 Replies)
Discussion started by: *Jess*
0 Replies
4. IP Networking
Hi
We run a script that queries a database via the internet and we need the fast possible connections to the database server.
I have centos server which sends the requests to the database across the internet . it sends upto 800 queries per milliseconds however this using the default... (4 Replies)
Discussion started by: um08
4 Replies
5. Programming
How can i modify the below to search for the things i'm looking for during a certain time frame?
select Node, NodeAlias, Summary, Tally, AlertKey, AlertGroup, Manager, Agent from mrtg_alerts where LastOccurrence > '5-Dec-2010' order by Manager desc;
In this particular case, this query is... (3 Replies)
Discussion started by: SkySmart
3 Replies
6. Shell Programming and Scripting
#!/bin/bash
user=`mysql userList -uuserlist -puserlistpassword -s -N -e "SELECT userName FROM users WHERE activated='n'"`
for i in $user; do
useradd "$i" -m
doneThis is what I have done so far. But obviously it still does not work.
I'm trying to create users based on information stored in a... (5 Replies)
Discussion started by: bucketuk
5 Replies
7. Shell Programming and Scripting
Thank you for taking the time to read my issue. I need to set up a script to run from a wagon wheel type toplogy where 1 server needs to query about 10 to 15 remote servers for duplicate values in a database table. If a duplicate value is found, send an email to me( or wall command to console).... (5 Replies)
Discussion started by: lutador72
5 Replies
8. Shell Programming and Scripting
HI,
I am having scenario like to print multipule rows from output of database query
sample query i mentioned below
code=`db2 -x select code,values from dummy`
in the query output i am getting around 110 records with 2 columns.
sample output pasted below
code,value... (3 Replies)
Discussion started by: bhaskar v
3 Replies
9. Programming
I am getting an error function in date formate while importing the date ccolumn in oracle sql developer tool
My date format in table is 6-Nov-14 and while importing its converted to 6/11/14 eventhough the format is as 6-Nov-14 in excel.
could you please let help me out what I need to change... (6 Replies)
Discussion started by: ramkumar15
6 Replies
10. Programming
Team
I am using DBartisan tool for sybase database.
I have a table that has below fields Employee_ID,EMP_Name,First_Nm,Last_Nm,Emp_Designation,Employee's_Manager
is it possible to retrieve hierarchical data based on below fields
Emp_Designation will have Soft Engg,SSE,Team Lead,... (6 Replies)
Discussion started by: Perlbaby
6 Replies
LEARN ABOUT REDHAT
prepare
PREPARE(7) SQL Commands PREPARE(7)
NAME
PREPARE - create a prepared query
SYNOPSIS
PREPARE plan_name [ (datatype [, ...] ) ] AS query
INPUTS
plan_name
An arbitrary name given to this particular prepared query. It must be unique within a single session, and is used to execute or
remove a previously prepared query.
datatype
The data-type of a parameter to the prepared query. To refer to the parameters in the prepared query itself, use $1, $2, etc.
OUTPUTS
PREPARE
The query has been prepared successfully.
DESCRIPTION
PREPARE creates a prepared query. A prepared query is a server-side object that can be used to optimize performance. When the PREPARE
statement is executed, the specified query is parsed, rewritten, and planned. When a subsequent EXECUTE statement is issued, the prepared
query need only be executed. Thus, the parsing, rewriting, and planning stages are only performed once, instead of every time the query is
executed.
Prepared queries can take parameters: values that are substituted into the query when it is executed. To specify the parameters to a pre-
pared query, include a list of data-types with the PREPARE statement. In the query itself, you can refer to the parameters by position
using $1, $2, etc. When executing the query, specify the actual values for these parameters in the EXECUTE statement -- refer to EXECUTE
[execute(7)] for more information.
Prepared queries are stored locally (in the current backend), and only exist for the duration of the current database session. When the
client exits, the prepared query is forgotten, and so it must be re-created before being used again. This also means that a single prepared
query cannot be used by multiple simultaneous database clients; however, each client can create their own prepared query to use.
Prepared queries have the largest performance advantage when a single backend is being used to execute a large number of similar queries.
The performance difference will be particularly significant if the queries are complex to plan or rewrite. For example, if the query
involves a join of many tables or requires the application of several rules. If the query is relatively simple to plan and rewrite but rel-
atively expensive to execute, the performance advantage of prepared queries will be less noticeable.
NOTES
In some situations, the query plan produced by PostgreSQL for a prepared query may be inferior to the plan produced if the query were sub-
mitted and executed normally. This is because when the query is planned (and the optimizer attempts to determine the optimal query plan),
the actual values of any parameters specified in the query are unavailable. PostgreSQL collects statistics on the distribution of data in
the table, and can use constant values in a query to make guesses about the likely result of executing the query. Since this data is
unavailable when planning prepared queries with parameters, the chosen plan may be sub-optimal.
For more information on query planning and the statistics collected by PostgreSQL for query optimization purposes, see the ANALYZE [ana-
lyze(7)] documentation.
COMPATIBILITY
SQL92
SQL92 includes a PREPARE statement, but it is only for use in embedded SQL clients. The PREPARE statement implemented by PostgreSQL also
uses a somewhat different syntax.
SQL - Language Statements 2002-11-22 PREPARE(7)