Data Base Issues - Oracle EBS R12: Checking swap space: 0 MB available, 1535 MB requi...: http://dbissues.blogspot.com/2016/02/i-am-trying-to-install-portal-forms.html I am trying to install "Oracle Reports and forms ...
Wednesday, February 20, 2019
Thursday, February 7, 2019
use sql case
12:13 PM
No comments
Mastering+Oracle+SQL
SELECT pm.emp_no, pm.ipd_admission_dept,
(SELECT dept_name
FROM hr_dept
WHERE dept_no = 1168) ipd_admission_cp, pm.ipd_visitor_dept,
(SELECT dept_name
FROM hr_dept
WHERE dept_no = 1183) ipd_visitor_cp, pm.em_billing_dept,
(SELECT dept_name
FROM hr_dept
WHERE dept_no = 1197) em_billing_cp, pm.ipd_epi_dept,
(SELECT dept_name
FROM hr_dept
WHERE dept_no = 1204) epi_cp, fnc_empname (pm.emp_no) ename,
SUM (pm.pay_amt) pay_amt, SUM (pm.c_amt) p_amt, SUM (pm.n_amt) n_amt,
SUM (pm.c_amt - pm.n_amt) tot_fract, SUM (pm.ref_amt) ref_amt,
(SUM (pm.pay_amt + pm.c_amt) - SUM (pm.n_amt + pm.ref_amt)
) net_coll
FROM (SELECT entered_by emp_no, (SELECT dept_no
FROM hr_dept
WHERE dept_no = 1168)
ipd_admission_dept,
(SELECT dept_no
FROM hr_dept
WHERE dept_no = 1183) ipd_visitor_dept,
(SELECT dept_no
FROM hr_dept
WHERE dept_no = 1197) em_billing_dept,
(SELECT dept_no
FROM hr_dept
WHERE dept_no = 1204) ipd_epi_dept,
CASE
WHEN trx_code_no IN ('PM', 'DP')
THEN ABS (cr_amt - dr_amt)
ELSE 0
END pay_amt,
CASE
WHEN trx_code_no IN ('PC', 'RC')
THEN ABS (cr_amt - dr_amt)
ELSE 0
END c_amt,
CASE
WHEN trx_code_no = 'NC'
THEN ABS (cr_amt - dr_amt)
ELSE 0
END n_amt,
CASE
WHEN trx_code_no = 'RF'
THEN ABS (cr_amt - dr_amt)
ELSE 0
END ref_amt
FROM fn_patledger
WHERE dept_no IN (1204, 1168, 1183, 1197)
AND entered_by = NVL (UPPER (:p_entered_by), entered_by)
AND TRUNC (entry_timestamp) BETWEEN NVL (:p_date_1,
TRUNC (entry_timestamp)
)
AND NVL (:p_date_2,
TRUNC (entry_timestamp)
)) pm
GROUP BY pm.emp_no,
pm.ipd_admission_dept,
pm.ipd_visitor_dept,
pm.em_billing_dept,
pm.ipd_epi_dept
ORDER BY fnc_empname (pm.emp_no)
##---
SELECT COUNT (reg_no) total, gender, CATEGORY,
CASE CATEGORY
WHEN 'Infant'
THEN 1
WHEN 'Child'
THEN 2
WHEN 'Young'
THEN 3
WHEN 'Adult'
THEN 4
WHEN 'Senior'
THEN 5
WHEN 'Most Senior'
THEN 6
ELSE 7
END cat
FROM (SELECT reg_no, gender, CATEGORY
FROM ehrv_patientlist_today
WHERE appoint_date BETWEEN NVL (:p_dt1, appoint_date)
AND NVL (:p_dt2, appoint_date))
GROUP BY gender, CATEGORY
ORDER BY cat;
----use case in where condition
WHERE patinfo.pathology =
CASE
WHEN NVL (p_pathology, 'N') = 'N'
AND NVL (p_imaging, 'N') = 'N'
AND NVL (p_due, 'N') = 'N'
AND NVL (p_overdue, 'N') = 'N'
AND NVL (p_ot, 'N') = 'N'
AND NVL (p_cannula, 'N') = 'N'
THEN NVL (p_pathology, patinfo.pathology)
ELSE p_pathology
END
OR patinfo.imaging =
CASE
WHEN NVL (p_pathology, 'N') = 'N'
AND NVL (p_imaging, 'N') = 'N'
AND NVL (p_due, 'N') = 'N'
AND NVL (p_overdue, 'N') = 'N'
AND NVL (p_ot, 'N') = 'N'
AND NVL (p_cannula, 'N') = 'N'
THEN NVL (p_imaging, patinfo.imaging)
ELSE p_imaging
END
OR patinfo.due =
CASE
WHEN NVL (p_pathology, 'N') = 'N'
AND NVL (p_imaging, 'N') = 'N'
AND NVL (p_due, 'N') = 'N'
AND NVL (p_overdue, 'N') = 'N'
AND NVL (p_ot, 'N') = 'N'
AND NVL (p_cannula, 'N') = 'N'
THEN NVL (p_due, patinfo.due)
ELSE p_due
END
OR patinfo.overdue =
CASE
WHEN NVL (p_pathology, 'N') = 'N'
AND NVL (p_imaging, 'N') = 'N'
AND NVL (p_due, 'N') = 'N'
AND NVL (p_overdue, 'N') = 'N'
AND NVL (p_ot, 'N') = 'N'
AND NVL (p_cannula, 'N') = 'N'
THEN NVL (p_overdue, patinfo.overdue)
ELSE p_overdue
END
OR patinfo.cann =
CASE
WHEN NVL (p_pathology, 'N') = 'N'
AND NVL (p_imaging, 'N') = 'N'
AND NVL (p_due, 'N') = 'N'
AND NVL (p_overdue, 'N') = 'N'
AND NVL (p_ot, 'N') = 'N'
AND NVL (p_cannula, 'N') = 'N'
THEN NVL (p_cannula, patinfo.cann)
ELSE p_cannula
END
OR patinfo.pot =
CASE
WHEN NVL (p_pathology, 'N') = 'N'
AND NVL (p_imaging, 'N') = 'N'
AND NVL (p_due, 'N') = 'N'
AND NVL (p_overdue, 'N') = 'N'
AND NVL (p_ot, 'N') = 'N'
AND NVL (p_cannula, 'N') = 'N'
THEN NVL (p_ot, patinfo.pot)
ELSE p_ot
END
AND patinfo.death = NVL (p_death, patinfo.death);
-----use >any means greate than smaller number
>all means greater than largest number
multicolumn subquery example
select * from emp where (sal,dept) in
(select max(sal),dept_no from emp group by dept)
SELECT pm.emp_no, pm.ipd_admission_dept,
(SELECT dept_name
FROM hr_dept
WHERE dept_no = 1168) ipd_admission_cp, pm.ipd_visitor_dept,
(SELECT dept_name
FROM hr_dept
WHERE dept_no = 1183) ipd_visitor_cp, pm.em_billing_dept,
(SELECT dept_name
FROM hr_dept
WHERE dept_no = 1197) em_billing_cp, pm.ipd_epi_dept,
(SELECT dept_name
FROM hr_dept
WHERE dept_no = 1204) epi_cp, fnc_empname (pm.emp_no) ename,
SUM (pm.pay_amt) pay_amt, SUM (pm.c_amt) p_amt, SUM (pm.n_amt) n_amt,
SUM (pm.c_amt - pm.n_amt) tot_fract, SUM (pm.ref_amt) ref_amt,
(SUM (pm.pay_amt + pm.c_amt) - SUM (pm.n_amt + pm.ref_amt)
) net_coll
FROM (SELECT entered_by emp_no, (SELECT dept_no
FROM hr_dept
WHERE dept_no = 1168)
ipd_admission_dept,
(SELECT dept_no
FROM hr_dept
WHERE dept_no = 1183) ipd_visitor_dept,
(SELECT dept_no
FROM hr_dept
WHERE dept_no = 1197) em_billing_dept,
(SELECT dept_no
FROM hr_dept
WHERE dept_no = 1204) ipd_epi_dept,
CASE
WHEN trx_code_no IN ('PM', 'DP')
THEN ABS (cr_amt - dr_amt)
ELSE 0
END pay_amt,
CASE
WHEN trx_code_no IN ('PC', 'RC')
THEN ABS (cr_amt - dr_amt)
ELSE 0
END c_amt,
CASE
WHEN trx_code_no = 'NC'
THEN ABS (cr_amt - dr_amt)
ELSE 0
END n_amt,
CASE
WHEN trx_code_no = 'RF'
THEN ABS (cr_amt - dr_amt)
ELSE 0
END ref_amt
FROM fn_patledger
WHERE dept_no IN (1204, 1168, 1183, 1197)
AND entered_by = NVL (UPPER (:p_entered_by), entered_by)
AND TRUNC (entry_timestamp) BETWEEN NVL (:p_date_1,
TRUNC (entry_timestamp)
)
AND NVL (:p_date_2,
TRUNC (entry_timestamp)
)) pm
GROUP BY pm.emp_no,
pm.ipd_admission_dept,
pm.ipd_visitor_dept,
pm.em_billing_dept,
pm.ipd_epi_dept
ORDER BY fnc_empname (pm.emp_no)
##---
SELECT COUNT (reg_no) total, gender, CATEGORY,
CASE CATEGORY
WHEN 'Infant'
THEN 1
WHEN 'Child'
THEN 2
WHEN 'Young'
THEN 3
WHEN 'Adult'
THEN 4
WHEN 'Senior'
THEN 5
WHEN 'Most Senior'
THEN 6
ELSE 7
END cat
FROM (SELECT reg_no, gender, CATEGORY
FROM ehrv_patientlist_today
WHERE appoint_date BETWEEN NVL (:p_dt1, appoint_date)
AND NVL (:p_dt2, appoint_date))
GROUP BY gender, CATEGORY
ORDER BY cat;
----use case in where condition
WHERE patinfo.pathology =
CASE
WHEN NVL (p_pathology, 'N') = 'N'
AND NVL (p_imaging, 'N') = 'N'
AND NVL (p_due, 'N') = 'N'
AND NVL (p_overdue, 'N') = 'N'
AND NVL (p_ot, 'N') = 'N'
AND NVL (p_cannula, 'N') = 'N'
THEN NVL (p_pathology, patinfo.pathology)
ELSE p_pathology
END
OR patinfo.imaging =
CASE
WHEN NVL (p_pathology, 'N') = 'N'
AND NVL (p_imaging, 'N') = 'N'
AND NVL (p_due, 'N') = 'N'
AND NVL (p_overdue, 'N') = 'N'
AND NVL (p_ot, 'N') = 'N'
AND NVL (p_cannula, 'N') = 'N'
THEN NVL (p_imaging, patinfo.imaging)
ELSE p_imaging
END
OR patinfo.due =
CASE
WHEN NVL (p_pathology, 'N') = 'N'
AND NVL (p_imaging, 'N') = 'N'
AND NVL (p_due, 'N') = 'N'
AND NVL (p_overdue, 'N') = 'N'
AND NVL (p_ot, 'N') = 'N'
AND NVL (p_cannula, 'N') = 'N'
THEN NVL (p_due, patinfo.due)
ELSE p_due
END
OR patinfo.overdue =
CASE
WHEN NVL (p_pathology, 'N') = 'N'
AND NVL (p_imaging, 'N') = 'N'
AND NVL (p_due, 'N') = 'N'
AND NVL (p_overdue, 'N') = 'N'
AND NVL (p_ot, 'N') = 'N'
AND NVL (p_cannula, 'N') = 'N'
THEN NVL (p_overdue, patinfo.overdue)
ELSE p_overdue
END
OR patinfo.cann =
CASE
WHEN NVL (p_pathology, 'N') = 'N'
AND NVL (p_imaging, 'N') = 'N'
AND NVL (p_due, 'N') = 'N'
AND NVL (p_overdue, 'N') = 'N'
AND NVL (p_ot, 'N') = 'N'
AND NVL (p_cannula, 'N') = 'N'
THEN NVL (p_cannula, patinfo.cann)
ELSE p_cannula
END
OR patinfo.pot =
CASE
WHEN NVL (p_pathology, 'N') = 'N'
AND NVL (p_imaging, 'N') = 'N'
AND NVL (p_due, 'N') = 'N'
AND NVL (p_overdue, 'N') = 'N'
AND NVL (p_ot, 'N') = 'N'
AND NVL (p_cannula, 'N') = 'N'
THEN NVL (p_ot, patinfo.pot)
ELSE p_ot
END
AND patinfo.death = NVL (p_death, patinfo.death);
-----use >any means greate than smaller number
>all means greater than largest number
multicolumn subquery example
select * from emp where (sal,dept) in
(select max(sal),dept_no from emp group by dept)