Hi All,
I am new to both this blog and technology. I was able to
see a response for one of the questions on triggers as
below.
I would like to know why are we using
" if rtrim(to_char(sysdate,'day'))=rtrim('sunday') then"
instead, can't we use
" if sysdate = 'sunday' then".
I can understand the use of "rtrim", but dont know y v r
using to_char. I have seen this in many cases but did not
get a convincible explaination.
Please help me with this and do excuse if this question
sounds silly.
Thanks in advance......
create or replace trigger trg_sun
before insert on <table name>
begin
if rtrim(to_char(sysdate,'day'))=rtrim('sunday') then
raise_application_error(-20345,'no transaction in sunday');
end if;
end trg_sun;
Answer Posted / eshwer
Hi,
see the below example you can easily understand that why we are using trim.
select decode(TRIM(to_char(SYSDATE,'Day')),'Monday','3','1') from dual
1. select decode(to_char(SYSDATE,'Day'),'Monday','3','1') from dual
Ans : 1 – error because eroju Monday ne kabatti query 3 return cheyali kani 1 return chesthundi. Karanam spaces so we need to use trim function.enduko kinda points chudu
2. Run this query and check the output select to_char(SYSDATE,'Day') from dual
3. select length(to_char(SYSDATE,'Day')) from dual –- ee query run chei output 9 vasthundi. But Monday actual length is 6.
run these queries
Is This Answer Correct ? | 4 Yes | 0 No |
Post New Answer View All Answers
What is rtm stands for?
How do you create an update query?
How are functions and procedures called in PL/SQL?
how to implement one-to-one, one-to-many and many-to-many relationships while designing tables? : Sql dba
what are the differences between binary and varbinary? : Sql dba
What is the purpose of the sql select top clause?
How does one use sql*loader to load images, sound clips and documents? : aql loader
Explain isolation levels. : Transact sql
Can we use ddl statements in stored procedure sql server?
how to use like conditions? : Sql dba
What will you get by the cursor attribute sql%found?
Is join an inner join?
What types of commands can be executed in sql*plus?
How does sql*loader handles newline characters in a record? : aql loader
how can we take a backup of a mysql table and how can we restore it. ? : Sql dba