概要:このチュートリアルでは、PL/pgSQL select intoステートメントを使って、データベースからデータを選択し変数に割り当てる方法を学習していただきます。
Introduction to PL/pgSQL Select Into statement
The select into statement allows you to select data from the database and assign the data to a variable.
The following illustrates the syntax of the select into statement:
Code language: PostgreSQL SQL dialect and PL/pgSQL (pgsql)
In this syntax, you place the variable after the into keyword.This documentation, in a single variable assignment to the variable in the database.The following shows the構文は、以下の通りです。 select intoステートメントは、select句によって返されたデータを変数に割り当てます。
テーブルからデータを選択する以外にも、join、group by,、havingといったselectステートメントの他の句を使用することが可能です。
PL/pgSQL Select Intoステートメントの例
次の例を参照してください:
Code language: PostgreSQL SQL dialect and PL/pgSQL (pgsql)
出力:
Code language: Shell Session (shell)
この例では:
- 最初に、
actorテーブルからの俳優の数を格納するactor_countという変数を宣言してください。 - 次に、
select intoステートメントを使用してactor_countに俳優の数を代入します。 - 最後に、
raise noticeステートメントを使用して変数actor_countの値を示すメッセージを表示します。
まとめ
-
select intoステートメントを使用してデータベースからデータを選択し、変数に割り当てます。
- Was this tutorial helpful ?
- YesNo