我需要今天的日期输出来进行操作

时间:2018-10-06 05:56:10

标签: oracle stored-procedures

我的存储过程如下:

WITH dates
AS
  (SELECT (dt + level - 1) AS etadate
  FROM
    (SELECT TRUNC(DATE '2018-09-01', 'MM') - 1 AS dt FROM DUAL
    ) d
    CONNECT BY LEVEL <= sysdate - dt + 1
  )
SELECT TO_CHAR(TO_DATE(d.etadate,'DD-MM-YYYY HH24:MI:SS'),'DD-MM-YY')           AS DATEFORM,
  COALESCE(nsp.YNAME, LAG(nsp.YNAME IGNORE NULLS) OVER (ORDER BY d.etadate))         AS YNAME,
  COALESCE(nsp.CATEGORY, LAG(nsp.CATEGORY IGNORE NULLS) OVER (ORDER BY d.etadate))           AS CATEGORY,
  COALESCE(nsp.TYPE, LAG(nsp.TYPE IGNORE NULLS) OVER (ORDER BY d.etadate)) AS TYPE,
  COALESCE(nsp.STOCK_BALANCE, LAG(nsp.STOCK_BALANCE IGNORE NULLS) OVER (ORDER BY d.etadate)) AS STOCK_BALANCE
FROM dates d
LEFT JOIN VW_NET_STOCK_POSITION nsp 
 ON d.etadate = TRUNC(nsp.LAST_UPD_IS)

这是输出:

OUTPUT

现在,我只想输出今天的日期。输出应该是此输出的最后记录,因为今天是2018年10月6日。

1 个答案:

答案 0 :(得分:1)

  

需要在null处重复上一次交易

最简单的方法是采用原始查询并将其包装在过滤查询中:

where
   (case when Note is null then 1 else 0 end)
 <>(case when ID is null then 1 else 0 end)

在现实生活中,这种性能可能并不出色,这取决于基础表中有多少数据。