2
1

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.

WITH句 の FUNCTION で ズンドコキヨシ(※ワンライナーも可)

Last updated at Posted at 2016-03-17

ズンドコキヨシまとめ
http://qiita.com/shunsugai@github/items/971a15461de29563bf90

こないだは30個位だったズンドコキヨシのタグが、100個超えとる……

負けてはいられん!今度は Oracle Database 12cR1 新機能 の
WITH句 の FUNCTION で ズンドコしてみたやで彡(゚)(゚)

2.1.4.11 SQL WITH句に定義されるPL/SQLファンクション
http://docs.oracle.com/cd/E57425_01/121/NEWFT/chapter12101.htm#FEATURENO10021

ソースは以下の通り。

WITH
  FUNCTION fnc_zun_doko(v_zun IN VARCHAR2) RETURN VARCHAR2 IS
  BEGIN
    IF SUBSTR(v_zun, -5) = '00001' THEN
      RETURN REPLACE(REPLACE(v_zun, '0', 'ズン!'), '1', 'ドコ!') || 'キ・ヨ・シ!';
    ELSE
      RETURN fnc_zun_doko(v_zun || MOD(TRUNC(DBMS_RANDOM.VALUE*10), 2));
    END IF;
  END;
SELECT fnc_zun_doko(NULL) FROM DUAL;
/

結果は以下やで 彡(゚)(゚)

SQL> WITH
  2    FUNCTION fnc_zun_doko(v_zun IN VARCHAR2) RETURN VARCHAR2 IS
  3    BEGIN
  4      IF SUBSTR(v_zun, -5) = '00001' THEN
  5        RETURN REPLACE(REPLACE(v_zun, '0', 'ズン!'), '1', 'ドコ!') || 'キ・ヨ・シ!';
  6      ELSE
  7        RETURN fnc_zun_doko(v_zun || MOD(TRUNC(DBMS_RANDOM.VALUE*10), 2));
  8      END IF;
  9    END;
 10  SELECT fnc_zun_doko(NULL) FROM DUAL;
 11  /

FNC_ZUN_DOKO(NULL)
--------------------------------------------------------------------------------
ドコ!ズン!ドコ!ズン!ズン!ドコ!ドコ!ズン!ズン!ドコ!ドコ!ズン!ズン!ド
コ!ズン!ズン!ドコ!ズン!ズン!ズン!ドコ!ズン!ドコ!ズン!ドコ!ズン!ドコ
!ズン!ドコ!ドコ!ドコ!ズン!ドコ!ドコ!ズン!ズン!ドコ!ドコ!ズン!ドコ!
ズン!ズン!ズン!ドコ!ズン!ドコ!ドコ!ドコ!ズン!ズン!ズン!ドコ!ドコ!ズ
ン!ドコ!ドコ!ズン!ズン!ドコ!ズン!ドコ!ドコ!ドコ!ズン!ドコ!ドコ!ズン
!ドコ!ドコ!ドコ!ドコ!ドコ!ドコ!ズン!ドコ!ドコ!ドコ!ズン!ドコ!ズン!
ドコ!ドコ!ズン!ズン!ドコ!ドコ!ドコ!ズン!ズン!ズン!ドコ!ズン!ズン!ド
コ!ドコ!ドコ!ズン!ズン!ドコ!ドコ!ズン!ドコ!ドコ!ドコ!ドコ!ズン!ドコ
!ズン!ズン!ドコ!ドコ!ズン!ズン!ズン!ドコ!ズン!ズン!ズン!ズン!ズン!
ドコ!キ・ヨ・シ!

12c限定やけど、こっちのがスマートやね!彡(^)(^)

※3/18追記・こいつは(ほぼ)ワンライナーでも行けたやで彡(゚)(゚)

SQL> WITH FUNCTION fnc_zun_doko(v_zun IN VARCHAR2) RETURN VARCHAR2 IS BEGIN IF SUBSTR(v_zun, -5) = '00001' THEN  RETURN REPLACE(REPLACE(v_zun, '0', ' ズン!'), '1', 'ドコ!') || 'キ・ヨ・シ!'; ELSE RETURN fnc_zun_doko(v_zun || MOD(TRUNC(DBMS_RANDOM.VALUE*10), 2)); END IF; END; SELECT fnc_zun_doko(NULL) FROM DUAL;
  2  /

FNC_ZUN_DOKO(NULL)
--------------------------------------------------------------------------------
ドコ!ドコ!ズン!ズン!ズン!ドコ!ズン!ズン!ドコ!ドコ!ズン!ズン!ズン!ド
コ!ドコ!ズン!ズン!ドコ!ドコ!ドコ!ズン!ズン!ドコ!ズン!ドコ!ズン!ドコ
!ドコ!ズン!ズン!ズン!ズン!ズン!ズン!ズン!ズン!ドコ!キ・ヨ・シ!
2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?