GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Tech FAQs  >  PL/SQL
Go To First  |  Previous Question  |  Next Question 
 PL/SQL  |  Question 113 of 166    Print  
function which returns previous business date of given input date
How can I write a function which returns previous business date of given input date
1. skip holidays when you find previous day
2. skip Sunday and saturday's when you find previous day
US holidays are defined in HOLIDAYS table

date, holiday_desc

1-Jan-2007 New Year




  
Total Answers and Comments: 2 Last Update: October 10, 2007     Asked by: Rajesh 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
October 10, 2007 15:03:00   #1  
ravgopal Member Since: October 2007   Contribution: 7    

RE: function which returns previous business date of g...

Did you find the solution? if not then here it is..try this

a) Create the sample table holiday :
create table holiday (h_dt date h_desc varchar2(100));

b) let us feed some records;

Insert into holiday values ('1-jan-2007' 'New Year');
Insert into holiday values ('8-oct-2007' 'Columbus day');

c) Querying holiday table you will find :

H_DT H_DESC
--------- -------------
01-JAN-07 New Year

08-OCT-07 Columbus day

d) PL/SQL code to get the date
------------------------------------------------------------------
Declare


in_dt date : '&Dt'; --input date goes here
v_dt date;
v_chk number;

begin

<<start_here>>

select count(1) into v_chk from holiday where h_dt in_dt;

if v_chk > 0 then
in_dt : in_dt-1;
goto start_here; --Loop to check consecutive holidays
end if;

select decode(to_char(in_dt 'DY') 'SUN' in_dt-2 'SAT' in_dt-1 in_dt)
into v_dt from dual;

dbms_output.put_line(v_dt);

end;
/

------------------------------------------------------------------

e) Output :

SQL> @lastbusiness
Enter value for dt: 8-Oct-2007
Result : 05-OCT-07

SQL> @lastbusiness
Enter value for dt: 2-Jan-2007
Result : 02-JAN-07

SQL> @lastbusiness
Enter value for dt: 1-Jan-2007
Result : 29-DEC-06


 
Is this answer useful? Yes | No
October 10, 2007 15:06:02   #2  
ravgopal Member Since: October 2007   Contribution: 7    

RE: function which returns previous business date of g...
if you need to get the previous business date just change the in_dt variable in declaration to

input_dt date : '&Dt';
in_dt date : input_dt - 1;

 
Is this answer useful? Yes | No

 Related Questions

Latest Answer : no difference ...
Read Answers (9) | Asked by : Suyog

How do i write a function that returnsmore than 1 records from a tablefor example in sql server there is a solution as create function f1() return table asselect * from emphow do i do the same in oracle. plz help

I want to convert source Date format "CCYYMMD" to "CCYY-MM-DD23.59.59.999999" in to the target for example source date is 19980224it should be in target 1998-02-24.23.59.59.999999
Read Answers (1) | Asked by : Sachin

Hi 1.What is difference between procedure and function?1. procedure may or may not return values whereas function must return value2. we can call the function in the sql statements whereas we can't call the procedureExcept these two, is there any difference between these two.2. What is pl/sql table and what is use of it. In which case, we can use it3. What is ref cursor, what is the use of it.4.how the function will return multiple values. Pls give me with examples

Latest Answer : We can call a function from anonymous block as a part of sql statement written in that block.eg: create or replace function fn_emp(v_empno in number)return varchar2 isbeginselect ename into v_ename from empwhere empno=v_empno;return v_ename;end;this function ...
Read Answers (2) | Asked by : Anuruddha SINGH

Latest Answer : Hi.....yes we can create a table by using a procedure  or a function but it must be done by Dynamic SQL. Dynamic SQL is a programming technique that enables you to build SQL statements dynamically at runtime. lets say you want to create an EMP table ...
Read Answers (1) | Asked by : sarada

Hi,1. Iam looking for sample program for ref cursor. ref cursor can be associated with many select statements and we can use the ref cursor to return the multiple value from the procedure or function. 
Latest Answer : Hi,Let me answer your second questin first. Why ref cursor instead of %ROWTYPE.%ROWTYPE is used for fetches record/row of a single table.OR in case of columns of different tables then you have to create a RECORD and then used %ROWTYPE.But ...

Latest Answer : HI ALL,try this..,create or replace procedure ddl_proc(tabname in varchar2)asv_cursor INTEGER;ddl_exe INTEGER;beginv_cursor:=Dbms_sql.open_cursor;Dbms_sql.Parse(v_cursor,' Create Table '||tabname||' (col1 number(2),col2 varchar2(5)) ',Dbms_sql.native);ddl_exe:=Dbms_sql.Execute(v_cursor);dbms_sql.close_cursor(v_cursor);end ...
Read Answers (2) | Asked by : madhug56

Latest Answer : you can use SYSDATE oracle.lv_today := sysdate;or select sysdate into lv_today from dual;both the statements assign sysdate to lv_today ...

Latest Answer : To created flat files, or read flat files in a procedure or function, the built-ins in the UTL_FILE package can be used. ...
Read Answers (1) | Asked by : hiavijit


 Sponsored Links

 
Related Articles

Service Oriented Java Business Integration Review

Service Oriented Java Business Integration Review Introduction If you ve read through the texts which give you an introduction to SOA or Web Services you will often find them to be quite frustrating and the reason for this is because they spend too much time referencing business processes which are
 

Business Intelligence Key Performance Indicators

Business Intelligence Key Performance Indicators What are Key Performance Indicators Key Performance Indicators are also known as Key Success Indicators they help an organization to better define and measure their progress toward professional goals Once an organization has clearly identified its nee
 

How to Best Use Business Intelligence to Your Advantage

How to Best Use Business Intelligence to Your Advantage It is no big secret that today s businesses rely heavily on data and the information it delivers about their companies Whether it is for the purpose of customer acquisition improving operational performance or understanding competitors all of t
 

Business Intelligence in Information Technology

Business Intelligence in Information Technology IT stands for Information Technology Information Technology is a system designed to gather process or distribute information IT can be inspected in terms of the following three groupings; the data gathering the data processing and the data distribut
 

Business Intelligence Integration

Business Intelligence Integration How to Integrate Business Intelligence within Your Organization Before you Integrate Business Intelligence into your Organization Business Intelligence has developed into strategic process over the years of its extraordinary growth even so it still needs to be incor
 

Business Intelligence Tips

Business Intelligence Tips Understand Your Organization first Truly understanding your company and how it works is perhaps one of the most important Business Intelligence tips anyone can offer This includes understanding the business itself the processes involved the data and how that data is used b
 

Business Performance Management

Business Performance Management What is Business Performance Management Business Performance Management is most commonly described as a set of processes that help companies or organizations optimize their business performance It is specifically designed to organize automate and analyze business meth
 

Business Intelligence Applications

Business Intelligence Applications In this article we are going to take some time to discuss the various applications that are normally provided with Business Intelligence Systems mosgoogle Tools Used to Analyze Performance Projects and Internal Operations First we will look over the tools most comm
 

Business Intelligence Data Analysis

Business Intelligence Data Analysis Data Analysis Data Analysis is a complete and thorough review of all of the information being collected and warehoused by an organization This is most commonly done by organizing and examining the data collected with the help of charts graphs and tables mosgoogle
 

Business Intelligence History

Business Intelligence History When did Business Intelligence first come into play Before the Information Age of the late 20th century companies had to collect their information from non automated sources Those were the days that businesses lacked any type of sophisticated computing resources to enab
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape