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 Transact-SQL

Last updated at Posted at 2016-03-15

Overview

SAP Sybase Adaptive Server Enterprise にて検証

SQL

SET NOCOUNT ON -- 変数格納時に "(1 row affected)" がいちいち出力されるので、出さないようにしとく
DECLARE @zd varchar(20), @rand FLOAT
WHILE @zd != 'ズンズンズンズンドコ'
BEGIN
    print @zd
    SET @rand = RAND()
    SET @zd = RIGHT(@zd + CASE
                               WHEN @rand < 0.5 THEN 'ズン'
                               ELSE 'ドコ'
                          END
                       , 10)
END
SELECT @zd + 'キ・ヨ・シ!'

解説

  • ズンドコの文字列, ランダム関数を格納する変数を定義
  • WHILEで変数値が「ズンズンズンズンドコ」になるまでループ処理させる
  • RAND関数は0.0〜1.0のFLOAT型のランダム値が返ってくるので、0.5未満だったら「ズン」、それ以外は「ドコ」を変数値に結合
  • 結合した結果から後方10文字を取得して変数に格納して
  • ループを抜けられたら、「キ・ヨ・シ!」を結合して、出力
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?