Help us understand the problem. What is going on with this article?

Oracleの表関数でズンドコキヨシ

More than 3 years have passed since last update.

巷で大流行している「ズンドコキヨシ」をOracleの表関数でキメてみた☆

http://qiita.com/shunsugai@github/items/971a15461de29563bf90

CREATE OR REPLACE TYPE TYPE_ZUNDOKO AS OBJECT(
    COL VARCHAR2(256)
);
/
CREATE OR REPLACE TYPE TYPE_ZUNDOKO_TABLE AS TABLE OF TYPE_ZUNDOKO;
/
CREATE OR REPLACE FUNCTION ZUNDOKO(MAXROW NUMBER DEFAULT 100) RETURN TYPE_ZUNDOKO_TABLE PIPELINED
IS
    WORD VARCHAR(4);
    TYPE WORD_ARRAY IS VARRAY(2) OF VARCHAR2(4);
    WORD_LIST WORD_ARRAY := WORD_ARRAY('ズン', 'ドコ');
    TYPE HISTORY_ARRAY IS VARRAY(5) OF VARCHAR2(4);
    HISTORY HISTORY_ARRAY := HISTORY_ARRAY('', '', '', '', '');
BEGIN
    FOR I IN 1..MAXROW LOOP
        WORD := WORD_LIST(TRUNC(DBMS_RANDOM.VALUE() * 2 + 1));
        PIPE ROW(TYPE_ZUNDOKO(WORD));
        IF HISTORY(2) || HISTORY(3) || HISTORY(4) || HISTORY(5) || WORD = 'ズンズンズンズンドコ' THEN
            PIPE ROW(TYPE_ZUNDOKO('キ・ヨ・シ!'));
            EXIT;
        END IF;
        HISTORY(1) := HISTORY(2);
        HISTORY(2) := HISTORY(3);
        HISTORY(3) := HISTORY(4);
        HISTORY(4) := HISTORY(5);
        HISTORY(5) := WORD;
    END LOOP;
    RETURN;
END;
/

で、このテーブル関数をセレクトすると以下が表示されるはず。

SQL> SELECT * FROM TABLE(ZUNDOKO());

COL
--------------------------------------------------------------------------------
ドコ
ズン
ズン
ズン
ドコ
ズン
ズン
ズン
ズン
ズン
ズン
ズン
ズン
ズン
ドコ
キ・ヨ・シ!

16行が選択されました。

パパやったね!!!

nobuhito
無いものは作る、欲しい物も作る
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした