Create function with a cursor in it
I need help to create a function called f_Getfeedesc. I want to use a cursor for Loop. The function will return fees description for any folder.
If a folder has more than one fee description, it will concatenate the fees description.
The select statement I have here returns the following fees description:
CO Residential 3+ Units No Entry Penalty Fee
C of O Initial Fee
CO Residential 3+ Units Initial Fee
However when the function is done if you run it using the folderrsn 99999 the result should look like this:
CO Residential 3+ Units No Entry Penalty Fee / C of O Initial Fee / CO Residential 3+ Units Initial Fee
If the folderrsn has only one fee description the result should just return that one fee description. e.g CO Residential 3+ Units No Entry Penalty Fee
I am using the following tables:
folder table with FOLDERRSN......... NOT NULL NUMBER(10,0) column.
accountbillfee table with FEECODE..........NOT NULL NUMBER(10,0) column.
validaccountfee table with FEECODE........NOT NULL NUMBER(10,0) and FEEDESC............NOT NULL VARCHAR2(80) columns.
SELECT DISTINCT vaf.feedesc
FROM folder f, accountbillfee abf, validaccountfee vaf
WHERE f.folderrsn = abf.folderrsn
AND vaf.feecode = abf.feecode
--And f.folderrsn = argfolderrsn
AND f.folderrsn = 99999 --for a specific folderrsn
Edited by: user4653174 on Sep 12, 2008 1:31 PM
Hi,
What you're trying to do is called "string aggregation".
There's an excellent page on AskTom with several general solutions.
I recommend the first one, STRAGG.
Once you have STRAGG installed, you can get the output you want as simply as this:
SELECT feecode
, STRAGG (feedesc)
FROM validaccountfee
GROUP BY feecode;Edited by: Frank Kulash on Sep 13, 2008 2:56 AM
Similar Messages
-
2 functions with one cursor or.. 1 function with 2 cursors?
Hi friends,
I hope you help me to decide is this easy question:
Actually I have 2 functions. Both are the same more or less: Both get data from USERS table. (In the users table there are several columns, I'm interested in "code" and "description")
Function1 have a cursor which obtain data and orders by code,
Function2 have a cursor which obtain data and orders by description.
That's the only difference.
I want to "optimize" the code so I was thinking on creating only a function.
To do the same in one only function I thinked on passing a parameter i.e.: p_ordertype to know which would be the order ("C" for code or "D" for description)
In that function I would have two cursors and I would ask for the parameter to execute one "FOR...." or the other.
The question: Would it be really effective? I think that if I have 2 cursors in a function... I would cosume more memory than if I would only have one cursor.. (because I think data selected from cursors is parsed to memory when you invoke the function, before the 1st instruction after the BEGIN is executed, isn't it?)
Would it be better 2 functions with one cursor each one or... one function with 2 cursors?
Thanks in advance for your opinions.
Jose.Hi again Todd,
there's a problem with you solution :
Imagine you have the following users:
usercode - userdescr
1 - ALAN
2 - RICHARD
3 - DANI
12 - CHARLIE
20 - BARRY
If we pass a 'C' as p_ordertype (to obtain the list like above, ordered by usercode) , the result would be:
1 - ALAN
12 - CHARLIE
2 - RICHARD
20 - BARRY
3 - DANI
Do you understand what i'm trying to explain?... I hope that... I tried with
ORDER BY DECODE(p_ordertype,'C',usercode,'D',TO_NUMBER(userdescr));
but it doesn't works...
More ideas? -
How can I Create function with an out Parameter
how all
how can I Create function with an out Parameter
I try to create it it sucess but how can I CALL it , it give me error
please I want A simple example
thanks3rd post on same question by same user :
Re: how can I Create function with an out Parameter
how can I Create function with an out Parameter -
Create view With Ref cursor data
Hi friends,
I want to create view as follows.
Example:
Create or replace v_name
select job,sal, <funcation>
from emp;
Note:- Function not having out parameter.
Function returning ref cursor values datatype.
Requirement:-
I want to create view even function returing ref cursor datatype.
Please advise how to create view.
Regards,
Kishoreuser7284612 wrote:
Hi friends,
I want to create view as follows.
Example:
Create or replace v_name
select job,sal, <funcation>
from emp;
Note:- Function not having out parameter.
Function returning ref cursor values datatype.
Requirement:-
I want to create view even function returing ref cursor datatype.
Please advise how to create view.You perhaps are misunderstanding what a ref cursor is. It does not contain data like a table, so cannot be treated as one.
Take a read of this:
PL/SQL 101 : Understanding Ref Cursors -
Function with dynamics cursor.
Hi everybody,
I'm trying to write a function having as argument as SQL query(or a part of it). This SQL query should generate a cusror within the function. All the way would have the generated cusror always the same structure.
CREATE OR REPLACE FUNCTION Calcul_avg(Name_Table VARCHAR) RETURN NUMBER
IS
TYPE Funct_Cursor_Type IS REF CURSOR RETURN Defined_Table%ROWTYPE;
Funct_Cursor Funct_Cursor_Type;
OPEN Funct_Cursor
FOR SELECT ID, NAME FROM Name_Table ;
Return Calcul_avg;
With this function,
I'm getting the error:
PLS-00455: cursor 'FUNCT_CURSOR' cannot be used in dynamic SQL OPEN statement
Thanks for your help!!
AlexThe error message measn what it says. We cannot use a strongly typed cursor with dynamic SQL. This is because the typing is enforced at compile time, whereas the cursor is only assembled at runtime. So we must use weakly typed cursors in this situation.
If you have 9i then you can use an instance of the pre-defined SYS_REFCURSOR. Else
TYPE Funct_Cursor_Type IS REF CURSOR;Cheers, APC -
Error while creating function with record type as return type
Hi i tried the following code to get the nth highest sal using record type and function.
CREATE OR REPLACE PACKAGE pack_rec_cur AS
TYPE rec_type IS RECORD (
name EMP.ename%TYPE,
sal EMP.sal%TYPE);
END;The above package is created
CREATE OR REPLACE
FUNCTION fun_rec_cur(n INT) RETURN pack_rec_cur.rec_type AS
rec pack_rec_cur.rec_type;
CURSOR cur_rec IS
SELECT ename,sal
FROM emp
WHERE sal is not null
ORDER BY DESC;
BEGIN
OPEN cur_rec;
FOR i IN 1..n LOOP
FETCH cur_rec into rec;
EXIT WHEN cur_rec%NOTFOUND;
END LOOP;
CLOSE cur_rec;
RETURN rec;
END; The above function is giving errors
LINE/COL ERROR
4/7 PL/SQL: SQL Statement ignored
7/16 PL/SQL: ORA-00936: missing expression
SQL> Could you please correct me where i'm doing mistake
Thanks.You are missing the column name in order by clauase. Is it ename desc?
CREATE OR REPLACE
FUNCTION fun_rec_cur(n INT) RETURN pack_rec_cur.rec_type AS
rec pack_rec_cur.rec_type;
CURSOR cur_rec IS
SELECT ename,sal
FROM emp
WHERE sal is not null
ORDER BY ENAME DESC; ---added ename
BEGIN
OPEN cur_rec;
FOR i IN 1..n LOOP
FETCH cur_rec into rec;
EXIT WHEN cur_rec%NOTFOUND;
END LOOP;
CLOSE cur_rec;
RETURN rec;
END;
-OUTPUT
SQL> SET SERVEROUT ON
SQL>
SQL> DECLARE
2 rec pack_rec_cur.rec_type;
3 BEGIN
4 rec := fun_rec_cur (6); --you get the 6th record in order of ename desc
5 DBMS_OUTPUT.put_line ('ename::' || rec.NAME || ' sal ::' || rec.sal);
6 END;
7 /
ename::MARTIN sal ::1250
PL/SQL procedure successfully completed.
SQL> -
Running a function with a cursor output
Hi All,
It sounds like this should be easy, but I can't get it to work! I'm trying to run or debug a function in JDev. The function simply calls a Java SP that returns a cursor. This all works fine and it runs in SPL Plus with no problems. The problem is that when I try to run it from within JDev I get presented with the PL/SQL block window, and nothing I do will let me view the contents of the cursor returned - mostly I just get errors and the code doesn't run at all.
The default code it generates is:
DECLARE
v_Return NULL;
BEGIN
v_Return := ALISI.POC.POCCALLSP();
-- Modify the code to output the variable
-- DBMS_OUTPUT.PUT_LINE('v_Return = ' || v_Return);
END;
I think this should be modified to say:
DECLARE
v_Return Types.ref_cursor;
BEGIN
v_Return := ALISI.POC.POCCALLSP();
-- Modify the code to output the variable
DBMS_OUTPUT.PUT_LINE('v_Return = ' || v_Return);
END;
But the DBMS_OUTPUT.PUT_LINE is expecting a string, not a cursor, and nothing I've tried (I've tried so many things I can't begin to list them - or remember them) will work.
Can anyone point out the error in my ways? Is it anything to do with the fact that I'm using a function and not a procedure? As you can probably tell I'm new to all this!
Many thanks,
John.With "simple" variables, we are able to display the output using DBMS_OUTPUT. For composite variables (PL/SQL tables, PL/SQL records, cursors, etc), there's no good way for us to directly display the result. DBMS_OUTPUT.PUT_LINE can only take a "String", or something that can be converted to it, and unlike Java, not everything implements a toString method. We would expect in such cases that the user modify the code as desired to output the data.
That being said, you are actually encountering a bug here. With most datatypes that we can't display directly, we generally get enough information that we generate code that at least compiles and runs. I've logged a bug (3124777) to track this.
(For what it's worth, I've tried this in 9.0.5, only to discover that the functionality has regressed a bit to be even less correct than in 9.0.3.)
After the bug is fixed the output should look like this:
DECLARE
v_Return Types.ref_cursor; -- assuming this is the name of your ref cursor type
BEGIN
v_Return := ALISI.POC.POCCALLSP();
-- Modify the code to output the variable
-- DBMS_OUTPUT.PUT_LINE('v_Return = ' || v_Return);
END;The user would then need to modify the part that displays the output. In this example, it might go something like this:
DECLARE
v_Return Types.ref_cursor; -- assuming this is the name of your ref cursor type
v_Record v_Return%ROWTYPE;
BEGIN
v_Return := ALISI.POC.POCCALLSP();
-- Modify the code to output the variable
LOOP
FETCH v_Return INTO v_Record;
EXIT WHEN v_Return%NOTFOUND;
DBMS_OUTPUT.PUT_LINE (v_Record.employee_id || CHR(9) || v_Record.last_name
|| CHR(9) || v_Record.salary); -- replace with your field names
END LOOP;
END;I hope this helps!
-- Brian -
How can I create banners with 100% height?
I want the homepage to load with 100% height and there buttons that anchor to sections further down the website that I also want to be 100% height when scrolled to.
3rd post on same question by same user :
Re: how can I Create function with an out Parameter
how can I Create function with an out Parameter -
How to create a procedure function with a return value of ref cursor?
Can anybody provide a sample about how to create a procedure function with a return value of REF CURSOR?
I heard if I can create a function to return a ref cursor, I can use VB to read its recordset.
Thanks a lot.http://osi.oracle.com/~tkyte/ResultSets/index.html
-
How to create a function with ref_cursor as parameter in OWB 10.1
Hi,
Can any one help me how to create a function with ref_cursor as parameter in OWB 10.1.?
Its urgent. Please help me.
Thanks,
SivHi David,
Thanks for your reply.
Before going for this function, I need to create a package in transformation node in owb module.
My package is as follows,
Create or replace package 123
type xxx is RECORD ( parameters);
type yyy is RECORD (parameters);
type aaa is table of yyy;
type bbb is REF CURSOR return xxx;
type ccc is record (parameters);
type ddd is ref cursor return eee;
END;
How can I create the above kind of package manually in OWB 10.1 (Should not to import the package)
Please help me its urgent.
Thanks,
Siv -
Creating Report using EPM Functions with Dynamic Filters
Hi All,
I am new to BPC, In BPC 7.5 i seen like we can generate EPM report using EVDRE function very quickly and easy too. Is the same feature is existing in BPC 10.0 ? if no how can we create EPM reports using EPM Functions with Dynamic Filters on the Members of the dimension like in BPC 7.5.
And i searched in SDN, there is no suitable blogs or documents which are related to generation of Reports using EPM Functions. All are described just in simple syntax way. It is not going to be understand for the beginners.
Would you please specify in detail step by step.
Thanks in Advance.
Siva NagarajuSiva,
These functions are not used to create reports per se but rather assist in building reports. For ex, you want to make use of certain property to derive any of the dimension members in one of your axes, you will use EPMMemberProperty. Similary, if you want to override members in any axis, you will make use of EPMDimensionOverride.
Also, EvDRE is not replacement of EPM functions. Rather, you simply create reports using report editor (drag and drop) and then make use of EPM functions to build your report. Forget EvDRE for now.
You can protect your report to not allow users to have that Edit Report enabled for them.
As Vadim rightly pointed out, start building some reports and then ask specific questions.
Hope it clears your doubts. -
BETWEEN FUNCTION WITH IN A DECODE FUNTION IN A CURSOR
The following below is my query..I have to get the hours,min and seconds from a 'yyyy-mm-dd-24hh.mi.ss' value and check if the time is between 12 am to 6 am , then write it with one value else write an another value..I am trying to use 'BETWEEN' function in decode function but i am getting error.....Can we use BETWEEN function with in decode function or is there any other way
set serveroutput on
declare
cursor cur_dte is select lst_upd_date from EMPLOYESS ;
begin
for i in cur_dte loop
DECODE (substr(trim(i.lst_upd_date),12)) ,between '00.00.00.0000' and '06.00.00.00.0000' ,101,102);
dbms_output.put_line(i.lst_upd_date);
end loop;
endFirst of all. If you are in PL/SQL then CASE is just a more colmplex expression then IF THEN ELSE. I usually prefere If then else, but for some rare cases.
The other issue is that you convert a datetime value into a string. This is wrong. it opens up all possible kinds of cenversion bugs. Stay with date or timestamp as long as possible.
The solution depends a little upon the datatype of your lst_upd_date column.
Here is a pl/sql solution assuming it is DATE.
The TRUNC function can be used to reduce a datetime to a day or to an hour.
declare
cursor cur_dte is select lst_upd_date from employees ;
begin
for i in cur_dte loop
if trunc(i.lst_upd_date,'HH') between trunc(i.lst_upd_date) and trunc(i.lst_upd_date)+6/24 then
dbms_output.put_line(to_char(i.lst_upd_date,'DD-MON-YYYY HH24:MI:SS'));
end if;
end loop;
end;
/But a pure SQL solution is much better.
Here is how you implement it using CASE in SQL.
example using pure sql
select e.*,
case when trunc(e.lst_upd_date,'HH')
between trunc(e.lst_upd_date) and trunc(e.lst_upd_date)+6/24
then 101
else 102
end as "early_morning_check"
from employees e;And if it is a timestamp column then you could use the EXTRACT function.
select e.*,
case when to_number(extract(hour from e.lst_upd_date))
between 0 and 6
then 101
else 102
end as "early_morning_check"
from employees e;You might want to consider if date values like 06:45:00 should be included or not. -
Parallel piplelined function not parallelizing with ref cursor
RDBMS 11.2.0.3
I have a function with the following signature
function to_file (
p_source in sys_refcursor
, p_file_name in varchar2
, p_directory in varchar2 default 'DD_DUMP'
return dd_dump_ntt
pipelined
parallel_enable ( partition p_source by any )
authid current_user;The function works in parallel when I use a cursor expression like this
begin
for rec in ( select *
from table(dd_dump.to_file( cursor(select /*+ parallel(i 4) */ c1||chr(9)||c2 from mytable i), 'f.out' ))
loop
dbms_output.put_line(rec.file_name || chr(9) || rec.num_records );
end loop;
end;
f.out_162 276234
f.out_213 280399
f.out_230 286834
f.out_70 289549But when I use a refcursor, it does not run in parallel
declare
rc sys_refcursor;
begin
open rc for 'select /*+ parallel(i 4) */ c1||chr(9)||c2 from mytable i';
for rec in ( select *
from table(dd_dump.to_file( rc, 'f.out' ))
loop
dbms_output.put_line(rec.file_name || chr(9) || rec.num_records );
end loop;
end;
f.out_914 1133016Is this an expected behavior or am I doing something wrong? How can I use the function when the client returns the SQL statement as a character string
Edited by: Sanjeev Chauhan on Mar 9, 2012 11:54 AMSanjeev Chauhan wrote:
I am not performing any DML in the pipelined function. If you read the note carefuly it shows parallel_enable works only when you use:
table(table_function(<font color=red>CURSOR</font>(select...)))and not when you use
table(table_function(<font color=red>ref-cursor-name</font>))SY. -
Function Module to create Delivery with JIT Calls
Hi SAP Guru's,
We are working on SAP 4.6C version.
I am looking for a function module to create delivery with JIT Calls.
We are currently using the SAP standard function module "SHP_VL10_DELIVERY_CREATE" to create Delivery with JIT Calls. Each JIT Calls has apx 60-80 materials in it and each material refers to a unique Scheduling Agreement. This function module is taking very long time in production server to create delivery, it does not take much time in dev or quality server.
We have JITV setting profile (For Sold To Party and Partner Description Profile) set as RELACE (to summarize the line items in JIT Call).
Is there another function module that we can use to create delivery with JIT Calls?
Thanks in Advance,
AmitHi there,
There is no such function module.
Regards
Sanju -
On the AGO Function need to Create TODATE function with Diff levels - MTD,Q
Hi All,
My Basic Requirement is to Create Time Series Function on AAA ie ( Month To Date , Quarter To Date and Year To Date )
The Logic for the AAA = XXX / Previous 3 Months Revenue.
we know that we can use the AGO Function to create Previous 3 months Revenue with Month is Level . But the issue is .... i cant use AGO function since i need to perform Year to Date, QTD and MTD upon 'AAA' this OBIEE doesn't permit to use nested time series functions upon varying levels .
So How can i Resolve the issue ie creation of TODATE function on the AGO Function with Diff levels
Thanks,
Swapna Shi,
for your requirement create three repository variables like
for previous 3 months create repository variable like
select to_char(sysdate,'yyyymm') -3 from dual;
for month to date first calculate first day of the month
select To_Char(Add_Months(Last_Day(Sysdate),-1) + 1,'MM/DD/YYYY') from dual;
after put a filter in answers date between first date of the present month and current date
create the same thing for year to date
calculate first date in the year like following query
select To_Char(Trunc(Sysdate,'YEAR'),'MM/DD/YYYY') from dual;
after that apply filter date b/w first date in the year and current date
i hope it works for your scenario
Regards
Naresh
Edited by: Naresh Meda on Nov 10, 2008 2:08 AM
Edited by: Naresh Meda on Nov 10, 2008 2:12 AM
Maybe you are looking for
-
How to calculate percentge based on totals of two columns?
All, I am trying to create a percentage in the totals of a worksheet. PCT = (AMT01 / AMT02) * 100 GTPCT = (AMT01 / ( SUM(AMT01) OVER (PARTITION BY COL01)) AMT02 will be hidden PCT will not be totaled, since the total is not correct. GTPCT will be for
-
Ftp Adapter Inbound operation not working
Hi All, I'm running on SOA 11g on a Oracle Linux machine. FtpAdapter is configured and works well for outbound operations (my test composite can put a file on a ftp location). For inbound operation something is not working, my composite, a simple ftp
-
UDDI - inquiry/publish API
Hi all, i want to use the UDDI server from XI. With the UDDI client from XI i can publish my web services. But now i want to configure the UDDI Client in transaction suddireg in order to get access to UDDI from ERP (transaction wsadmin). But i have a
-
Error while importing schemas using datapump
Hi, I am trying to import schema from qc to development. after importing i got the following error attached below: Processing object type SCHEMA_EXPORT/TABLE/GRANT/WITH_GRANT_OPTION/OBJECT_GRANT Processing object type SCHEMA_EXPORT/TABLE/GRANT/CROSS_
-
Flash froze and crashed computer
I was playing a flash-based game when the game completely locked up my computer, and the only possible solution was to do a hard reboot (pressing and holding the power key). I waited and then restarted, but the screen had vertical and horizontal pixe