3
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Oracleで個人的によく使うコマンド その1

Last updated at Posted at 2017-09-14

個人的にOracleでちょいちょい使うコマンドや、ちょっとした時にパッとコピペできると楽なコマンドをまとめておく。

ある程度まとめたらコマンドの種類別に少し整理しよう・・・


##インスタンス作成時に設定したコンポーネント構成を確認

SELECT comp_name
	  ,version
	  ,status
FROM dba_registry
ORDER BY 1;

##どのユーザー所有のテーブルかの確認

col OWNER for a30
col TABLE_NAME for a30

SELECT owner
	  ,table_name 
FROM dba_tables 
WHERE table_name='テーブル名';

##表に紐づく索引と索引が貼られているカラムの確認

col COLUMN_NAME for a30

SELECT table_name
	  ,index_name
	  ,column_name 
FROM user_ind_columns
WHERE table_name = 'テーブル名';

###テーブルの列に設定されたコメントを取得するSQL

SELECT column_name
	  ,comments
FROM user_col_comments
WHERE table_name = 'テーブル名'

##SIDとSERIAL#の確認系

###SIDとSERIAL#の確認

SELECT s.username
	  ,l.sid
	  ,s.serial# 
FROM v$lock l,v$session s
WHERE l.sid=s.sid 
ORDER BY 1;

###OS上のPIDからのSIDとSERIAL#の確認

SELECT s.username
	  ,s.sid
	  ,s.serial#
	  ,s.program
	  ,p.spid
	,s.status
FROM v$session s,v$process p
WHERE p.addr=s.paddr 
	AND spid='PSコマンドで確認したPID';

##ユーザと実行中のSQLのIDの確認

SELECT distinct s.username
	           ,s.sid
	           ,s.serial#
	           ,q.sql_id
	           ,s.status
FROM v$session s,v$sql q
WHERE s.sql_id=q.sql_id 
	and s.username IS NOT NULL
ORDER BY q.sql_id;

###SQL文自体も確認する場合

SELECT distinct s.username
	           ,s.sid,
	           ,s.serial#
	           ,q.sql_id
	           ,s.status
	           ,q.sql_text
FROM v$session s,v$sql q
WHERE s.sql_id=q.sql_id 
	AND s.username IS NOT NULL
ORDER BY q.sql_id;

##処理の進捗状況確認

SELECT sid
	  ,serial#
	  ,username
	  ,opname
	  ,(sofar/totalwork)*100 as WIP --進捗度(%)
	  ,time_remaining
	  ,to_char(start_time, 'YYYY/MM/DD HH:MI:SS')
FROM v$session_longops
WHERE username = 'ユーザー名'
	AND time_remaining !=0;

##接続ユーザ所有のパッケージなどを確認

SELECT object_type
	  ,created_status
	  ,status,oject_type
FROM user_objects
WHERE object_type IN ('PROCEDURE','FUNCTION','PACKAGE','PACKAGEBODY');

##ディレクトリ・オブジェクトの確認
expdp/impdp使ってないとすぐに忘れる・・・

SELECT * FROM dba_directories;

表領域毎に表領域割当制限を付与する

ALTER USER ユーザー QUOTA サイズ ON 表領域名;

表領域割当制限の確認

select username,tablespace_name,max_bytes from DBA_TS_QUOTAS;
3
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?