Skip to content

Oracle Tips

foolmacky edited this page Dec 22, 2022 · 3 revisions

■ アカウント・ロールの管理のためのSQL

//アカウント一覧
select username, account_status, expiry_date, lock_date, last_login from dba_users order by username;

//system権限
select * from dba_sys_privs where grantee like 'HOGE%';

//role権限付与
select * from dba_role_privs where admin_option = 'NO' and common = 'NO' and grantee like 'HOGE5' order by grantee;

//object権限
select * from dba_tab_privs where grantee = 'HOGE' order by type, table_name;
select * from dba_tab_privs where grantee = 'HOGE' and privilege = 'SELECT' and type = 'TABLE' order by type, table_name;
//table以外のobjectに関しても使える
//EXECUTE : FUNCTION, TYPE, PROCEDURE, PACKAGE
//SELECT : SEQUENCE
//SELECT, INSERT, UPDATE, DELETE : TABLE

■ アカウントの作成など

  • アカウント関連
//作成
create user [USER] identified by [初期password]
default tablespace users
temporary tablespace temp
quota unlimited on users
password expire --変更を強制
;

//削除
drop user [USER] cascade;

//ロック解除
alter user [USER] account unlock;

//パスワード初期化
alter user [USER] identified by [初期password] password expire;
  • 権限付与,削除
//付与
grant [ROLE] to [USER];
ex.
grant delete on SCHEMA.TABLE to [ROLE/USER];

//削除
revoke select on SCHEMA.TABLE from [ROLE/USER];

■ オブジェクトの確認

//簡易的
select * from tab;

//table
select table_name from dba_tables where owner = 'OBJECT OWNER' order by table_name;
//index
select index_name from dba_indexes where owner = 'OBJECT OWNER' order by table_name,index_name;
//partition table
select table_name, partitioning_type, subpartitioning_type, partition_count from dba_part_tables where owner = 'OWNER' order by table_name;
//sequence
select sequence_name, last_number, max_value from dba_sequences where sequence_owner = 'OWNER' order by sequence_name;

//other objects (function, procedure, package, type, synonym, etc)
select object_type, object_name, status from dba_objects where owner = 'OWNER' and object_type = 'FUNCTION' order by object_type, object_name;

//DDL
select text from dba_source where owner = 'OWNER' and name = 'OBJECT名' order by line;

■ OracleのStored Procedureに関連して

OracleのProcに対して配列型のパラメータを予め定義して渡し、Procの中でLoop処理させてデータ処理することができる
ファイルから行を読み取って、その内容をTableに連続してインサートしたりするのに使える
配列型のパラメータを順番にインサートするとともに、通常のパラメータを渡して、どの行でも同じ内容を同時にインサートすることもできる

■ ファイルからインサートする際のパフォーマンスについて

Tableの内容や、インサートする前にデータを加工する必要があるかなどの条件によって異なると思うが、

  • データをパラメータとして配列で渡してインサートする
  • Oracle独自のMultiInsertの書き方のSQLでインサートする

この比較だと、最新のver.のインスタンスでない場合は、前者のほうがパフォーマンスが高いようだ

Clone this wiki locally