Question

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

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. Build a proc to create a temp table
    I would like to turn a create a temp table into a stored proc. I have included create table code.
  2. ORA-02019 - Select from a remote DB and…
    We have a scenario involving 3 databases. (Say A, B, C) In databaase B, a proc runs selecting a table from database A and inserting into database C. We get a ORA-02019 error during this query. Here are some more details: Database B: The proc resides here. For this database, db_domain=' ' Select * from glob…
  3. 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 …
  4. two million recs using insert select...
    Hi Guru's, I have 3 insert select queries in a single script, just select from a single table B and insert into tableA the query won't finish at all... i have a trigger on the tableA (where i'm inserting into), this trigger basically updates another tableC when ever ther is an insert on table A... Please advise... this would be run once in a …
  5. What would be the best way to select and insert…
    a_table has 22 columns: a_id, a_name, a_1, a_2, a_2...a_20. I need to select from this table (which is in a different schema) and insert into my_table 20 times: insert into my_table(select a_id, a_name, a_1 where a_1 is not null); insert into my_table(select a_id, a_name, a_2 where a_2 is not null); . .…

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

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

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:

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

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

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