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



Hi All, I am new to both this blog and technology. I was able to see a response for one of the ..

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

Hi All, I am new to both this blog and technology. I was able to see a response for one of the ..

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

Post New Answer

More SQL PLSQL Interview Questions

What is sql not null constraint?

0 Answers  


In table a 1lakh data is present,in table b 20 thousand data is present, to get unique data from table a and b which join to be considered. whether right outer join or left inner join. 

2 Answers   GE,


Is hadoop a nosql?

0 Answers  


how to eliminate null values in a column i.e table vlaues 1 2 3 NULL 3 4 1 5 NULL i want output like this 1 2 3 3 4 1 5 i dnt want to use nvl is null and i dnt want replace the NULL value with any value i.e nvl(col,o);

11 Answers   Satyam,


What are the two different parts of the pl/sql packages?

0 Answers  






What is native sql query?

0 Answers  


Can a foreign key be a duplicate?

0 Answers  


Explain alias in sql?

0 Answers  


We have a CURSOR then we need BULK COLLECT?

1 Answers  


Table1: Col1 col2 1 2 10 3 4 89 5 6 Table:2 Col1 col2 3 2 9 5 4 7 6 87 With the help of table1 and table2 write a query to simulate the fallowing results. Output1: Col1 col2 1 2 2 3 3 4 4 5 5 6 Output2: Col1 col2 2 3 10 4 5 89 6 7 1.Write query for single row to multiple row using sql statements. Eg:a,b,c,d,e,f Change to A B C D E F 2. Write query for multiple row to single row using sql statements. Eg2 A B C D E F Change to Eg:a,b,c,d,e,f Table1: Col1 col2 8 5 2 9 4 2 5 1.Write a query to select all the rows from a table1,if the value of A is null then corresponding B’s value should be printed in A’s value.if the value of A is null in that table then corresponding B’s value should be printed as 30. 2. write a query to find the sum of A and B .display the max among both. 3.write a query to find total number of rows from table 1. Note: if any column value is null in a row then that row should be considered as 2 rows. 4.write a query to display all the records of table1 except A containg 2 as well B containg 5. 5.rewrite the fallowing without using join and group by. Select b.title,max(bc.returneddate –bc.checkoutdate)” mostdaysout” From bookshelf_checkout bc, Book shelf B Where bc.title(+)=b.title Group by b.title. 6.rewrite fallowing query Select id_category from category_master X where exists (select 1 from sub_category Y where X.id_category=Y.id_category) Customer: Name phone1 phone2 phone3 bitwise A 23456 67890 12345 --- B 67459 89760 37689 --- Don’t_call Col1 67890 37689 1.q) update the customer table of bitwise with 1 or 0. Exists in don’t_call table menas show -1 Other wise -0. Output. Name bitwise A 010 B 010

0 Answers   Protech,


In testing where do we use sql language and how it helps in testing?

2 Answers  


What operators deal with null?

0 Answers  


Categories