prosource

저장 프로시저의 조건부 간격

probook 2023. 9. 5. 20:38
반응형

저장 프로시저의 조건부 간격

저장 프로시저의 매개 변수를 기준으로 이 SQL 문의 간격을 변경하고 싶습니다.1일, 8시간, 1시간의 세 가지 다른 간격을 사용하고 싶습니다.

CREATE DEFINER= 'dbshizzle' PROCEDURE `getData`(in sD text(17), in sT text(8))
BEGIN
select stime, sval
from tblNumber
where sDix = 'allright'
and timestamp >= now() - interval 1 day
order by timestamp;
END

정수 매개 변수가 있는 IF 문을 사용해야 합니까, 아니면 텍스트 매개 변수를 사용해야 합니까?

매개 변수를 조정하고 시간으로 값을 전달하는 것은 어떻습니까?

CREATE DEFINER = 'dbshizzle' PROCEDURE `getData`(
    in in_sD text(17),  -- should change to varchar
    in in_sT text(8),   -- should change to varchar
    in in_hours int
)
BEGIN
    select stime, sval
    from tblNumber
    where sDix = 'allright'
    and timestamp >= now() - interval in_hours hour
    order by timestamp;
END;

언급URL : https://stackoverflow.com/questions/42534390/conditional-interval-in-stored-procedure

반응형