Function in param, start_date & number , return sums next working day
Hi Friends,
I need a funtion which can take in parameters as start_date and number , sum them as new date and return new_start_date as workind day.
Suppose '15-SEP-2009' + 6 should return 23-SEP-2009 as new date.
Basically the sum of date and number should return next working day (excluding saturday,sunday).
e.g '15-SEP-2009' + 6 =21-SEP-2009 , but it includes saturday and sunday , so it should return 23-SEP-2009.
Thanks
Niren
Hi, Niren,
The first respondent gave a better function for testing for work days (Monday through Friday). If there's a bug with Saturdays, I'm sure that can fixed. Also,that function depends on your NLS settings. If that's an issue for you, that can be fixed, too. The idea that there are 5 work days in any 7 consecutive days will cut down the execution time considerable.
A function like I suggested would be useful if you had to consider holidays as well as weekends.
Here's an untested example:
CREATE OR REPLACE FUNCTION work_days_away
( in_start_date DATE
, in_day_cnt NUMBER
RETURN DATE
DETERMINISTIC
IS
IF in_start_date - TRUNC (in_start_date, 'IW') >= 5
OR is_holiday (in_start_date)
THEN
RETURN work_days_away ( in_start_date + 1
, in_day_cnt
ELSIF in_day_cnt >= 1
THEN
RETURN work_days_away ( in_start_date + 1
, in_day_cnt - 1
ELSE
RETURN in_start_date;
END IF;
END work_days_away;This use the date format 'IW', which does not depend on NLS settings, rather than 'D', which does.
Similar Messages
-
FM for Holiday & Next Working day
HI All,
Please suggest any single FM, which can give the current day is Holiday or not. If, Yes, the what is the next working day for a Facorty calender ID.
Both validation should be happend in a single FM.
Thanks & Regards,
Prabhakar.
Moderator message: FAQ, please search for previous discussions of this topic.
Edited by: Thomas Zloch on Apr 18, 2011 6:13 PMhi ,
Pls check this FM
CALL FUNCTION 'BKK_CHECK_HOLIDAY'
EXPORTING
i_date = wf_cntdt
i_calendar1 = 'B1'
IMPORTING
e_x_no_workingday = wf_holi.
*get actual working days upto report date.
it_act_work_days-dat_from = w_date-low.
it_act_work_days-dat_to = w_date-high.
APPEND it_act_work_days.
*calculate actual working days.
CALL FUNCTION 'WFCS_FCAL_WDAYS_GET_S'
EXPORTING
pi_time_interval = it_act_work_days
pi_fcalid = 'B1'
IMPORTING
pe_wdays = wf_actdays.
regards
Deepak.
Edited by: Deepak Dhamat on Apr 18, 2011 12:31 PM -
Calculate next working day in future
Hi,
I hope somebody of you could help me here. I have the requirement to find the next working day 2 days after the visit. I need to join two tables which have an N to N relation.
This is the first source table tbl_cust with customer and visiting day:
customer_id Name visit_day company_id
1 Tobias 27.08.2011 100
2 Hans 30.08.2011 100
3 Lars 27.08.2011 200
4 Dave 29.08.2011 200The second table tbl_comp_days includes the days where the different companies work:
company_id company_day working_day (yes/no)
100 27.08.2011 no
100 28.08.2011 no
100 29.08.2011 yes
100 30.08.2011 yes
100 31.08.2011 yes
100 01.09.2011 yes
200 27.08.2011 yes
200 28.08.2011 yes
200 29.08.2011 no
200 30.08.2011 yes
200 31.08.2011 yes
200 01.09.2011 yesNow I want to calculate the second next work of the company joined with the customer visit_day
Means: tbl_cust.visit_day + 2
when tbl_comp_days.working_day is yes
if tbl_cust.visit_day is not a working day find the next possible working day + 2 working days
Output example:
customer_id Name visit_day visit_day_plus_2
1 Tobias 27.08.2011 31.08.2011
2 Hans 30.08.2011 01.09.2011
3 Lars 27.08.2011 30.08.2011
4 Dave 29.08.2011 01.09.2011Thanks for your help
TobiasHi, Tobias,
Here's one way:
WITH got_r_num AS
SELECT c.customer_id, c.name, c.visit_day, d.company_day AS visit_day_plus_2
, ROW_NUMBER () OVER ( PARTITION BY c.customer_id
ORDER BY d.company_day
) AS r_num
FROM tbl_cust c
JOIN tbl_comp_days d ON c.company_id = d.company_id
AND c.visit_day < d.company_day
AND c.visit_day >= d.company_day + 10 -- See note
WHERE d.working_day = 'yes'
SELECT customer_id, name, visit_day, visit_day_plus_2
FROM got_r_num
WHERE r_num = 2
;If you'd post CREATE TABLE and INSERT statements for the sample data, then I could test it.
The last join condition ( c.visit_day >= d.company_day + 10) isn't strictly necessary. Depending on the size of the company_day table, it may make execution faster, by limiting the join to days soon after visit_day, rather than any time after visit_day. As I wrote it, it assumes that there will always be at least 2 working days in any period of 10 consecutive days. (In my company, there are always at least 2 working days in a period of 5 consecutive days.) You cam change the "magic number" 10 to anything else, or you can omit that condition altogether.
Edited by: Frank Kulash on Aug 23, 2011 10:49 AM
Added note. -
Netdue date alteration with next working day
Hi,
I have one report for Accounts Receivables .
In this when net due date falls on holiday, i need to shift this "net due date" to a next working day.
I have one FM "DATE_CONVERT_TO_FACTORYDATE" which i can use for the purpose.
As a input to this FM we need to give Factory calendar ID which is an attribute to Infoobject 0PLANT.
Unfortunately i do not have 0PLANT in my datamodel. But i do have 0COMP_CODE in my datamodel.
As i do not have any link between Factory calendar ID and 0COMP_CODE i am searching for an appropriate solution so that i could use this FM to shift net due date to Next working if the net due date is an holiday.
Any Ideas?Simran
I am not sure if we can get a direct link from 0plant to 0comp_code, but you can enhance the master data of the 0company code to add the factory caledar and load them manually into 0plant.
Let me know if this helps..
Regards,
Avinash -
Billing date of 2nd/4th saturday getting pushed to next working day.
whenever my client trying to create bill of service order, bills on 2nd/4th saturday, the billing date is getting pushed to next working day. I checked their calender, they have maintained 2nd/4th saturday as holiday in holiday calender. However the validity is only till 2009. But the bills are getting still getting pushed. Am not too keen on using validation, please help.
Hi,
Are they creating invoices thru back ground ( using batch job ) ? in this case in the holiday calendar 2n'd and 4'th saturday is holiday, so the system is proposing new work day. you have to check all the three calendars once again let me know.
Thanks,
Chandu. -
URGENT: Add Non-working day value to the next working day
Hello expertz!
I have a requirement were i need to shift the values of the non-working days to the next working day. The report allready works, showing only the values for the working days, but for example if i have the amount of 100 on 06.12.2009 (saturday) i want that this value is added to the amount of 09.12.2009, which is the next working day.
Does anybody knows a solution to do this? Is this possible in BEx?
Please advise if you think this is not possible.
Thanks for the help.
NunoHi Anil,
I really appreciate your suggestion, but i'm still not getting the point. How to store the value of the non-working day in a variable and then add it where? Can you please clarify?
Thank you very much for your help.
Nuno -
Schedule line confirmation on next working day
Hi,
For a sales org, (IE93) in a sales order if we request delivery on 25.12.2009 (Xmas day), APO availability check is performed and it is confirming on the next/prior working day.
But in case of other sales org(GB93) it is confirming on the same day(on Xmas itself, which is a holiday)..
We want the same control for GB93 also.. Any idea?
Regards,
MayilHi,
Check the Factory calender Assignmene for these two COMPANY CODES, PLANT, in OVR3
I believe the Factory calender is different for these two Organisational Units.
Check the Factory calender settings in OVR3 transaction code
Please revert back if you need further details
thanks,
santosh -
LENGTH function for a large number returns 40 not the number of digits
In SQL*Plus:
SQL> select length(12345678901234567890123456789012345678901234567890)lngth
2 from dual;
LNGTH
40
SQL> select length('12345678901234567890123456789012345678901234567890')lngth
2 from dual;
LNGTH
50
It seems that the implicit conversion from number to char in the first query causes an unexpected result. From the documentation of the LENGTH function at http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions181.htm#i79330:
"If you omit fmt, then n is converted to a VARCHAR2 value exactly long enough to hold its significant digits."
Perhaps Oracle considers that only 40 digits are significant (?)Additional reason.
There is implicit data conversion as like to_char(number).
SQL> set numwidth 50
SQL> select 12345678901234567890123456789012345678901234567890 num from dual;
NUM
12345678901234567890123456789012345678900000000000
SQL> select length(12345678901234567890123456789012345678901234567890) numlen from dual;
NUMLEN
40
SQL> select to_char(12345678901234567890123456789012345678901234567890) numlen from dual;
NUMLEN
1.2345678901234567890123456789012346E+49
SQL> select length(to_char(12345678901234567890123456789012345678901234567890)) numlen from dual;
NUMLEN
40
SQL> select to_char(12345678901234567890123456789012345678901234567890,
2 '09000000000000000000000000000000000000000000000000')
3 num from dual;
NUM
12345678901234567890123456789012345678900000000000
SQL> select length(to_char(12345678901234567890123456789012345678901234567890,
2 '09000000000000000000000000000000000000000000000000'))
3 num from dual;
NUM
51
SQL> select to_char(12345678901234567890123456789012345678901234567890,
2 'fm09000000000000000000000000000000000000000000000000')
3 num from dual;
NUM
12345678901234567890123456789012345678900000000000
SQL> select length(to_char(12345678901234567890123456789012345678901234567890,
2 'fm09000000000000000000000000000000000000000000000000'))
3 num from dual;
NUM
50 -
Code or function to generate next working date for a given date
hi,
First lets see the table struncture and table data.
CREATE TABLE LT_CA_HOLIDAYS
HOLIDAY_DATE DATE NOT NULL,
IS_BANK_HOLIDAY CHAR(1 BYTE) NOT NULL,
DISPLAY_NAME VARCHAR2(35 BYTE) NOT NULL
Insert into LT_CA_HOLIDAYS
(HOLIDAY_DATE, IS_BANK_HOLIDAY, DISPLAY_NAME)
Values
(TO_DATE('12/25/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 'Christmas Day');
Insert into LT_CA_HOLIDAYS
(HOLIDAY_DATE, IS_BANK_HOLIDAY, DISPLAY_NAME)
Values
(TO_DATE('01/01/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 'New Years Day');
Insert into LT_CA_HOLIDAYS
(HOLIDAY_DATE, IS_BANK_HOLIDAY, DISPLAY_NAME)
Values
(TO_DATE('01/17/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 'Martin Luther King Jr');
Insert into LT_CA_HOLIDAYS
(HOLIDAY_DATE, IS_BANK_HOLIDAY, DISPLAY_NAME)
Values
(TO_DATE('02/21/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 'Washington s B-Day');
Insert into LT_CA_HOLIDAYS
(HOLIDAY_DATE, IS_BANK_HOLIDAY, DISPLAY_NAME)
Values
(TO_DATE('05/30/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 'Memorial');
Insert into LT_CA_HOLIDAYS
(HOLIDAY_DATE, IS_BANK_HOLIDAY, DISPLAY_NAME)
Values
(TO_DATE('07/04/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 'Independence Day');
Insert into LT_CA_HOLIDAYS
(HOLIDAY_DATE, IS_BANK_HOLIDAY, DISPLAY_NAME)
Values
(TO_DATE('09/05/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 'Labor Day');
Insert into LT_CA_HOLIDAYS
(HOLIDAY_DATE, IS_BANK_HOLIDAY, DISPLAY_NAME)
Values
(TO_DATE('10/10/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 'Columbus Day');
Insert into LT_CA_HOLIDAYS
(HOLIDAY_DATE, IS_BANK_HOLIDAY, DISPLAY_NAME)
Values
(TO_DATE('11/11/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 'Verterans Day');
Insert into LT_CA_HOLIDAYS
(HOLIDAY_DATE, IS_BANK_HOLIDAY, DISPLAY_NAME)
Values
(TO_DATE('11/24/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 'Thanksgiving Day');
Insert into LT_CA_HOLIDAYS
(HOLIDAY_DATE, IS_BANK_HOLIDAY, DISPLAY_NAME)
Values
(TO_DATE('12/25/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 'Christmas Day');
Insert into LT_CA_HOLIDAYS
(HOLIDAY_DATE, IS_BANK_HOLIDAY, DISPLAY_NAME)
Values
(TO_DATE('12/26/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 'Bank Observed Christmas');
Insert into LT_CA_HOLIDAYS
(HOLIDAY_DATE, IS_BANK_HOLIDAY, DISPLAY_NAME)
Values
(TO_DATE('01/01/2012 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 'New Years Day');
Insert into LT_CA_HOLIDAYS
(HOLIDAY_DATE, IS_BANK_HOLIDAY, DISPLAY_NAME)
Values
(TO_DATE('01/02/2012 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 'Bank Observed New Years Day');
COMMIT;.
The requirement goes something like this:
Weekend days SATURDAY and SUNDAY ARE CONSIDERED holidays.
The list of holidays are in LT_CA_HOLIDAYS.
We will be given a date as p_processdate.we need to check if p_processdate is a holiday or a working day,
if p_processdate is a holiday then we need to generate the next working day .
If p_processdate is a working day we need to test whether p_processdate +1 is a working day, IF p_processdate+1 is a holiday then
we need to generate the next working day near to p_processdate + 1.
RegardsDECLARE
day_param date:=TO_DATE('01/16/2011','MM/DD/YYYY');--- SET your input date
n_yes number;
BEGIN
LOOP
day_param:=day_param+1;
select count(*) into n_yes from LT_CA_HOLIDAYS WHERE TO_CHAR(HOLIDAY_DATE,'MM/DD/YYYY')=TO_CHAR(day_param ,'MM/DD/YYYY') ANd IS_BANK_HOLIDAY='Y' ;
IF(to_char (day_param,'DY') NOT IN ('SAT','SUN')) AND n_yes=0 THEN
EXIT;
END IF;
END LOOP;
DBMS_output.put_line('output'||day_param);
END;OUTPUT
output18-JAN-11
Edited by: Leonard on Aug 26, 2011 5:13 AM -
How to get the next working date?
Hi,
I need to extract data between the 2nd of the month, and second working date of the following month.
Here is the code I have to check if the date is a weekend, and check if it is in the Holidays table (for UK Holidays):
(This code is to check against Easter 2014, so Good Friday was on the 18th of April, Easter Monday was on the 21st, and the date I want returned is Tuesday the 22nd but I cannot get it working correctly).
declare @LatestDate datetime
set @LatestDate = DATEADD(m,-9,getdate()) -- cast('01/11/2014' as datetime) --dateadd(m,1,datediff(d,0,'01/11/2014'))
set @LatestDate = DATEADD(d,13,@LatestDate)
print @LatestDate
if datepart(dw,@LatestDate) in (1,7)
Begin
while datepart(dw,@LatestDate) in (1,7)
OR
exists (select * from Hermes_Rep..Holidays where Holiday =right(CONVERT(CHAR(10), @LatestDate, 101),4) + '-' + left(CONVERT(CHAR(15), @LatestDate, 101),2) + '-' + SUBSTRING(CONVERT(CHAR(15), @LatestDate, 101),4,2))
Begin
set @LatestDate=DATEADD(d,1,@LatestDate)
End
End
What I need is for my code to always return the 2nd working day of any month, taking into account weekends, and Holidays in the Holidays table.
The Holidays table has dates in the format '2014-04-18 00:00:00' (for Good Friday 2014)Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI-ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI-ISO Standard SQL. And you need to read and download the PDF for:
https:--www.simple-talk.com-books-sql-books-119-sql-code-smells-
>>Here is the code I have to check if the date is a weekend, and check if it is in the Holidays table (for UK Holidays): <<
Do you know what a calendar table is?
>> (This code is to check against Easter 2014, so Good Friday was on the 18th of April, Easter Monday was on the 21st, and the date I want returned is Tuesday the 22nd but I cannot get it working correctly). <<
Catholic or Orthodox Easter? This is one of many reasons we do not use computations in SQL. What you did is the wrong approach done with bad programming. For example, we do not use the old Sybase getdate() now. The only display format allowed in
ANSI/ISO Standard SQL, but you used a local dialect!
COBOL treats dates as strings like you did; SQL has a temporal data type.
>> What I need is for my code to always return the 2nd working day of any month, taking into account weekends, and Holidays in the Holidays table. <<
The idea of a Holiday table is bad; why are these dates totally different entities from other dates? Would you split Personnel on sex and have “Male_Personnel” and “Female_Personnel”?
The Julian business day is a good trick. Number the days from whenever your calendar starts and repeat a number for a weekend or company holiday.
CREATE TABLE Calendar
(cal_date DATE NOT NULL PRIMARY KEY,
julian_business_nbr INTEGER NOT NULL,
INSERT INTO Calendar
VALUES ('2007-04-05', 42),
('2007-04-06', 43), -- good Friday
('2007-04-07', 43),
('2007-04-08', 43), -- Easter Sunday
('2007-04-09', 44),
('2007-04-10', 45); --Tuesday
To compute the business days from Thursday of this week to next
Tuesdays:
SELECT (C2.julian_business_nbr - C1.julian_business_nbr)
FROM Calendar AS C1, Calendar AS C2
WHERE C1.cal_date = '2007-04-05',
AND C2.cal_date = '2007-04-10';
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
HI,
Can anyone help me with a function to find the next working date excluding holidays from a table 'holidays'
The input to the function would be a date and output as well.
ThanksHi,
Assuming work days are Monday through Friday, and all dts in the holiday table are at midnight:
FUNCTION next_work_day (in_dt IN DATE)
RETURN DATE
DETERMINISTIC
IS
-- next_work_day returns the frist working day (that is, anything except Saturday, Sunday or days
-- in the holiday table) after (not including) in_dt.
-- The value returned is always midnight (00:00:00).
junk PLS_INTEGER;
return_dt DATE := TRUNC (in_dt);
BEGIN
LOOP
return_dt := return_dt +
CASE return_dt - TRUNC (return_dt, IW')
WHEN 4 THEN 3 -- Friday -> Monday
WHEN 5 THEN 2 -- Saturday -> Monday
ELSE 1
END;
SELECT 1
INTO junk
FROM holidays
WHERE dt = return_dt;
-- If the SELECT statement above didn't raise an error, this is a holiday,
-- so repeat the loop and try the next day
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
RETURN return_dt;
END next_work_day;This solution does not depend on NLS settings.
(Untested.)
Edited by: Frank Kulash on Jun 4, 2009 3:58 PM -
Function for calculating working days
Dear Oracle
Is there any function to calculate no of working days if I pass From date & To date?.
Thanks
Christy.This would work for normal weekdays, but what about bank holidays?
They change from country to country, so you need to create a package yourself.
We got one that looks like the following:
create or replace
package body zentr_date_functions as
function eastern (p_year in number) return date is
-- Get easter sunday (working from 1900 to 2099)
-- CKL 02.09.1998 nach c't 18/98
l_a pls_integer;
l_b pls_integer;
l_c pls_integer;
l_d pls_integer;
l_e pls_integer;
l_p pls_integer;
function make_date(p_d in pls_integer, p_m in pls_integer, p_y in pls_integer) return date is
begin
return to_date(to_char(p_d, '00')||to_char(p_m, '00')||to_char(p_y, '0000'), 'DDMMYYYY');
end;
begin
if p_year not between 1900 and 2099 then
return null;
end if;
l_a := mod(p_year, 19);
l_b := mod(p_year, 4);
l_c := mod(p_year, 7);
l_d := mod(19 * l_a + 24, 30);
l_e := mod(2 * l_b + 4 * l_c + 6 * l_d + 5, 7);
l_p := 22 + l_d + l_e;
if l_p > 31 then
if l_p = 56 and l_d = 28 and l_a > 10 then
return make_date(18, 4, p_year);
elsif l_p = 57 then
return make_date(19, 4, p_year);
else
return make_date(l_p - 31, 4, p_year);
end if;
else
return make_date(l_p, 3, p_year);
end if;
end eastern;
function is_workday (p_date in date) return number as
-- is this a working day?
l_eastern date;
begin
if to_char(p_date, 'DY', 'NLS_DATE_LANGUAGE = AMERICAN') in ('SAT', 'SUN') then
return 0;
end if;
if to_char(p_date, 'DDMM') in ('0101', '0105', '0310', '2412', '2512', '2612', '3112') then
-- fixed date bank holidays in lower saxony, Germany
return 0;
end if;
if to_number(to_char(p_date, 'MM')) not between 3 and 6 then
return 1;
end if;
if to_number(to_char(p_date, 'YYYY')) not between 1900 and 2099 then
-- calculation not possible
return null;
end if;
l_eastern := eastern (to_number(to_char(p_date, 'YYYY')));
if trunc(p_date) in (l_eastern - 2, l_eastern + 1, l_eastern + 39, l_eastern + 50) then
-- good friday, easter monday, ascension day, pentecost monday
return 0;
end if;
return 1;
end is_workday;
function workdays_between (p_date1 in date, p_date2 in date) return number as
-- count number of working days between p_date1 and p_date2 (incl. both)
l_count pls_integer := 0;
begin
for i in 0 .. p_date2 - p_date1 loop
l_count := l_count + is_workday(p_date1 + i);
end loop;
return l_count;
end workdays_between;
end;
/ -
CALCULATE THE NEXT WORKING DATE ACCORDING TO THE CALENDAR
Hello,
Could somebody tell me the name of any function module or abap class to determine the next working day according to calendar. I need add (let say) 30 days to the date but only working days (I dont take into acount sunday, easter etc.)
Thanks in Advance
Adamtry function BKK_ADD_WORKINGDAY
or WDKAL_DATE_ADD_FKDAYS
Cheers
Thomas -
How can i find out the next 2 working days.
Hi Experts,
Based on a given date, i would like to find out the next 2 working days.
Help me out.
Regards,
Mansi.Hi,
Use this FM WRF_PSCD_GET_NEXT_WORKDAY
first get the first working day and pass that day again to get the next working day
and also pass the calender id for the same
Import parameters Value
I Import parameters Value
I_DATE 09/15/2007
I_CALENDAR1 US
I_CALENDAR2
Export parameters Value
E_WORKDAY 09/17/2007
Regards
Shiva -
How to pipeline a function with a dynamic number of columns?
Hi everyone,
I'm trying to figure out how to write a piplined function that generates a dynamic SQL statement from its inputs, executes the query, and returns the results of the query in the pipeline. The number and names of the columns in the dynamic query is unknown number until the function is invoked.
I suspect that DBMS_SQL is involved, but can't quite figure out how to construct a row using it that I can use PIPE ROW on. I also can't figure out what data type the function should return (ANYDATASET?)
pseudo-PLSQL follows:
create function myfunction ( param1 varchar2)
return anydataset pipelined
as
query_string := <... do stuff with param1 ...>
< -- >
open a cursor for query_string
determine the number of columns
read a row
PIPE ROW it
<--->
Can what I'm trying to do be done?
Thanks,
KeithThe following works on 10R2
create or replace type NColPipe as object
l_parm varchar2(10), -- The parameter given to the table function
rows_requested number, -- The parameter given to the table function
ret_type anytype, -- The return type of the table function
rows_returned number, -- The number of rows currently returned by the table function
static function ODCITableDescribe( rtype out anytype, p_parm in varchar2, p_rows_req in number := 2 )
return number,
static function ODCITablePrepare( sctx out NColPipe, ti in sys.ODCITabFuncInfo, p_parm in varchar2, p_rows_req in number := 2 )
return number,
static function ODCITableStart( sctx in out NColPipe, p_parm in varchar2, p_rows_req in number := 2 )
return number,
member function ODCITableFetch( self in out NColPipe, nrows in number, outset out anydataset )
return number,
member function ODCITableClose( self in NColPipe )
return number,
static function show( p_parm in varchar2, p_rows_req in number := 2 )
return anydataset pipelined using NColPipe
create or replace type body NColPipe as
static function ODCITableDescribe( rtype out anytype, p_parm in varchar2, p_rows_req in number := 2 )
return number
is
atyp anytype;
begin
anytype.begincreate( dbms_types.typecode_object, atyp );
if p_parm = 'one'
then
atyp.addattr( 'one'
, dbms_types.typecode_varchar2
, null
, null
, 10
, null
, null
elsif p_parm = 'two'
then
atyp.addattr( 'one'
, dbms_types.typecode_varchar2
, null
, null
, 10
, null
, null
atyp.addattr( 'two'
, dbms_types.typecode_varchar2
, null
, null
, 10
, null
, null
else
atyp.addattr( p_parm || '1'
, dbms_types.typecode_varchar2
, null
, null
, 10
, null
, null
atyp.addattr( p_parm || '2'
, dbms_types.typecode_varchar2
, null
, null
, 10
, null
, null
atyp.addattr( p_parm || '3'
, dbms_types.typecode_number
, 10
, 0
, null
, null
, null
end if;
atyp.endcreate;
anytype.begincreate( dbms_types.typecode_table, rtype );
rtype.SetInfo( null, null, null, null, null, atyp, dbms_types.typecode_object, 0 );
rtype.endcreate();
return odciconst.success;
exception
when others then
return odciconst.error;
end;
static function ODCITablePrepare( sctx out NColPipe, ti in sys.ODCITabFuncInfo, p_parm in varchar2, p_rows_req in number := 2 )
return number
is
elem_typ sys.anytype;
prec pls_integer;
scale pls_integer;
len pls_integer;
csid pls_integer;
csfrm pls_integer;
tc pls_integer;
aname varchar2(30);
begin
tc := ti.RetType.GetAttrElemInfo( 1, prec, scale, len, csid, csfrm, elem_typ, aname );
sctx := NColPipe( p_parm, p_rows_req, elem_typ, 0 );
return odciconst.success;
end;
static function ODCITableStart( sctx in out NColPipe, p_parm in varchar2, p_rows_req in number := 2 )
return number
is
begin
return odciconst.success;
end;
member function ODCITableFetch( self in out NColPipe, nrows in number, outset out anydataset )
return number
is
begin
anydataset.begincreate( dbms_types.typecode_object, self.ret_type, outset );
for i in self.rows_returned + 1 .. self.rows_requested
loop
outset.addinstance;
outset.piecewise();
if self.l_parm = 'one'
then
outset.setvarchar2( to_char( i ) );
elsif self.l_parm = 'two'
then
outset.setvarchar2( to_char( i ) );
outset.setvarchar2( 'row: ' || to_char( i ) );
else
outset.setvarchar2( 'row: ' || to_char( i ) );
outset.setvarchar2( 'row: ' || to_char( i ) );
outset.setnumber( i );
end if;
self.rows_returned := self.rows_returned + 1;
end loop;
outset.endcreate;
return odciconst.success;
end;
member function ODCITableClose( self in NColPipe )
return number
is
begin
return odciconst.success;
end;
end;
/And to use it
SQL> select * from table( NColPipe.show( 'test', 3 ) );
test1 test2 test3
row: 1 row: 1 1
row: 2 row: 2 2
row: 3 row: 3 3
SQL> select * from table( NColPipe.show( 'two', 5 ) );
one two
1 row: 1
2 row: 2
3 row: 3
4 row: 4
5 row: 5
SQL> select * from table( NColPipe.show( 'one' ) );
one
1
2
SQL> Anton
Maybe you are looking for
-
Unable to load persistence provider
hi, i'm using spring context to reimplement some java methods in SOA suite. I have a deplyed and runnable Spring MVC project, which use hibernate to connect between database and project POJO classes. i use this spring project's java methods which are
-
My wife and I both have iPhones and iPads. Can we both have access to the same iTunes Match library or do we have to have separate subscriptions? Our devices are synced to the same computer and we currently download titles from the same library. We
-
Pantone swatch palette not persistent
Hello all, I'm posting this in the hopes that someone else searching for the problem might find my post to lead them to the solution. I recently installed Illus CS4 on my new mac (yay!) I'm slowly working through all the new features - and new glitch
-
Iphone 6 massasge app crash when trying to select a photo
I can send massage just fine. I am able to copy and paste photos or video no problems. But if i try to use the cam button in the massage app it pulls up the screen and no preview of last photos show up and the massage app will crash. any idea? try to
-
Project status graph in OBIEE?
Hi Gurus, I am wondering if it is possible to create a Project status graph (e.g. Microsoft project graph) in OBIEE? My requirement is to create similar graph with OBIEE. Please let me if it is possible, if yes then how. http://www.workengine.com/App