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 5 years have passed since last update.

oracle procedure いろいろ

0
Last updated at Posted at 2020-05-23

ただのメモとリンク集です。

  1. SQL*Plusで結果の前後に出力される空行を削除する方法
  2. SPOOLで不要な空行を出力させない
  3. sqlplus WHENEVER SQLERROR を検証
  4. 表作成、変更など
  5. 【シェルスクリプト】IFSで区切り文字(デリミタ)を変更する方法
  6. Bashでコマンドライン実行結果を空白区切りで配列に入れる
  7. PL/SQL EXCEPTION (例外)
  8. PL/SQL EXCEPTION (例外)本家

WHENEVER SQLERROR EXIT SQL.SQLCODE 時のsqlplusの戻り値は、sqlcode mod 255 で設定せれることですね。

WHENEVER SQLERROR EXIT SQL.SQLCODE
select mod(6550,256) from dual;

そして、考えた良さそうなコード(無名ブロック)

SET SERVEROUTPUT ON

SET LINES 100
SET PAGES 0
SET HEADING OFF
SET TRIMSPOOL OFF
SET FEEDBACK OFF
SET ECHO OFF
SET RECSEP OFF

WHENEVER SQLERROR EXIT SQL.SQLCODE
WHENEVER OSERROR  EXIT failure

variable retcode number
variable upd_count number

declare
	dd date;
	cnt number;
begin
	:retcode := 0;
	select sysdate into dd from dual;
	select to_number(EMP_ID) into cnt from EMP where 1=1 and rownum=1;
	:upd_count := 0;
	FOR i IN 1..30 LOOP
		:upd_count := :upd_count + 1;
	end loop;
	
	/*dbms_output.put_line(cnt);*/
	if cnt = 9 then
		/*dbms_output.put_line(cnt);*/
		cnt := cnt / 0;
	end if;
exception
	when others then
		:retcode := 255;
end;
/

SET TERMOUT ON
print :upd_count

exit :retcode

一応動くし、shell から結果を取れる。

以上。

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?