ORACLE SQL CAST in case语句

时间:2018-05-17 15:36:13

标签: sql oracle casting integer case

在CASE声明中有没有办法将CAST作为INTEGER?

CASE 
WHEN SV.END_DATE IS NOT NULL THEN SV.END_DATE - SV.START_DATE 
ELSE 0
END AS DAYDIFF

1 个答案:

答案 0 :(得分:2)

是的,你可以cast数值数据类型的值,没有小数部分:

import tensorflow as tf
import numpy as np

dataset = np.array([(np.random.rand(), i/20) for i in range(100)])
dataset = tf.data.Dataset.from_tensor_slices(dataset)
dataset = dataset.shuffle(100)
iterator = dataset.make_one_shot_iterator()

a = iterator.get_next()
b = iterator.get_next()
loop_vars = [a, b]

def cond(a, b):
    l1 = tf.gather(a, 1)
    l2 = tf.gather(b, 1)
    return tf.equal(l1, l2)

def body(a, b):
    a = iterator.get_next()
    b = iterator.get_next()
    return a, b

loop = tf.while_loop(cond, body, loop_vars)


with tf.Session() as sess:
    for i in range(10):
        values = sess.run([loop])
        print values

或者您可以truncate the result,它也会删除值的小数部分:

CASE 
  WHEN SV.END_DATE IS NOT NULL THEN
    CAST(SV.END_DATE - SV.START_DATE AS NUMBER(38))
  ELSE 0
END AS DAYDIFF