SHOEISHA iD

※旧SEメンバーシップ会員の方は、同じ登録情報(メールアドレス&パスワード)でログインいただけます

EnterpriseZine(エンタープライズジン)編集部では、情報システム担当、セキュリティ担当の方々向けに、EnterpriseZine Day、Security Online Day、DataTechという、3つのイベントを開催しております。それぞれ編集部独自の切り口で、業界トレンドや最新事例を網羅。最新の動向を知ることができる場として、好評を得ています。

直近開催のイベントはこちら!

EnterpriseZine編集部ではイベントを随時開催しております

EnterpriseZine(エンタープライズジン)編集部では、情報システム担当、セキュリティ担当の方々向けの講座「EnterpriseZine Academy」や、すべてのITパーソンに向けた「新エバンジェリスト養成講座」などの講座を企画しています。EnterpriseZine編集部ならではの切り口・企画・講師セレクトで、明日を担うIT人材の育成をミッションに展開しております。

お申し込み受付中!

MySQL事始

MySQL事始 SQL文(3) 代表的なSQL関数

第6回


コラム:ネットにつながずにマニュアルを見る

MySQLサーバにはSQL関数や構文に関するヘルプ(英語)が用意されています。インターネット上のマニュアルをダウンロードしておく手もありますが、データセンターなどで急にコマンドを打って確認しなければいけない場合になど便利です。ヘルプを使用するにはmysqlクライアントから以下の構文を利用します。

help 参照したい内容

例えば万が一SELECT文のORDER BYが先かGROUP BYが先かなどで悩んだ場合などは以下のコマンドで確認できます。

help SELECT

ちなみに、helpだけを実行すると、mysqlクライアント単独で実行できるコマンドや出力形式の変更などのオプションが確認できます。

mysql> help

For information about MySQL products and services, visit:
   http://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
   http://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:
   https://shop.mysql.com/

List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?         (\?) Synonym for `help'.
clear     (\c) Clear the current input statement.
...<略>...
system    (\!) Execute a system shell command.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.

For server side help, type 'help contents'

どのような内容が指定できるかの確認には、まずhelp contentsを実行します。

mysql> help contents
You asked for help about help category: "Contents"
For more information, type 'help ', where  is one of the following
categories:
   Account Management
   Administration
   Compound Statements
   Data Definition
   Data Manipulation
   Data Types
   ...<略>...
   Utility

CREATE TABLE文などを含むData Definitionや、データ型の解説を行うData Typesなどが指定できることが分かります。 ここでは、今回開設したフロー制御関数にどのようなものがあるか、またフロー制御関数のIFはどのような構文なのかを以下のコマンドで確認しています。

mysql> help functions
You asked for help about help category: "Functions"
For more information, type 'help ', where  is one of the following
topics:
   PROCEDURE ANALYSE
categories:
   Bit Functions
   Comparison operators
   Control flow functions
   ...<略>...
   String Functions

mysql> help Control flow functions
You asked for help about help category: "Control flow functions"
For more information, type 'help ', where  is one of the following
topics:
   CASE OPERATOR
   IF FUNCTION
   IFNULL
   NULLIF

mysql> help IF FUNCTION
Name: 'IF FUNCTION'
Description:
Syntax:
IF(expr1,expr2,expr3)
If expr1 is TRUE (expr1 <> 0 and expr1 <> NULL) then IF() returns
expr2; otherwise it returns expr3. IF() returns a numeric or string
value, depending on the context in which it is used.
URL: http://dev.mysql.com/doc/refman/5.5/en/control-flow-functions.html
Examples:
mysql> SELECT IF(1>2,2,3);
        -> 3
mysql> SELECT IF(1<2,'yes','no');
        -> 'yes'
mysql> SELECT IF(STRCMP('test','test1'),'no','yes');
        -> 'no'

この記事は参考になりましたか?

  • Facebook
  • Twitter
  • Pocket
  • note
MySQL事始連載記事一覧

もっと読む

この記事の著者

梶山隆輔(カジヤマリュウスケ)

日本オラクル MySQL Global Business Unit Asia Pacific & Japan担当 MySQLソリューション・エンジニアリング・ディレクターオラクル社において、MySQLのお客様環境への導入支援や製品の技術解説を担当するセールスコンサルタントチームのアジア太平洋地域リーダー。多国籍なM...

※プロフィールは、執筆時点、または直近の記事の寄稿時点での内容です

この記事は参考になりましたか?

この記事をシェア

EnterpriseZine(エンタープライズジン)
https://enterprisezine.jp/article/detail/3398 2012/07/09 16:44

Job Board

AD

おすすめ

アクセスランキング

アクセスランキング

イベント

EnterpriseZine(エンタープライズジン)編集部では、情報システム担当、セキュリティ担当の方々向けに、EnterpriseZine Day、Security Online Day、DataTechという、3つのイベントを開催しております。それぞれ編集部独自の切り口で、業界トレンドや最新事例を網羅。最新の動向を知ることができる場として、好評を得ています。

新規会員登録無料のご案内

  • ・全ての過去記事が閲覧できます
  • ・会員限定メルマガを受信できます

メールバックナンバー

アクセスランキング

アクセスランキング