본문 바로가기

분류 전체보기

[펌] 중복값 삭제에 Analytic Function을 사용하는 예제 The Power of Analytic Functions * 원문에서 필요한 부분만 발췌한 자료이므로 필요할 경우 원문을 확인하세요. In this article we show the power of analytic functions on an example : Removing Duplicate Rows. -- 중복값이 많아서 많은 행은 삭제해야 하는 테이블 확인 select count(*), count(distinct OBJECT_NAME) from t; COUNT(*) COUNT(DISTINCT OBJECT_NAME) ---------- --------------------------- 1697024 5017 Here you can see that we have more than 1.6 million.. 더보기
스크랩 - 행 복제를 이용한 집계 select deptno, job, sum(sal) from emp group by deptno, job union all select deptno, null, sum(sal) from emp group by deptno union all select null, null, sum(sal) from emp; 위의 쿼리를 다음처럼 변경해 볼 수 있다. ^^ -- 1단계 select * from (select deptno, job, sum(sal) as sum_sal from emp group by deptno, job) e, (select 1 as no from dual union all select 2 from dual union all select 3 from dual) order by no; -- 2단.. 더보기
BITAND (비트단위 AND연산 함수) BITAND (비트단위 AND연산 함수) BITAND 함수는 파라미터로 주어지는 expr1, expr2값에 대해서 비트단위 AND 연산을 수행한다. 정수값 5(이진수 101)와 정수값 1(이진수 001)을 파라미터로 주면, 정수값 1(이진수 1)을 반환한다. 파라미터는 음수가 아닌 정수값이어야 하고, 정수값을 반환한다. 오라클 문서에는 BITAND 함수가 DECODE와 함께 써서 아래 형태로 자주 사용된다고 했는데, DECODE(BITAND(col, 1), 1, ... 이렇게 함께 사용하는 것이 과연 쓸모가 많은지는 의문을 가지게 한다. 아래 예제로 BITAND 함수의 쓸모를 찾아보도록 하자. (특히 두 번째 파라미터가 1,2,4,8 인 경우를 눈여겨 보도록 하자.) SELECT rownum , BITA.. 더보기
스크랩 - /*+ BYPASS_UJVC */ and updatable views 업데이트 /*+ BYPASS_UJVC */ and updatable views High volume UPDATE statements with SET sub-queries can be one of hardest SQLs to tune. Consider the following: UPDATE my_table a SET col1 = (SELECT col1 FROM my_temp_table WHERE key = a.key) WHERE col3 = 'BLORT' This SQL will probably perform a full table scan on my_table (not such a problem) and then for every row returned, it will perform an indexed SELEC.. 더보기
SQL*Plus Substitution Variables Christopher Jones Updated February 2004 Contents 1 Introduction 2 Using Substitution Variables 2.1 Creating, Showing and Deleting Substitution Variables 2.2 Referencing Substitution Variables 2.3 Prompting for Undefined Variables 2.4 Difference Between "&" and "&&" Prefixes 2.5 Storing a Query Column Value in a Substitution Variable 2.6 Predefined Substitution Variables 2.7 Script Parameters 2.8.. 더보기