Question

Asked on 2009-02-06 at 07:32:16ID: 25451765

Can I add dynamically add sql where clause (from another table) into a stored proc.

by: ShamD100

Rating9.3Excellent

Hi,

I have a stored procedure in my Oracle Database, which performs a simple select and insert on a group of tables.  

Eg:        
    insert into CUSTOMER (select p.customer_id,  p.name,  p.email, p.address )
        from PASSENGER p
        where p.name = 'John');

I also have a table which has a field which contain SQL where clauses.
In my stored procedure, is it possible to perform a select on this table, retrieve a where clause and add it to my first 'select and insert' statement ? This would then form my where clause.
I could add where clauses as I wish to this table to retrieve different result sets...and never have to re-compile my Stored Proc?

Please Advise!

  1. Oracle -- SQL Select "Where Sum <> 1"
    Doing the below WHERE statement causes a "group function is not allowed here" error. How can I fix ? SELECT FMFORMULAID, SUM(FMWEIGHTPCT) FROM FMFORMULAEXPANDED Where SUM(FMWEIGHTPCT) <> 1 GROUP BY FMFORMULAID
  2. Select existing string if exists from on etable and i…
    We have a lookup table that has a list of facilities with a unique ID assigned. When a user creates a record, the facility name is inserted into a lookup table and assigned a unique ID. If the user types a name that is already in existance, then the code should pull the existing name from the lookup table and insert into the record table; otherwise, disregard the insert …
  3. Temporary tables usage in select statement
    Hi, I have created a global temporary table. In the stored proc, I have defined a cursor on the temp table. After that i am inserting data into the temp table. Then i am opening the cursor, fetching values from the cursor. Then i am using the fetched data from cursor in teh where clause of a select statement of a normal table. But i am getting error …
  4. PL/SQL Stored Proc Question for a Loop
    Hello all, This is what I want to do in my stored proc and need some sample as a start. I am passing to my proc a few params. I need to take those params and then do a SELECT statement query, then I need to loop through each of those records and INSERT into another table the values in that row OR Update if that row say 3 fields already exist in…
  5. Oracle Insert/Update question for stored proc
    Hello all, I need to create two Insert or Update procs that each will do similar to what I know in SQL Server "If exists" then update else Insert to the table. I also need to make sure I have the Commit and Rollback properly. So I am looking for a good example of how to do this and make sure I have all the rollback stuff needed etc. The two table…

Solution

Sign up now to view this solution! It's quick, easy, and secure to subscribe. We will return you to this solution, unlocked, when you’re done.

About this Solution
View This Solution - Start Your 30 Day Free Trial
Zone
General
Tags
PL/SQL Oracle SQL
Participating Experts
3
Solution Grade
A

Replies

 by: JbolanosD

Posted on 2009-02-06 at 07:45:44ID: 28193745

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: ShamD

Posted on 2009-02-06 at 07:48:29ID: 28193746

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by:

Posted on 2009-02-06 at 07:49:19ID: 28193747

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: ShamD

Posted on 2009-02-06 at 08:26:03ID: 28193748

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: awking00

Posted on 2009-02-06 at 09:39:36ID: 28193749

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

Stay Connected

Oracle Around the Web

The latest Oracle news, tips, and tricks

Oracle Unveils Netra SPARC T3 Servers

New Carrier-Grade Blade and Rackmount Servers Deliver Better Performance, Density and Power Efficiency for the Communications Industry ...

read more

Oracle fixes 21 flaws in Java SE, Java for Business

Oracle is fixing 21 flaws in its Java SE and Java for Business products in its February critical patch update issued this week ...

read more

Obama’s Silicon Valley “Tech Supper”

Why was he there? Who wasn’t invited and why? What did they talk about? Why was he really there? These are the questions being debated ...

read more

Featured Oracle Experts

slightwv

slightwv has answered more than 2,000 Oracle questions and oversees database management within the U.S. Government. Slightwv

sdstuber

A regular presenter at the Collaborate conference, Oracle developer sdstuber is a top expert in PL/SQL and Oracle 9, 10 and 11. sdstuber

Testimonials

What users are saying about our experts

"The Oracle gurus provide answers, solutions and valuable workarounds"

User: schwertner

"Wow! Excellent, valuable explanation. Hats off to you"

User: aseshu70

"Solution worked fantastic and performs excellent! Thanks heaps"

User: klausbrandlhuber

Top Experts

  1. slightwv

    2,000

    0 points yesterday

    Profile

BrowseBecome an Expert