Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Regarding executing sql query in shell script Post 302786135 by abhii on Wednesday 27th of March 2013 02:02:43 AM
Old 03-27-2013
Regarding executing sql query in shell script

Hi,

I have one SQL file prepared in UNIX and one script that is executing that.

In SQL i have Update and create queries.

I want to introduce conditions in SQL file (in UNIX) that if either of the create or update query failes whole transaction should be rollback.

I just have 1 create and 2 update and i dont want to work on SQL as i want this to be sorted out using shell scripting,


Thanks
Abhii
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Executing a SQL query from a shell script

I cannot figure out how to run a SQL script, or just a sqlplus query, from a shell script (bash or ksh). Basically, I need to su - oracle from root and run a query, then test the exit status. (3 Replies)
Discussion started by: 98_1LE
3 Replies

2. Shell Programming and Scripting

Executing Sql Query Using Shell Script

HI ALL i have a requirement like this. i have to write a shell script to run a sql query. DB is oracle. once the query is run, the results of the query has to be published in a data file. can you please advice me how to go about it. i am absolutely new to shell scripts and this is a part of my job. (14 Replies)
Discussion started by: ragha81
14 Replies

3. Shell Programming and Scripting

executing a SQL query in shell script

Hi ALL, I need an help in connecting to oracle database, executing a select query and printing it on the screen. Can any one please write a simple code or psuedo code and let me know. select query returns multiple values( say select name from emp) Thanks in advance LM (1 Reply)
Discussion started by: lijju.mathew
1 Replies

4. Shell Programming and Scripting

Script executing sql query

Hello, I have a sh script excuting a sql query through sqlplus. I am having trouble making my date equal to the date of the server time in the sql script. How can i call the server date from my query? Thanks (2 Replies)
Discussion started by: kingluke
2 Replies

5. 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

6. UNIX for Dummies Questions & Answers

executing SQL query using unix shell script

I want to perform few post-session success tasks like update a status to 'true' in one of the sql database table, update date values to current system date in one of the configuration table in sql. How do i achieve this in a post session command?syntax with example will be helpful. (3 Replies)
Discussion started by: nathanvaithi
3 Replies

7. Shell Programming and Scripting

Executing a shell script from a PL / SQL Block

Hi, I need to call a shell script present on solaris server from within a PL / SQL block. Kindly suggest.. Thanks Sudhir (1 Reply)
Discussion started by: sudhird
1 Replies

8. Shell Programming and Scripting

Executing SQL Query and sending a mail

Hi all, My reqirenet goes like this. Need to execute one select statement within the script and send a mail to the users with the number of records fecthed from the query. Please help.. Thanks. (3 Replies)
Discussion started by: Achiever
3 Replies

9. 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

10. UNIX for Beginners Questions & Answers

Help with Executing sql in Shell Script

Hello~ I have a requirement to write a shell script which will connect to the oracle database and run a select count(*) query on a table. The script should succeed only when the count returns a number greater than zero. If the count returns zero, the script should fail. Can someone please... (3 Replies)
Discussion started by: Naren.N
3 Replies
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)
All times are GMT -4. The time now is 02:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy