Oracle

Oracle的rollup、cube、grouping sets函数

﹥>﹥吖頭↗ 提交于 2021-02-08 04:22:17
转载自:https://blog.csdn.net/huang_xw/article/details/6402396 Oracle的group by除了基本用法以外,还有3种扩展用法,分别是rollup、cube、grouping sets。 1 rollup 假设有一个表test,有A、B、C、D、E5列。 如果使用group by rollup(A,B,C),首先会对(A、B、C)进行GROUP BY,然后对(A、B)进行GROUP BY,然后是(A)进行GROUP BY,最后对全表进行GROUP BY操作。roll up的意思是“卷起”,这也可以帮助我们理解group by rollup就是对选择的列从右到左以一次少一列的方式进行grouping直到所有列都去掉后的grouping(也就是全表grouping),对于n个参数的rollup,有n+1次的grouping 。以下2个sql的结果集是一样的: Select A,B,C,sum(E) from test group by rollup(A,B,C) 与 Select A,B,C,sum(E) from test group by A,B,C union all Select A,B,null,sum(E) from test group by A,B union all Select A,null,null,sum

Oracle - Index use with optional parameters

情到浓时终转凉″ 提交于 2021-02-08 04:03:43
问题 I use the following trick to be able to index a column that has some nulls: create index xx_people_idx1 on xx_people(id_number, -1); This works great. Sadly this does not help for when you use optional parameters though: select * from xx_people where id_number = nvl(:p_id_number, id_number); This results in a full table scan, even when you provide a value for p_id_number . Is there a trick to use the index in this situation? Since searching by id number and name are my only 2 searches this is

[转]详解Oracle高级分组函数(ROLLUP, CUBE, GROUPING SETS)

ぃ、小莉子 提交于 2021-02-08 03:31:31
原文地址:http://blog.csdn.net/u014558001/article/details/42387929 本文主要讲解 ROLLUP, CUBE, GROUPING SETS的主要用法,这些函数可以理解为GroupBy分组函数封装后的精简用法,相当于多个union all 的组合显示效果,但是要比 多个union all的效率要高。 其实这些函数在时间的程序开发中应用的并不多,至少在我工作的多年时间中没用过几次,因为现在的各种开发工具/平台都自带了这些高级分组统计功能,使用的方便性及美观性都比这些要好。但如果临时查下数据,用这些函数还是不错的。 创建测试环境 1. 创建表 [sql] view plain copy createtable EMP2 ( ID NUMBER, -- 员工编号 NAME VARCHAR2(20), --姓名 SEX VARCHAR2(2), --性别 HIREDATE DATE, --入职日期 BASE VARCHAR2(20), --工作母地 DEPT VARCHAR2(20), --所在部门 SAL NUMBER --月工资 ); 2. 插入测试数据 [sql] view plain copy insert into emp2 (ID, NAME, SEX, HIREDATE,BASE, DEPT, SAL) values

SQL SELECT Sum values without including duplicates

橙三吉。 提交于 2021-02-08 02:20:01
问题 I have a problem in Oracle SQL that I'm trying to get my head around. I'll illustrate with an example. I have three tables that I am querying: Employees __________________________________________ | EmployeeID | Name | | 1 | John Smith | | 2 | Douglas Hoppalot | | 3 | Harry Holiday | ... InternalCosts ________________________________ | IntID | Amount | EmployeeID | | 1 | 10 | 1 | | 2 | 20 | 2 | | 3 | 30 | 1 | ... ExternalCosts ________________________________ | ExtID | Amount | EmployeeID | |

SQL SELECT Sum values without including duplicates

送分小仙女□ 提交于 2021-02-08 02:13:41
问题 I have a problem in Oracle SQL that I'm trying to get my head around. I'll illustrate with an example. I have three tables that I am querying: Employees __________________________________________ | EmployeeID | Name | | 1 | John Smith | | 2 | Douglas Hoppalot | | 3 | Harry Holiday | ... InternalCosts ________________________________ | IntID | Amount | EmployeeID | | 1 | 10 | 1 | | 2 | 20 | 2 | | 3 | 30 | 1 | ... ExternalCosts ________________________________ | ExtID | Amount | EmployeeID | |

SQL SELECT Sum values without including duplicates

北城以北 提交于 2021-02-08 02:13:17
问题 I have a problem in Oracle SQL that I'm trying to get my head around. I'll illustrate with an example. I have three tables that I am querying: Employees __________________________________________ | EmployeeID | Name | | 1 | John Smith | | 2 | Douglas Hoppalot | | 3 | Harry Holiday | ... InternalCosts ________________________________ | IntID | Amount | EmployeeID | | 1 | 10 | 1 | | 2 | 20 | 2 | | 3 | 30 | 1 | ... ExternalCosts ________________________________ | ExtID | Amount | EmployeeID | |

Oracle Data Provider for .NET does not support Oracle 19.0.48.0.0

拥有回忆 提交于 2021-02-08 02:08:27
问题 We just upgraded to Oracle 19c (19.3.0) and all apps stopped working with this error message: Oracle Data Provider for .NET does not support Oracle 19.0.48.0.0 I updated Oracle.ManagedDataAccess.EntityFramework and Oracle.ManagedDataAccess to 19.3.0 Any solution? 来源: https://stackoverflow.com/questions/57717088/oracle-data-provider-for-net-does-not-support-oracle-19-0-48-0-0

Oracle SQL Developer - Error: “FROM keyword not found where expected”

房东的猫 提交于 2021-02-08 02:05:12
问题 Sorry for my noob question but I'm trying to figure out why my Oracle-SQL indicates the error "FROM keyword not found where expected" as the picture below: The code I'm trying to run is the following: select PCKCOO AS 'COMPANHIA_DO_PEDIDO_NUMERO_DO_PEDIDO', PCDOCO AS 'DOCUMENTO_NUMERO_DA_OS_FATURA', PCDCTO AS 'TIPO_DE_ORDEM', PCSFXO AS 'SUFIXO_DO_PEDIDO', rpad(HORDT,'0',6) AS 'HORARIO_DE_LIBERACAO', FX_PARA_GREGORIANA(HORDJ, 'DD/MM/YYYY')||' '||rpad(HORDT,6,'0') "APROVACAO", rank() over

Combining Two Tables With Oracle SQL

主宰稳场 提交于 2021-02-07 21:57:00
问题 I have two tables in the following structure: TABLE 1: ITEM | JAN | FEB | MAR | APR | MAY | JUN ___________________________________________ Item A| 50 | 10 | 25 | NULL| NULL| NULL Item C| 26 | 20 | 23 | NULL| NULL| NULL Item B| 25 | 30 | 22 | NULL| NULL| NULL TABLE 2: ITEM | JAN | FEB | MAR | APR | MAY | JUN ___________________________________________ Item A| NULL| NULL| NULL| 32 | 26 | 12 Item B| NULL| NULL| NULL| 25 | 24 | 10 Item D| NULL| NULL| NULL| 22 | 35 | 14 I am trying to merge the

Combining Two Tables With Oracle SQL

a 夏天 提交于 2021-02-07 21:56:20
问题 I have two tables in the following structure: TABLE 1: ITEM | JAN | FEB | MAR | APR | MAY | JUN ___________________________________________ Item A| 50 | 10 | 25 | NULL| NULL| NULL Item C| 26 | 20 | 23 | NULL| NULL| NULL Item B| 25 | 30 | 22 | NULL| NULL| NULL TABLE 2: ITEM | JAN | FEB | MAR | APR | MAY | JUN ___________________________________________ Item A| NULL| NULL| NULL| 32 | 26 | 12 Item B| NULL| NULL| NULL| 25 | 24 | 10 Item D| NULL| NULL| NULL| 22 | 35 | 14 I am trying to merge the