Cleaning up tables and views of oracle stored procedures

*, Oracle cursor basis

Explicit cursor:
 CURSOR cursor name (parameter) [return value type] IS
  Select statement
The life cycle:
Most of the time we follow these steps when designing programs:
 1. Open the cursor open cs1;
 2、开始循环 while cs1%found loop | for column_name in .. LOOP
 3. Get the value from the cursor fetch .. into.. |
 4. Check which line is returned
 5. Processing
 6. Close the loop end loop;
 7. Close the cursor if cs1&isopen then close cs1;
Options: Parameters and Return Types

 

*, Oracle stored procedure deletes all tables in a user tablespace

 

declare
    v_name all_tables.table_name%type;
    cursor mycur is select table_name from all_tables where owner='test';
begin
    open mycur;
    loop
        fetch mycur into v_name;
        exit when mycur%NOTFOUND OR mycur%NOTFOUND IS NULL;
        execute immediate 'drop table '|| v_name;
    end loop;
    close mycur;
end;

 *, Oracle stored procedure deletes all views of a user tablespace

 

declare
    v_name all_tables.table_name%type;
    cursor mycur is select view_name from all_views where owner='test';
begin
    open mycur;
    loop
        fetch mycur into v_name;
        exit when mycur%NOTFOUND OR mycur%NOTFOUND IS NULL;
        execute immediate 'drop view '|| v_name;
    end loop;
    close mycur;
end;

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326520098&siteId=291194637