Live ORACLE

if you are Oracle Developer ,than this Blog most likely will make you happy.

About my Blog

This Blog particularized for Oracle Developers ... you will see interesting Codes for SQL , PL/SQL as well as new ideas for Developer Suite and Client Tools that will help you in your professional life ... and I hope I reach for your satisfaction.

About Me

I'm Hany Freedom , 25 years old , I live in EL-Minia City in Egypt , I'm Moderator at ArabOUG.org the best Arabic Forum for ORACLE on the Net. if you interested to know more about me .... just Click Here.

Dynamic SQL Procedure that Accepts Table Name and WHERE Clause



DROP TABLE employees_temp CASCADE CONSTRAINTS PURGE;


CREATE TABLE employees_temp
AS
SELECT *
FROM employees;


CREATE OR REPLACE PROCEDURE Delete_rows

(table_name IN VARCHAR2,

condition IN VARCHAR2 DEFAULT NULL)

AS

where_clause VARCHAR2(100) := ' WHERE '

||condition;

v_table VARCHAR2(30);

BEGIN

-- first make sure that the table actually exists; if not, raise an exception

SELECT object_name

INTO v_table

FROM user_objects

WHERE object_name = Upper(table_name)

AND object_type = 'TABLE';

IF condition IS NULL THEN

where_clause := NULL;

END IF;

EXECUTE IMMEDIATE 'DELETE FROM '|| v_table || where_clause;

EXCEPTION

WHEN no_data_found THEN

dbms_output.Put_line('Invalid table: '

||table_name);

END;

/


BEGIN

Delete_rows('employees_temp','employee_id = 111');

END;

/



Share/Save/Bookmark

0 comments:

Post a Comment



Newer Posts Older Posts Home Page
 
http://www.dpriver.com/images/sqlpp-banner-2.png

Thanks for reading my Blog ... you Visitor Number :-