Home » SQL & PL/SQL » SQL & PL/SQL » Can clarify pls
Can clarify pls [message #192901] Thu, 14 September 2006 03:11 Go to next message
irajasekharhexa
Messages: 6
Registered: June 2005
Location: Bangalore
Junior Member

CREATE OR REPLACE VIEW VW_Load_Hist_Prior_Load
AS
(
SELECT
CASE WHEN Load_Hist_Load_Month = '01'
THEN '12'
ELSE TO_CHAR((TO_NUMBER(Load_Hist_Load_Month) - 1),'00')
END AS Load_Hist_Load_Month
)

In the above code can any body explain what is the statement THEN '12'
will perform exactly.
Re: Can clarify pls [message #192904 is a reply to message #192901] Thu, 14 September 2006 03:21 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Documentation is a wonderful thing.

CASE lets you use an IF...THEN...ELSE... structure in your SQL

In your example, it is saying that when the value of Load_Hist_Load_Month = '01', return the value '12', otherwise return the value TO_CHAR((TO_NUMBER(Load_Hist_Load_Month) - 1),'00').

This could alse be rewritten as
DECODE(load_hist_load_month,'01','12',TO_CHAR((TO_NUMBER(Load_Hist_Load_Month) - 1),'00'))


Re: Can clarify pls [message #192905 is a reply to message #192901] Thu, 14 September 2006 03:23 Go to previous messageGo to next message
skooman
Messages: 912
Registered: March 2005
Location: Netherlands
Senior Member
It will return the characters 1 and 2.

In more detail, this statement says:
if Load_Hist_Load_Month equals 1, then return '12', else return Load_Hist_Load_Month minus 1.

(with some formatting around it)

Regards,
Sabine
Re: Can clarify pls [message #193132 is a reply to message #192901] Fri, 15 September 2006 00:24 Go to previous message
irajasekharhexa
Messages: 6
Registered: June 2005
Location: Bangalore
Junior Member

thanks for your inputs
Previous Topic: TOUGH QUERY
Next Topic: CLOB wrong character
Goto Forum:
  


Current Time: Thu Dec 08 14:07:52 CST 2016

Total time taken to generate the page: 0.11329 seconds