stories2
stories2

Reputation: 486

Oracle DB not declared 'RIGHT'

i expected get ls_fr, ls_to which is update using if statement.

But the query exception message says Not declared RIGHT. I thought RIGHT is built-in function. How can i solve this or declare RIGHT function?

declare
ls_today VARCHAR2(15);
ls_time VARCHAR2(15);
ls_bef_day VARCHAR2(15);
ls_next_day VARCHAR2(15);
ls_fr VARCHAR2(15);
ls_to VARCHAR2(15);
begin
ls_today := '20181105';
ls_time := '20181105175612';
ls_bef_day := '20181104';
ls_next_day := '20181106';
If RIGHT(ls_time, 6) >= '000000' and RIGHT(ls_time, 6) <= '055959' Then 
ls_fr := ls_bef_day;
ls_to := ls_today;
Else
ls_fr := ls_today;
ls_to := ls_next_day;
End If;
select ls_fr, ls_to INTO ls_fr, ls_to FROM DUAL;
end;

Upvotes: 0

Views: 84

Answers (1)

Radagast81
Radagast81

Reputation: 3006

The simpliest would be tho use SUBSTR instead of RIGHT with negative position (as there is no RIGHT in oracle) :

If SUBSTR(ls_time, -6) >= '000000' and SUBSTR(ls_time, -6) <= '055959' Then

Negative position with SUBSTR means the position is given according to the end of the string. And if you omit the length parameter as above the substring is taken till the end of the string. Therefore SUBSTR(..., -pos) is equivalent to RIGHT(..., pos).

Upvotes: 5

Related Questions