본문 바로가기

Database&WAS

[Oracle] COALESCE() 함수 - COALESCE(a1, a2, a3, a4,... aN) * a1 부터 aN까지 첫음으로 null 이 아닌 값을 리턴 * 모든 값이 null 이면 null 리턴 ex) sale1/2/3 중에 순서대로 비교해서 null 이 아닌 첫번째 값을 가져오고 모두 null이면 0을 리턴 SELECT COALESCE(sale1,sale2,sale3,0) FROM product WHERE id = :key1 DECODE로 쓰면... DECODE(sale1,NULL, DECODE(sale2,NULL,DECODE(sale3,NULL,0,sale3),sale2),sale1) NVL 쓰면... NVL(COALESCE(sale1,sale2,sale3),0) 또는 NVL(sale1,NVL(sale2,NVL(sale3,0))).. 더보기
[Oracle] NULLIF() 함수 - NULLIF(a1, a2) a1 = a2 면 null 리턴, 같지 않으면 a1을 리턴 ex) SELECT old_id, NULLIF(new_id,old_id) "new_id" FROM customer CASE 문으로 쓴다면.. CASE WHEN new_id = old_id THEN NULL ELSE new_id END DECODE 로 쓴다면.. DECODE(a1,a2,NULL,a1) 더보기
[Oracle] SUM() 함수 합계를 구하는 함수 ^^; 요지는 각 레코드별 합계를 구하되 한편으로 총 누계를 한꺼번에 구하는 방법 방법이야 조인이든, 합계 변수를 둬서 프로그램 하든, 합계 쿼리만 한번 더 돌리든...여러가지지만 그중 하나.. 예제를 보는게 나을 듯 ㅎㅎ SELECT mcode, total, unload, transfer, special, SUM (total) OVER (ORDER BY mcode) AS t_weight, SUM (unload) OVER (ORDER BY mcode) AS t_unload, SUM (transfer) OVER (ORDER BY mcode) AS t_trnasfer, SUM (special) OVER (ORDER BY mcode) AS t_sepcial FROM (SELECT a.mco.. 더보기
HINTs #1 - [Oracle] The application developer and end users know more about the data and how it is used than the optimizer does. Oracle provides a method known as HINTS to enable you to tell the optimizer the method to use for the SQL statement. Oracle recommends that HINTS not be used as the main method of controlling the optimization for SQL statements. Instead, the SQL statement should be appropriately rewritten.. 더보기
HINTs #2 - [Oracle] Specifies if any of the tables or indexes in the statement are analyzed, use the Cost Based optimizer otherwise use the Rule Based. If they are analyzed, it uses the cost based optimizer to provide the best response time for batch processing. Processing the SQL statements using ALL_ROWS is the best practice for databases that have large amounts of batch processing, such as Data Warehouses. It is.. 더보기
Hint 요약 - [Oracle] A. initialization parameter중 OPTIMIZER_MODE 지정가능 값 1.ALL_ROWS Goal : Best Throughput 용도 : 전체 RESOURCE 소비를 최소화 시키기 위한 힌트. Cost-Based 접근방식. 예 : SELECT /*+ALL_ROWS */ EMPNO,ENAME FROM EMP WHERE EMPNO = 7655; 2.FIRST_ROWS Goal : Best Response Time 용도 : 조건에 맞는 첫번째 row를 리턴하기 위한 Resource 소비를 최소화 시키기위한 힌트. Cost-Based 접근방식. 특징 : - Index Scan 이 가능하다면 Optimizer가 Full Table Scan 대신 Index Scan을 선택한다. - Index.. 더보기