oracle儲存過程及游標使用例項

2021-09-23 14:19:30 字數 732 閱讀 6073

create or replace procedure t_table_count_test as

v_tablename varchar2(50);

v_count integer;

str_sql varchar2(200);

–從all_tables裡面獲取的所有表的表名稱,儲存在游標內

cursor mycursor is

select t.table_name from all_tables t;

begin

if mycursor%isopen = false then

open mycursor;

end if;

–獲取游標的當前表名

fetch mycursor into v_tablename;

while mycursor%found

loop

–根據當前表名,獲取表內的資料量

str_sql := 'select count(*) from '||v_tablename ;

execute immediate str_sql into v_count ;

–列印表名和資料量。

dbms_output.put_line(v_tablename||』:』||v_count);

fetch mycursor into v_tablename;

end loop;

end t_table_count_test;

Oracle儲存過程使用動態游標

spool f dbtest12.log set timing on set serveroutput on declare 定義游標 獲取所有表 cursor c alltables is select t.owner t.table name from all tab comments t wh...

oracle儲存過程,游標

oracle儲存過程,游標 2010 07 07 13 01 create or replace procedure p tb task log is 功能 插入任務到任務日誌表 v task start date date v task end date date v sql code numbe...

oracle 儲存過程 游標

create or replace procedure exception3 as 使用者自定義異常 e too high sal exception 宣告自定義異常 v sal employees.salary type begin select salary into v sal from em...