MariaDBでは、RIGHT() は、文字列の右端から指定された数の文字を返す組み込みの文字列関数です。
RIGHT() 2つの引数を受け入れます。文字列、およびその文字列の右側から返される文字数。
構文
構文は次のようになります:
RIGHT(str,len)
str は文字列であり、len 文字列の右側から抽出する文字数です。
例
基本的な例は次のとおりです。
SELECT RIGHT('Aerospace', 5); 結果:
+-----------------------+
| RIGHT('Aerospace', 5) |
+-----------------------+
| space |
+-----------------------+ データベースの例
データベース列の値の正しい部分を取得する例を次に示します。
SELECT
ProductName,
RIGHT(ProductName, 11) AS "Right part"
FROM Products; 結果:
+---------------------------------+-------------+ | ProductName | Right part | +---------------------------------+-------------+ | Left handed screwdriver | screwdriver | | Right handed screwdriver | screwdriver | | Long Weight (blue) | ight (blue) | | Long Weight (green) | ght (green) | | Sledge Hammer | edge Hammer | | Chainsaw | Chainsaw | | Straw Dog Box | raw Dog Box | | Bottomless Coffee Mugs (4 Pack) | gs (4 Pack) | +---------------------------------+-------------+
ヌル引数
引数のいずれか(またはすべて)がnullの場合 、RIGHT() 関数はnullを返します :
SELECT
RIGHT(null, 3),
RIGHT('Coffee', null),
RIGHT(null, null); 結果:
+----------------+-----------------------+-------------------+
| RIGHT(null, 3) | RIGHT('Coffee', null) | RIGHT(null, null) |
+----------------+-----------------------+-------------------+
| NULL | NULL | NULL |
+----------------+-----------------------+-------------------+ 引数がありません
RIGHT()を呼び出す 引数を渡さないとエラーが発生します:
SELECT RIGHT(); 結果:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1