Professional Documents
Culture Documents
to_date('2003/07/09',
'yyyy/mm/dd')
To find all email addresses in a table that exists more than once:
SELECT email, COUNT(email) AS NumOccurrences FROM users GROUP BY email
HAVING ( COUNT(email) > 1 )
To find rows that occurs exactly once:
SELECT email FROM users GROUP BY email HAVING ( COUNT(email) = 1 )
SELECT COUNT FROM ((SELECT X103_CONTRACT_DT FROM
gpdjw_x103_gc01Iwb_stg1
MINUS
select d_exposure_start_date FROMb2rvl.stg_loan_contracts))
select * from error_log where to_char(err_date,'YYYY-MM-DD') ='2011-12-26'
order by err_date
select * from error_log where err_src='SAPU file'and to_char(Err_Date,'YYYYMM-DD')=To_char(sysdate,'YYYY-MM-DD')
Composite key
A composite key is a primary key that consists of more than one column. Oracle
will create a composite primary key index on the table to implement and enforce the
composite key. Composite keys are also known as concatenated or aggregate
keys.
,ipr.emple_dly_ipr_dt,ipra.EMPLE_DLY_ACTV_UNIT_QTY
RANK
Let's assume we want to assign a sequential order, or rank, to people within a department based on
salary, we might use the RANK function like.
SELECT empno,
deptno,
sal,
RANK() OVER (PARTITION BY deptno ORDER BY sal) "rank"
FROM
emp;
EMPNO
DEPTNO
SAL
rank
---------- ---------- ---------- ---------7934
10
1300
1
7782
10
2450
2
7839
10
5000
3
7369
20
800
1
7876
20
1100
2
7566
20
2975
3
7788
20
3000
4
7902
20
3000
4
7900
30
950
1
7654
30
1250
2
7521
30
1250
2
7844
7499
7698
30
30
30
1500
1600
2850
4
5
6
SQL>
What we see here is where two people have the same salary they are assigned the same rank. When
multiple rows share the same rank the next rank in the sequence is not consecutive.
DENSE_RANK
The DENSE_RANK function acts like the RANK function except that it assigns consecutive ranks.
SELECT empno,
deptno,
sal,
DENSE_RANK() OVER (PARTITION BY deptno ORDER BY sal) "rank"
FROM
emp;
EMPNO
DEPTNO
SAL
rank
---------- ---------- ---------- ---------7934
10
1300
1
7782
10
2450
2
7839
10
5000
3
7369
20
800
1
7876
20
1100
2
7566
20
2975
3
7788
20
3000
4
7902
20
3000
4
7900
30
950
1
7654
30
1250
2
7521
30
1250
2
7844
30
1500
3
7499
30
1600
4
7698
30
2850
5
SQL>
Hierarchy query
10
0
10
1
55
5
55
88
Data in Table
45
5
10
3
10
2
18
0
57
8
36
0
26
0
26
3
26
1
27
0