Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.Opens in a new tab

For information on migrating to InterSystems IRISOpens in a new tab, see Why Migrate to InterSystems IRIS?

$Get 関数

$Get 関数を使用すると、変数の有無にかかわらず、確実に変数にアクセスします。変数が存在する場合、$Get は値を返します。変数が存在しない場合、$Get は空文字列か $Get の 2 番目の引数として指定した文字列を返します。

SAMPLES>write $get(fred)

SAMPLES>write $get(fred, 2)
2
SAMPLES>set fred = 1

SAMPLES>write $get(fred, 2)
1
SAMPLES>

定義の有無が不確かな配列にアクセスしたい場合、If 文と $Data 関数を使用してコードを記述することもできますが、$Get 関数を使用する方が簡単です。

SAMPLES>set a(3) = "yes"

SAMPLES>set x = "no" if $data(a(3)) { set x = a(3) }

SAMPLES>write x
yes
SAMPLES>kill x

SAMPLES>set x = $get(a(3), "no")

SAMPLES>write x
yes
SAMPLES>
FeedbackOpens in a new tab