NVARCHAR2 表示为十六进制

NVARCHAR2 is being represented as hex

我有一个 NVARCHAR2 field in Oracle and I'm doing a LISTAGG 并在其中附加了一些文本。

LISTAGG(
  CASE
    WHEN a.is_dead = 'Y' AND a.death_cause IS NOT NULL AND a.death_date IS NOT NULL THEN a.composite_pednum || ' - ' || a.death_cause || ' (' || a.death_date || ')'
    WHEN a.is_dead = 'Y' AND a.death_cause IS NOT NULL THEN a.composite_pednum || ' - ' || a.death_cause
    WHEN a.is_dead = 'Y' THEN a.composite_pednum || ' - Dead'
    WHEN a.is_dead = 'N' THEN a.composite_pednum || ' - Alive'
    ELSE a.composite_pednum || ' - Unknown Status'
  END,
  ';'
) WITHIN GROUP (ORDER BY a.pedigree_number ASC) AS cage_animals

在PHP中,我explode将这段文字转成数组,待会处理。

$cage_animals = array();
if(!empty($data['CAGE_ANIMALS'][$i])) {
  $cage_animals = explode(';', $data['CAGE_ANIMALS'][$i]);
}

这给了我类似的东西

["cage_animals"]=>
  array(2) {
    [0]=>
    string(38) "R15-57713-B - Alive"
    [1]=>
    string(40) "R15-57714-RR - Alive"
  }

注意到字符串的长度看起来比实际长度多了吗?我认为这可能是因为以下屏幕截图 (不是完整屏幕截图):

所以我的问题是如何防止这种情况发生?我试图找到 Alivestrpos,但我总是得到 false,因为找不到文本。

我最终为每个 THEN 子句使用了 CASTTO_CHAR

LISTAGG(
  CASE
    WHEN a.is_dead = 'Y' AND a.death_cause IS NOT NULL AND a.death_date IS NOT NULL THEN TO_CHAR(a.composite_pednum || ' - ' || a.death_cause || ' (' || TO_CHAR(a.death_date, 'Mon DD, YYYY') || ')')
    WHEN a.is_dead = 'Y' AND a.death_cause IS NOT NULL THEN TO_CHAR(a.composite_pednum || ' - ' || a.death_cause)
    WHEN a.is_dead = 'Y' THEN TO_CHAR(a.composite_pednum || ' - Dead')
    WHEN a.is_dead = 'N' THEN TO_CHAR(a.composite_pednum || ' - Alive')
    ELSE TO_CHAR(a.composite_pednum || ' - Unknown Status')
  END,
  ';'
) WITHIN GROUP (ORDER BY a.pedigree_number ASC) AS cage_animals