批量刪除Orcale資料庫使用者表

2021-05-02 15:15:09 字數 2306 閱讀 1139

set serveroutput on

declare

-- step 1: declare the variables

v_product_name varchar(100);

v_product_count integer:=0;

-- step 2: declare the cursor

cursor cv_product_cursor is

select  table_name

from user_tables

where table_name like '_/_%' escape'/';

begin

-- step 3: open the cursor

open cv_product_cursor;

--display devision

dbms_output.put_line('------------------------------begin------------------------------------');

loop

-- step 4: fetch the rows from the cursor

fetch cv_product_cursor

into v_product_name;

-- exit the loop when there are no more rows, as indicated by

-- the boolean variable cv_product_cursor%notfound (= true when

-- there are no more rows)

exit when cv_product_cursor%notfound;

-- drop table

execute immediate 'drop table ' || v_product_name;   

--set the number of dropped tables

v_product_count :=v_product_count +1;

--use dbms_output.put_line() to display execute result    

dbms_output.put_line(v_product_count ||' : '||

'dorp table ' || v_product_name ||' sucessfully'

);    

end loop;

--display devision

dbms_output.put_line('-------------------------------end-------------------------------------');

--dispaly the number of dropped tables

dbms_output.put_line('total:'||v_product_count );

-- step 5: close the cursor

close cv_product_cursor;

exception

when others then    

dbms_output.put_line(v_product_count+1 ||' : '||

'dorp table ' || v_product_name ||' failed'

);   

--display devision

dbms_output.put_line('-------------------------------end-------------------------------------');

--dispaly the number of dropped tables

dbms_output.put_line('total:'||v_product_count );

dbms_output.put_line('------------------------------errormsg---------------------------------');

dbms_output.put_line(v_product_count+1||' : '||sqlerrm);

dbms_output.put_line('------------------------------errormsg---------------------------------');

-- step 5: close the cursor

close cv_product_cursor;

end;

/

Orcale資料庫基礎

orcale資料庫的主要特點 orcale資料型別 char資料型別 當需要固定長度的字串時,使用char資料型別。這種資料型別的列長度可以是1 2000位元組,如果在定義時未指明大小,其預設占用1位元組。varchar2資料型別 varchar2資料型別支援可變長度的字串。該資料型別的大小為1 4...

批量刪除Oracle資料庫的資料

在使用delete語句刪除資料時,資料庫是要做日誌記錄的,以便將來可以恢復資料,可是我在刪除上百萬條資料時,十分緩慢甚至宕機,請問有沒有什麼好方法?more 觀點一 create or replace procedure delete table isi number 10 begin for x ...

刪除資料庫使用者

usr bin ksh 1 upload the shell command to the server 2 grant the 777 to the command 3 use method like as follow dropuser.sh username the username as t...