0
0

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】自スキーマ内のfunctionの作成と実行

Last updated at Posted at 2020-09-16

作業内容

  1. 対象ユーザへの「create procedure」権限の付与
  2. 自スキーマ内functionの実行
  3. 自スキーマ内functionの削除

1. 対象ユーザへの「create procedure」権限の付与

functionもprocedureと同様に「create procedure」権限の付与で良い。

権限付与前
$ sqlplus USER/USER
SQL> create function testfunction(num in number) return number
  2  is
  3  twice number;
  4  begin
  5  twice := num * 2;
  6  return twice;
  7  end;
  8  /
create function testfunction is
*
行1でエラーが発生しました。:
ORA-01031: 権限が不足しています

SQL> 

権限付与
$ sqlplus / as sysdba
SQL> grant create procedure to USER;

権限付与が成功しました。

SQL> exit

2. 自スキーマ内functionの実行

自スキーマ内のfunctionであれば、追加権限なしで実行できる。

権限付与後
$ sqlplus USER/USER
SQL> create function testfunction(num in number) return number
  2  is
  3  twice number;
  4  begin
  5  twice := num * 2;
  6  return twice;
  7  end;
  8  /

ファンクションが作成されました。

SQL>
SQL> select testfunction(100) from dual;

testfunction(100)
-------------
          200

SQL> exit
$ sqlplus / as sysdba
SQL> set lin 300
SQL> col owner for a10
SQL> col object_name for a15
SQL> col object_type for a15
SQL> select owner,object_name,object_type from dba_objects where object_type='FUNCTION' and owner='USER';

OWNER      OBJECT_NAME     OBJECT_TYPE
---------- --------------- ---------------
USER       TESTFUNCTION    FUNCTION

SQL>

3. 自スキーマ内functionの削除

自スキーマ内のfunctionであれば、削除も追加権限なしで良い。

$ sqlplus USER/USER
SQL> drop function testfunction;

ファンクションが削除されました。

SQL>exit
$ sqlplus / as sysdba
SQL> select * from dba_objects where object_type='FUNCTION' and owner='USER';

レコードが選択されませんでした。

SQL>

そのうち、他スキーマ内のfunctionのパターンも。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?