Create dynamic delete from command : Delete Data « PL SQL « Oracle PL / SQL






Create dynamic delete from command

    
SQL>
SQL> CREATE or replace PROCEDURE delete_rows (table_name IN VARCHAR2,condition IN VARCHAR2 DEFAULT NULL) AS
  2      where_clause VARCHAR2(100) := ' WHERE ' || condition;
  3  BEGIN
  4      IF condition IS NULL THEN
  5          where_clause := NULL;
  6      END IF;
  7      EXECUTE IMMEDIATE 'DELETE FROM ' || table_name || where_clause;
  8  END;
  9  /

Procedure created.

SQL>

   
    
    
    
  








Related examples in the same category

1.DELETE statement can be used within PL/SQL programs to delete a row or a set of rows
2.DELETE statement in PL/SQL block
3.Delete data statement with WHERE clauses.
4.Delete statement with variable
5.Delete a row and output referenced value
6.Delete employee with stored procedure
7.Use procedure to delete departments