Sponsored Content
Special Forums UNIX and Linux Applications Alternative for slow SQL subquery Post 302358957 by whoknows on Monday 5th of October 2009 09:34:00 AM
Old 10-05-2009
Tools Alternative for slow SQL subquery

Hi -- I have the following SQL query in my UNIX shell script -- but the subquery in the second section is very slow. I know there must be a way to do this with a union or something which would be better. Can anyone offer an alternative to this query? Thanks.
Code:
select
        count(*)
from
        employee_tbl
where
        employee_status_cd = 'C'
        or
        (
                employee_type_cd NOT IN ('TMGR', 'DIR')
                or
                (
                        employee_type_cd = 'MGMT'
                        and pay_grade_cd NOT BETWEEN '11' and '29'
                )
        )
        or
        (
                employee_type_cd = 'C'
                and comp_pay_pct = 0
                and employee_id in (select PT.employee_id
                from
                        payroll_tbl PT
                where
                        PT.specl_comp_cd = '21')
        )
;


Last edited by jim mcnamara; 10-05-2009 at 12:25 PM.. Reason: USE CODE TAGS please!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calling SQL LDR and SQL plus scripts in a shell script

Hi- I am trying to achieve the following in a script so I can schedule it on a cron job. I am fairly new to the unix environment... I have written a shell script that reads a flat file and loads the data into an Oracle table (Table1) via SQLLDR. This Works fine. Then, I run a nested insert... (5 Replies)
Discussion started by: rajagavini
5 Replies

2. Programming

Oracle: fixing an outer join on subquery...

