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;
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / eshwer
Run this query and check the result you can easyly understand y we used trim function..
select length(to_char(sysdate,'day')), length(rtrim(to_char(sysdate,'day'))) from dual;
| Is This Answer Correct ? | 0 Yes | 0 No |
What is difference between sql function and stored procedure?
What has stored procedures in sql?
How delete a row in sql?
what is self join and why is it required? : Sql dba
there are .......different types of serializability
write a query filter the null value data following source? name age john 30 smith null null 24 sharp 35 i want output name age john 30 sharp 35
Is it possible to link two groups inside a cross products after the cross products group has been created?
Which clause of an UPDATE statement allows you to affect only certain rows of a table? 1. The WHERE clause 2. The SET clause 3. The ROWS AFFECTED clause 4. The ORDER BY clause
how to check myisam tables for errors? : Sql dba
Is full outer join same as cross join?
What are stored procedures used for?
While inserting/updating million of records into a database table, how do I came to know how many records has been inserted or updated successfully so far?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)