

/* -------- 嵟怴扴摉幰(嬈柋擔晅儅僗僞) -------- */

CREATE OR REPLACE VIEW V_TANTO AS
select
 A.摼堄愭喊霓 摼堄愭喊霓
,case
 when (A.塩嬈扴摉奐巒擔晅2>=A.塩嬈扴摉奐巒擔晅1 AND B.攧忋巇擖摉擔擔晅>=A.塩嬈扴摉奐巒擔晅2 OR A.塩嬈扴摉奐巒擔晅2<A.塩嬈扴摉奐巒擔晅1 AND B.攧忋巇擖摉擔擔晅<A.塩嬈扴摉奐巒擔晅1) AND A.塩嬈扴摉喊霓2<>'' then A.塩嬈扴摉喊霓2
 else A.塩嬈扴摉喊霓1
end 塩嬈扴摉喊霓
from
 MM_TOK A
,FE_TODAY B
where
 B.俲俤倄 = '嬈柋擔晅儅僗僞'
;

/* -------- 嵟怴扴摉幰(僔僗僥儉擔晅偐傜) -------- */

CREATE OR REPLACE VIEW V_TANTONOW AS
select
 A.摼堄愭喊霓 摼堄愭喊霓
,decode(A.塩嬈扴摉喊霓2,' ',A.塩嬈扴摉喊霓1,
	decode(sign(A.塩嬈扴摉奐巒擔晅2-A.塩嬈扴摉奐巒擔晅1),-1,
		decode(sign(to_nchar(sysdate,'YYYYMMDD')-A.塩嬈扴摉奐巒擔晅1),-1,A.塩嬈扴摉喊霓2,A.塩嬈扴摉喊霓1), 
		decode(sign(to_nchar(sysdate,'YYYYMMDD')-A.塩嬈扴摉奐巒擔晅2),-1,A.塩嬈扴摉喊霓1,A.塩嬈扴摉喊霓2))) 塩嬈扴摉喊霓
from
 MM_TOK A
;

