κ·Όν μν©μ νμΈν μ μλ μ½λμ μμλ€
-- κ·Όν μ‘°ν > 9μ κ·Όν κΈ°λ‘ μ΄λ > κ²°μν λ μ§λ ν¬ν¨ + 곡ν΄μΌ ν¬ν¨ > λΉ μ§ λ μ§ λ©κΎΈκΈ°
-- 1. ANSI-SQL
-- 2. PL/SQL
-- 3. Java
set serveroutput on;
declare
vdate date;
vstate varchar2(30);
vcnt number;
begin
vdate := to_date('2023-09-01', 'yyyy-mm-dd');
for i in 1..30 loop
dbms_output.put_line(vdate);
select count(*) into vcnt from tblDate where to_char(regdate, 'yyyy-mm-dd') = to_char(vdate, 'yyyy-mm-dd');
if vcnt > 0 then
select state into vstate from tblDate where to_char(regdate, 'yyyy-mm-dd') = to_char(vdate, 'yyyy-mm-dd');
dbms_output.put_line(vstate);
end if;
vdate := vdate + 1;
end loop;
end;
-- ANSI-SQL
-- κ³μΈ΅ν 쿼리 μ¬μ©
select * from tblComputer;
select
lpad(' ', level * 3) || name
from tblComputer
start with seq = 1
connect by pseq = prior seq;
-- κ³μΈ΅ν 쿼리 = forλ¬Έ ν¨κ³Ό > μΌλ ¨ λ²νΈ μμ±
select * from dual;
-- 곡μκ°μ 쿼리
select level -- levelμ΄ 5λ³΄λ€ μμΌλ©΄ λΆλͺ¨μμμ λ¬Άμ΄λΌ
from dual
connect by level <= 5;
select sysdate + level
from dual
connect by level <= 5;
-- *** κΈ°μ΅!! > date μλ£νμΌλ‘ μνλ κΈ°κ°μ λ°μ΄ν° μμ±νλ λ°©λ²
create or replace view vwDate
as
select
to_date('2023-09-01', 'yyyy-mm-dd') + level - 1 as regdate
from dual
connect by level <= (to_date('2023-09-30', 'yyyy-mm-dd') - to_date('2023-09-01', 'yyyy-mm-dd') + 1);
select * from vwDate;
-- 맀κ°λ³μ -> λ·°λ νλ½μ
select * from vwDate; -- 9μ νλ¬ λ μ§
select * from tblDate; -- 9μ κ·Όν κΈ°λ‘
-- λΉ μ§ λ μ§ μμ΄μ μλ¨
select
*
from vwDate v
inner join tblDate t
on v.regdate = t.regdate;
select
*
from vwDate v
left outer join tblDate t
on v.regdate = t.regdate
order by v.regdate;
-- ν΄μΌ μ²λ¦¬(ν , μΌ)
select
v.regdate,
case
when to_char(v.regdate, 'd') in ('1') then 'μΌμμΌ'
when to_char(v.regdate, 'd') in ('7') then 'ν μμΌ'
else t.state
end as state
from vwDate v
left outer join tblDate t
on v.regdate = t.regdate
order by v.regdate;
-- 곡ν΄μΌ μ²λ¦¬ (μΆκ° ν
μ΄λΈ νμ)
create table tblHoliday(
seq number primary key,
regdate date not null,
name varchar2(30) not null
);
insert into tblHoliday values(1, '2023-09-28', 'μΆμ');
insert into tblHoliday values(2, '2023-09-29', 'μΆμ');
select * from tblHoliday;
-- νμΌ + ν΄μΌ μ²λ¦¬(ν , μΌ) + 곡ν΄μΌ + κ²°μ
select
v.regdate,
case
when to_char(v.regdate, 'd') in ('1') then 'μΌμμΌ'
when to_char(v.regdate, 'd') in ('7') then 'ν μμΌ'
when t.state is null and h.name is not null then h.name
when t.state is null and h.name is null then 'κ²°μ'
else t.state
end as state
from vwDate v
left outer join tblDate t
on v.regdate = t.regdate
left outer join tblHoliday h
on v.regdate = h.regdate
order by v.regdate;
κ°μ λΆλΆμ λλμ΄ DDLμ μμ±νμκ³ μ΄λ₯Ό κ²ν νμ¬ λ¬Έμλ‘ μμ±νμλ€. μνμ€ μμ± κ΅¬λ¬Έμ΄ λΉ μ Έμμ΄μ ν¨κ» μΆκ°νμ¬ μμ±νμλ€.
κ°λ erdλ₯Ό νΌν° μ²Έ νκΈ°λ²μΌλ‘ μμ±νλ€κ° ν μ΄λΈ μ¬μ΄μ κ΄κ³κ° 볡μ‘ν΄μ Έ IE νκΈ°λ²μΌλ‘ λ³κ²½νμ¬ λ€μ μμ±νμλ€.
DDLκ³Ό λλ―Έλ°μ΄ν°λ₯Ό μ΄μ©ν΄ λ¨Όμ μμ±λ DML ꡬ문λ€μ λ¬Έμννμλ€.