I have a stored procedure that is failing. The current query behind it is: SELECT DISTINCT <many, many values> FROM table1 LEFT OUTER JOIN table2 ON (table2.key = (select max (table2.key) from table2 where table2.key = table1.key) or ... (0 Replies)
Discussion started by: Elric of Grans
0 Replies

3. UNIX for Dummies Questions & Answers

Execute PL/SQL function from Unix script (.sql file)

Hi guys, I am new on here, I have a function in oracle that returns a specific value: create or replace PACKAGE BODY "CTC_ASDGET_SCHED" AS FUNCTION FN_ASDSCHEDULE_GET RETURN VARCHAR2 AS BEGIN DECLARE ASDSchedule varchar2(6); ASDComplete... (1 Reply)
Discussion started by: reptile
1 Replies

4. Shell Programming and Scripting

Alternative for wc -l

Hi techies .. This is my first posting hr .. Am facing a serious performance problem in counting the number of lines in the file. The input files i get will be in some 10 to 15 Gb of size or even sometimes more ..and I will load it to db I have used wc -l to confirm whether the loader... (14 Replies)
Discussion started by: rajesh_2383
14 Replies

5. Shell Programming and Scripting

Execute multiple SQL scripts from single SQL Plus connection

Hi! I would like to do a single connection to sqlplus and execute some querys. Actually I do for every query one connection to database i.e echo 'select STATUS from v$instance; exit' > $SQL_FILE sqlplus user/pass@sid @$SQL_FILE > $SELECT_RESULT echo 'select VERSION from v$instance;... (6 Replies)
Discussion started by: guif
6 Replies

6. UNIX for Advanced & Expert Users

Call parallel sql scripts from shell and return status when both sql are done

Hi Experts: I have a shell script that's kicked off by cron. Inside this shell script, I need to kick off two or more oracle sql scripts to process different groups of tables. And when both sql scripts are done, I will continue in the shell script to do other things like checking processing... (3 Replies)
Discussion started by: huasheng8
3 Replies

7. Programming

Help with Oracle SQL Developer - Subquery & Join will not work.

Greetings all, Hopefully there is someone out there on this forum who can help with this Oracle SQL Developer issue I have. Here is the code: CREATE OR REPLACE VIEW SALES_OVER_30000_WITH_TOTAL AS SELECT E.FIRST_NAME || ' ' || E.LAST_NAME AS EMPLOYEE_NAME, ... (2 Replies)
Discussion started by: U_C_Dispatj
2 Replies

8. Solaris

vi alternative

Is there any other editor, installed by 'default' in Sparc Solaris10, besides vi? I'd like to avoid installing anything new. If not, how to make vi more user-friendly? thanks. (8 Replies)
Discussion started by: orange47
8 Replies

9. Shell Programming and Scripting

Making a faster alternative to a slow awk command

Hi, I have a large number of input files with two columns of numbers. For example: 83 1453 99 3255 99 8482 99 7372 83 175 I only wish to retain lines where the numbers fullfil two requirements. E.g: =83 1000<=<=2000 To do this I use the following... (10 Replies)
Discussion started by: s052866
10 Replies

10. Shell Programming and Scripting

Storing multiple sql queries output into variable by running sql command only once

Hi All, I want to run multiple sql queries and store the data in variable but i want to use sql command only once. Is there a way without running sql command twice and storing.Please advise. Eg : Select 'Query 1 output' from dual; Select 'Query 2 output' from dual; I want to... (3 Replies)
Discussion started by: Rokkesh
3 Replies
INGRES_QUERY(3) 							 1							   INGRES_QUERY(3)

ingres_query - Send an SQL query to Ingres

SYNOPSIS
mixed ingres_query (resource $link, string $query, [array $params], [string $types]) DESCRIPTION
ingres_query(3) sends the given $query to the Ingres server. The query becomes part of the currently open transaction. If there is no open transaction, ingres_query(3) opens a new transaction. To close the transaction, you can call either ingres_commit(3) to commit the changes made to the database or ingres_rollback(3) to cancel these changes. When the script ends, any open transaction is rolled back (by calling ingres_rollback(3)). You can also use ingres_autocom- mit(3) before opening a new transaction to have every SQL query immediately committed. Note Related Configurations See also the ingres.describe, ingres.scrollable and ingres.utf8 directives in Runtime Configuration PARAMETERS
o $link - The connection link identifier. o $query - A valid SQL query (see the Ingres SQL reference guide) in the Ingres documentation. Data inside the query should be properly escaped. The following types of SQL queries cannot be sent with this function: o close (see ingres_close(3)) o commit (see ingres_commit(3)) o connect (see ingres_connect(3)) o disconnect (see ingres_close(3)) o get dbevent o prepare to commit o rollback (see ingres_rollback(3)) o savepoint o set autocommit (see ingres_autocommit(3)) oall cursor-related queries are unsupported o $params - An array of parameter values to be used with the query o $types - A string containing a sequence of types for the parameter values passed. When ingres.describe is enabled, this parameter can be ignored as the driver automatically fetches the expected parameter types from the server. +----------+------------------------------+---+---+ |Type code | | | | | | | | | | | Ingres type | | | | | | | | +----------+------------------------------+---+---+ | a | | | | | | | | | | | | | | | | BOOLEAN | | | | | | | | | b | | | | | | | | | | | | | | | | BYTE | | | | | | | | | B | | | | | | | | | | | | | | | | LONG BYTE/BLOB | | | | | | | | | c | | | | | | | | | | | | | | | | CHAR | | | | | | | | | d | | | | | | | | | | | | | | | | DATE/ANSIDATE/TIMESTAMP/TIME | | | | | | | | | f | | | | | | | | | | | | | | | | FLOAT | | | | | | | | | i | | | | | | | | | | | | | | | | INTEGER | | | | | | | | | L | | | | | | | | | | | | | | | | LONG TEXT | | | | | | | | | m | | | | | | | | | | | | | | | | MONEY | | | | | | | | | M | | | | | | | | | | | | | | | | LONG NVARCHAR | | | | | | | | | n | | | | | | | | | | | | | | | | NCHAR | | | | | | | | | N | | | | | | | | | | | | | | | | NVARCHAR | | | | | | | | | t | | | | | | | | | | | | | | | | TEXT | | | | | | | | | v | | | | | | | | | | | | | | | | VARCHAR | | | | | | | | | V | | | | | | | | | | | | | | | | LONG VARCHAR | | | | | | | | +----------+------------------------------+---+---+ RETURN VALUES
ingres_query(3) returns a query result identifier on success else it returns FALSE. To see if an error occurred use ingres_errno(3), ingres_error(3) or ingres_errsqlstate(3). EXAMPLES
Example #1 Send a simple select <?php $link = ingres_connect("demodb"); $result = ingres_query($link, "select * from user_profile"); while ($row = ingres_fetch_row($result)) { echo $row[1]; echo $row[2]; } ?> Example #2 Passing query parameters to ingres_query(3) <?php $link = ingres_connect("demodb"); $params[] = "Emma"; $query = "select * from user_profile where up_first = ?"; $result = ingres_query($link, $query, $params); while ($row = ingres_fetch_row($result)) { echo $row[1]; echo $row[2]; } ?> Example #3 Inserting a BLOB with parameter types <?php $link = ingres_connect("demodb"); //Open a photo $fh = fopen("photo.jpg","r"); $blob_data = stream_get_contents($fh); fclose($fh); //Prepare parameters $params[] = $blob_data; $params[] = 1201; //Define parameter types $param_types = "Bi"; $query = "update user_profile set up_image = ? where up_id = ?"; $result = ingres_query($link, $query , $params, $param_types); if (ingres_errno()) { echo ingres_errno() . "-" . ingres_error() . " "; } ingres_commit($link); ingres_close($link); ?> SEE ALSO
ingres_unbuffered_query(3), ingres_fetch_array(3), ingres_fetch_assoc(3), ingres_fetch_object(3), ingres_fetch_row(3), ingres_commit(3), ingres_rollback(3), ingres_autocommit(3), ingres_set_environment(3), ingres_errno(3), ingres_error(3). PHP Documentation Group INGRES_QUERY(3)
All times are GMT -4. The time now is 01:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy