NVARCHAR2被表示为十六进制

时间:2019-03-21 18:41:42

标签: php string oracle hex nvarchar

我在Oracle中有一个NVARCHAR2字段,我正在做一个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"
  }

请注意,字符串的长度看起来比实际的长多少?我认为这可能是由于以下屏幕截图(而不是完整的屏幕截图)

enter image description here

所以我的问题是如何防止这种情况发生?我试图找到Alive中的strpos,但由于找不到文本,我总是得到false

1 个答案:

答案 0 :(得分:0)

我最终为每个CAST子句使用了TO_CHARTHEN

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