ORACLE 语句

Posted Apprentice

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ORACLE 语句相关的知识,希望对你有一定的参考价值。

最近接触数据上传,从前辈汲取经验,以及自己写的一些sql语句,方便以后统计数据,以及进行一些修改操作。

1--查询各部门数据量

--注意:结束日期设置为当前日期的下一天

select e.name, zz.sumCount

  from (select z.dept_id, sum(count) as sumCount

          from (select t.dept_id,

                       t.contents,

                       sql_excute(‘select count(*) from ‘ || t.table_name ||

                                  ‘ where xypt_entry_date > to_date(‘ ||

                                  chr(39) || ‘2018-09-01‘ || chr(39) || ‘,‘ ||

                                  chr(39) || ‘yyyy-MM-dd‘ || chr(39) ||

                                  ‘) and xypt_entry_date <to_date(‘ ||

                                  chr(39) || ‘2018-09-28‘ || chr(39) || ‘,‘ ||

                                  chr(39) || ‘yyyy-MM-dd‘ || chr(39) || ‘) AND DATA_STATE=1‘) as count           

                  from ustcdms.dms_contents t

                  where 1=1

                 -- and t.bus_type = ‘sgsxx‘ –查询双公示数据则取消注释,只查询双公示

                  ) z

         group by z.dept_id) zz,

       ustcdms.dms_tree e

 where zz.dept_id = e.id

 order by e.id

 

 

2--查询各目录数据量 查询某个时间段到现在的数据

 select e.name,

        t.contents,

        sql_excute(‘select count(*) from ‘ || t.table_name ||

                   ‘ where xypt_entry_date > to_date(‘ || chr(39) ||

                   ‘2017-07-01‘ || chr(39) || ‘,‘ || chr(39) ||

                   ‘yyyy-MM-dd‘ || chr(39) || ‘)‘) as count

   from ustcdms.dms_contents t, ustcdms.dms_tree e

  where t.dept_id = e.id

  order by t.dept_id;

 

3.查询各目录数据量 查询某个部门

 select e.name

 

,

        t.contents,

        sql_excute(‘select count(*) from ‘ || t.table_name ||

                   ‘ where xypt_entry_date >= to_date(‘ || chr(39) ||

                   ‘2018-01-01‘ || chr(39) || ‘,‘ || chr(39) ||

                   ‘yyyy-MM-dd‘ || chr(39) || ‘) and xypt_entry_date <to_date(‘ ||

                                  chr(39) || ‘2018-04-19‘ || chr(39) || ‘,‘ ||

                                  chr(39) || ‘yyyy-MM-dd‘ || chr(39) || ‘)‘) as count

   from ustcdms.dms_contents t, ustcdms.dms_tree e

  where t.dept_id = e.id  and e.name

 

 like ‘市公安局‘

  order by t.dept_id

 

 4--查询各目录数据量  查询某个时间段内

 select e.name,

        t.contents,

       sql_excute(‘select count(*) from ‘ || t.table_name ||

                                  ‘ where xypt_entry_date > to_date(‘ ||

                                  chr(39) || ‘2017-07-01‘ || chr(39) || ‘,‘ ||

                                  chr(39) || ‘yyyy-MM-dd‘ || chr(39) ||

                                  ‘) and xypt_entry_date <to_date(‘ ||

                                  chr(39) || ‘2017-07-28‘ || chr(39) || ‘,‘ ||

                                  chr(39) || ‘yyyy-MM-dd‘ || chr(39) || ‘)‘) as count

   from ustcdms.dms_contents t, ustcdms.dms_tree e

  where t.dept_id = e.id

  order by t.dept_id;

 

5.数据上传失败后,当批量修改某个时间段中的时间信息,统一修改

 

UPDATE T_01090059 t

 SET t.xypt_entry_date = to_date(‘2018-09-21 10:21:00‘,

                                   ‘yyyy-mm-dd hh24:mi:ss‘)

 WHERE t.name = ‘黄林‘

   and t.xypt_entry_date >=

       to_date(‘2018-09-21 10:05:29‘, ‘yyyy-mm-dd hh24:mi:ss‘);   (删除‘t.name=‘黄林’and’ 则是修改当前时间内所有的数据)

 

以上是关于ORACLE 语句的主要内容,如果未能解决你的问题,请参考以下文章

java oracle 的插入语句

java oracle 的插入语句

oracle SQL查询语句

oracle ddl语句用啥编辑

Oracle 语句如何转义

oracle查询语句中in后面数据较多怎么优化