在创建具有订单的视图时缺少右括号

时间:2017-12-12 08:35:36

标签: sql oracle

为什么这样保留ORA-00907:缺少右括号

CREATE VIEW LAPORAN_POSTINGANBULANAN (BULAN_TAHUN,JUMLAH POSTING) 
AS
SELECT TO_CHAR(POST.TANGGAL_POSTING, 'YYYY-MM') AS "BULAN_TAHUN", 
       COUNT(*) AS "JUMLAHPOSTING"
FROM POST (
GROUP BY TO_CHAR(POST.TANGGAL_POSTING, 'YYYY-MM')
ORDER BY TO_CHAR(POST.TANGGAL_POSTING, 'YYYY-MM') ASC);

3 个答案:

答案 0 :(得分:0)

不需要paranthesis来包装组,因为它在语法上是错误的。 尝试删除它,如下所示它应该工作

CREATE VIEW LAPORAN_POSTINGANBULANAN (
    BULAN_TAHUN
    ,JUMLAH POSTING
    )
AS
SELECT TO_CHAR(POST.TANGGAL_POSTING, 'YYYY-MM') AS "BULAN_TAHUN"
    ,COUNT(*) AS "JUMLAHPOSTING"
FROM POST
GROUP BY TO_CHAR(POST.TANGGAL_POSTING, 'YYYY-MM') 
ORDER BY TO_CHAR(POST.TANGGAL_POSTING, 'YYYY-MM') ASC;

答案 1 :(得分:0)

视图没有参数或输出规范。因此我写的如下:

CREATE VIEW LAPORAN_POSTINGANBULANAN AS
  SELECT TO_CHAR(POST.TANGGAL_POSTING, 'YYYY-MM') AS "BULAN_TAHUN", 
         COUNT(*) AS "JUMLAHPOSTING"
  FROM POST 
  GROUP BY TO_CHAR(POST.TANGGAL_POSTING, 'YYYY-MM')
  ORDER BY TO_CHAR(POST.TANGGAL_POSTING, 'YYYY-MM') ASC;

答案 2 :(得分:0)

使用派生表简化代码,您不必多次重写CREATE VIEW LAPORAN_POSTINGANBULANAN (BULAN_TAHUN, JUMLAH_POSTING) AS SELECT "BULAN_TAHUN", COUNT(*) AS "JUMLAHPOSTING" FROM ( SELECT TO_CHAR(POST.TANGGAL_POSTING, 'YYYY-MM') AS "BULAN_TAHUN" FROM POST ) DT GROUP BY "BULAN_TAHUN" ORDER BY "BULAN_TAHUN" ASC 部分:

emulator