关于ORA-00907: missing right parenthesis问题整理

昨天我在写存储过程的时候,在把系统时间格式转换用于与数据库字段做比较,当我test时抛出ORA-00907: missing right parenthesis,缺省右括号;

下面是我的出错代码:

 dynamic_sql := 'select t3.departmentcode, t3.total from (select departmentcode,count(*) total from  ' || str_tablename || ' where  (LASTUPDATEDTIME between to_date(to_char(sysdate-1,"yyyy-mm-dd")  ,''yyyy-mm-dd'') and to_date(to_char(sysdate,"yyyy-mm-dd") ,''yyyy-mm-dd''))  and departmentcode is not NULL group by departmentcode) t3,v_s_data_input_dept_usernum t4 where t3.departmentcode = ' || str_departmentcode || '';
  

 

更正后,执行成功的代码:

dynamic_sql := 'select t3.departmentcode, t3.total from (select departmentcode,count(*) total from  ' || str_tablename || ' where  (LASTUPDATEDTIME between to_date(''' || to_char(sysdate-1,'yyyy-mm-dd') || ''',''yyyy-mm-dd'') and to_date(''' || to_char(sysdate,'yyyy-mm-dd') || ''',''yyyy-mm-dd''))  and departmentcode is not NULL group by departmentcode) t3,v_s_data_input_dept_usernum t4 where t3.departmentcode = ' || str_departmentcode || '';

 

红色的部分对比

希望对出现类似错误的有所帮助


----------------

还有第二种情况


(Oracle测试)使用SQL语句的select语句是经常会用到字段和表的的别名,使用要注意,字段的别名前面可以加as关键字,或是省略不写,但是表名的别名前面不可以加as,否则会报如下错误:

命令出错, 行: 11 列: 20
错误报告:
SQL 错误: ORA-00907: 缺失右括号
00907. 00000 -  "missing right parenthesis"
*Cause:   
*Action:



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值