データ型はある形式から別の形式に明示的または暗黙的に変換することができます。暗黙の変換がCriteriaとExpressionsで自動的に行われ、開発が容易になります。明示的なデータ型変換には、CONVERT関数またはCASTキーワードの使用が必要です。

タイプ変換の考察:

  • あらゆる型は、暗黙的にOBJECT型に変換することができます;
  • OBJECT型は、明示的に他の型に変換することができます;
  • NULLの値は任意の型に変換することができます;
  • 有効な暗黙的変換はすべて有効な明示的変換でもあります;
  • 通常、明示的な変換を必要とするリテラル値を含む状況では、情報の損失が発生しない場合、明示的な変換が暗黙的に適用されることがあります;
  • CData Virtuality Server が明示的な変換を Criteria 内で暗黙的に適用できないことを検出すると、Criteria は False として扱われます。例えば:

    SELECT * FROM my.table WHERE created_by = 'not a date'

    created_byが日付として型付けされていることを考えると、'not a date' を日付値に変換するのではなく、Criteria は文字列比較のままであるため、FALSEとなります;

  • 2つの型間で許可されていない明示的な変換は、実行前に例外が発生します。許可された明示的な変換は、実行時の値が変換可能でない場合、処理中に失敗する可能性があります。

The CData Virtuality Server conversions of float/double/bigdecimal/timestamp to string rely on the JDBC/Java-defined output formats. Pushdown behaviour attempts to mimic these results but may vary depending on the source type and conversion logic. Care should be taken not to assume the string form in criteria or other places where a variation may cause different results.

Type Conversions

Source type

Valid implicit target types

Valid explicit target types

string

clob

char, boolean, byte, short, integer, long, biginteger, float, double, bigdecimal, xml

string to xml is equivalent to XMLPARSE(DOCUMENT exp); see also XML Functions: XMLPARSE

char

string

-

boolean

string, byte, short, integer, long, biginteger, float, double, bigdecimal

-

byte

string, short, integer, long, biginteger, float, double, bigdecimal

boolean

short

string, integer, long, biginteger, float, double, bigdecimal

boolean, byte

integer

string, long, biginteger, double, bigdecimal

boolean, byte, short, float

long

string, biginteger, bigdecimal

boolean, byte, short, integer, float, double

biginteger

string, bigdecimal

boolean, byte, short, integer, long, float, double

bigdecimal

string

boolean, byte, short, integer, long, biginteger, float, double

date

string, timestamp

-

time

string, timestamp

-

timestamp

string

date, time

clob

string

-

xml

-

string

xml to string is equivalent to XMLSERIALIZE(exp AS STRING); see also XML Functions: XMLSERIALIZE