sql >> Databasteknik >  >> RDS >> Oracle

script för siffror som saknas fungerar inte?

Se detta exempel

WITH ORDH
     AS (SELECT 1111 AS ORDERNO FROM DUAL
         UNION ALL
         SELECT 1112 AS ORDERNO FROM DUAL
         UNION ALL
         SELECT 1115 AS ORDERNO FROM DUAL
         UNION ALL
         SELECT 1116 AS ORDERNO FROM DUAL
         UNION ALL
         SELECT 1118 AS ORDERNO FROM DUAL
         UNION ALL
         SELECT 1121 AS ORDERNO FROM DUAL),
     GOT_NEXT_ORDERNO
     AS (SELECT ORDERNO,
                LEAD ( ORDERNO ) OVER (ORDER BY ORDERNO) AS NEXT_ORDERNO
         FROM   ORDH)
SELECT ORDERNO + 1 AS FROM_NO, NEXT_ORDERNO - 1 AS TO_NO
FROM   GOT_NEXT_ORDERNO
WHERE  ORDERNO + 1 <> NEXT_ORDERNO;

   FROM_NO      TO_NO
---------- ----------
      1113       1114
      1117       1117
      1119       1120

3 rows selected.



  1. Få den första, andra, tredje eller fjärde måndagen i en månad i SQLite

  2. MySQL Hur skapar jag den här underfrågan?

  3. Oracle BLOB-datatyp till RichTextBox

  4. AWS rds - Hur läser man från en läs replika inuti en Java-applikation?