Plsql function to return period and yr values
Hi All,
I have a requirement to develop a function
which will accept any date and return the two values period, yr
as follows
if date is 1st oct 2011 then period should be 1 yr should be 2012
if date is 1st nov 2011 then period should be 2 yr should be 2012
if date is 1st dec 2011 then period should be 3 yr should be 2012
if date is 1st jan 2012 then period should be 4 yr should be 2012
if date is 1st feb 2012 then period should be 5 yr should be 2012
if date is 1st mar 2012 then period should be 6 yr should be 2012
if date is 1st apr 2012 then period should be 7 yr should be 2012
if date is 1st may 2012 then period should be 8 yr should be 2012
if date is 1st june 2012 then period should be 9 yr should be 2012
if date is 1st july 2012 then period should be 10 yr should be 2012
if date is 1st aug2012 then period should be 11 yr should be 2012
if date is 1st sept 2012 then period should be 12 yr should be 2012
if date is 1stoct 2012 then period should be 1 yr should be 2013
if date is 1st nov 2012 then period should be 2 yr should be 2013
if date is 1st dec 2012 then period should be 3 yr should be 2013
and so on
Please tell me how can i achive these through a plsql function
Thanks in anticipation.
Hi,
This forum is for questions using SQL*Developer, not for general PL/SQL questions.
It would be better to ask this question in the SQL and PL/SQL forum -
PL/SQL
Regards,
Mike
Similar Messages
-
Create a procedure to return period and year value
Hi All,
I have a requirement to develop a procedure
which will accept any date and return the two values period, yr
as follows
if date is 1st oct 2011 then period should be 1 yr should be 2012
if date is 1st nov 2011 then period should be 2 yr should be 2012
if date is 1st dec 2011 then period should be 3 yr should be 2012
if date is 1st jan 2012 then period should be 4 yr should be 2012
if date is 1st feb 2012 then period should be 5 yr should be 2012
if date is 1st mar 2012 then period should be 6 yr should be 2012
if date is 1st apr 2012 then period should be 7 yr should be 2012
if date is 1st may 2012 then period should be 8 yr should be 2012
if date is 1st june 2012 then period should be 9 yr should be 2012
if date is 1st july 2012 then period should be 10 yr should be 2012
if date is 1st aug2012 then period should be 11 yr should be 2012
if date is 1st sept 2012 then period should be 12 yr should be 2012
if date is 1stoct 2012 then period should be 1 yr should be 2013
if date is 1st nov 2012 then period should be 2 yr should be 2013
if date is 1st dec 2012 then period should be 3 yr should be 2013
and so on
Please tell me how can i achive these through a plsql function
Thanks in anticipation.CREATE OR REPLACE Function testdate
( INDATE IN DATE )
RETURN number
IS
PERIOD number;
YR NUMBER;
BEGIN
&INDATE
select
case
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='Oct'
then '1'AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy') FROM DUAL)
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='Nov'
then '2'AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy') FROM DUAL)
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='Dec'
then '3'AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy') FROM DUAL)
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='Jan'
then '4'AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy') FROM DUAL)
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='Feb'
then '5' AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy')from dual)
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='Mar'
then '6' AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy')from dual)
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='Apr'
then '7' AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy')from dual)
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='May'
then '8' AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy')from dual)
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='Jun'
then '9' AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy')from dual)
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='Jul'
then '10'AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy')from dual)
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='Aug'
then '11'AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy')from dual)
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='Sep'
then '12'AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy')from dual)
ELSE NULL
end
into PERIOD
FROM DUAL;
RETURN PERIOD;
RETURN YR;
end TESTDATE;
EXCEPTION
WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('NO OUTPUT');
END;
**Mark a Person Correct or helpful if his answer is as such**
Edited by: Anshul Sharma on Feb 15, 2012 8:46 PM
Edited by: Anshul Sharma on Feb 21, 2012 12:47 AM -
PLSQL function body returning an sql report returns ORA-01403 No Data Found
I am on APEX 3.1.2.00.02 and Oracle 10g.
I am developing a report with SQL Query (PL/SQL function body returning SQL query) type. But on running the report I am getting
report error:
ORA-01403: no data found
Region Source
declare
qry varchar2(32767);
begin
--Procedure call
my_pkg.get_query(qry);
htp.p(qry);
return /*select 1 from dual */ qry;
end;
Procedure
PROCEDURE get_query (V_QRY OUT VARCHAR2)
IS
qry varchar2(32767);
begin
qry := ' select name
, max(decode(to_char(service_date,''Mon-YY''), ''Jan-09'', value, null)) as "Jan-09"
, max(decode(to_char(service_date,''Mon-YY''), ''Jan-09'', value, null)) as "Feb-09"
from MY_TABLE
group by name ';
V_QRY := qry;
end;
The query will be enhanced later to add more months and year based on user parameters once I am successfull in running report on this.
I wish to use Query Specific Column names. I have seen this suggestion from Scott in a number of threads to use /*select 1 from dual */ with query but not working in my case.
Can someone please suggest what can I do to make it working?
Regards,
AmirFirstly, have you unit tested the procedure (namely, within the SQL Workshop, SQL*Plus, SQL Developer,etc, etc.) to see if it produces the right output in the first place?
If you have, and the query string generated is valid, try assigning the output to a page item (thus allowing you to view it in the session browser) or even pass the procedure output into the debug window (with the use of the wwv_flow.debug function). This might reveal some state or session change which is causing it not to return.You might find this easier to achieve if you change from a 'procedure and out parameter' combination to a 'function returning string' approach.
Alternatively, try re-creating the report in a new region - occasionally I've come across weird bugs with report regions which resolved themselves in this manner. -
Function to extract characteristics and its value from PI sheet
Hi experts,
I am working on a report to generate Avg. deckle for the month form the PI sheet. In the PI sheet the data that is displayed is basically the message characteristcs and its value.
Please tell me ne function that will give me the related data to be displayed.
Thanks in advance..reading the characteristics: CAVC_DB_READ_CFG_IN_CBASE.
reading the values according to the characteristics: CARD_CHARACTERISTIC_READ.
Note: the second FM is obsolete according to SAP. but it still works in opposition to the new ones. -
Converting SQL Report Region to PLSQL Function Body Returning SQL Query
All:
I want to convert my SQL Report Region to a PLSQL-generated SQL Report Region so that I can eliminate where clauses dynamically and speed up my app, and also so that I can provide additional sorting options.
<br><br>
My problem is that I have lots of embedded single quotes that already are coded as 3 single quotes in the SQL Report Region. I am not sure at all how to code them within the PLSQL.
<br><br>
As example, here is one column from my query:
<br><br>
select decode(nvl(g.date_sub_1,g.date_rec_1), null, decode(g.article, 0, 'E', 1, 'U'), '< a href="javascript:unElevate( ' ' ' || g.grid || ' ' ',' ' ' || g.natca || ' ' ')">' || decode(g.article, 0, 'E', 1, 'U') || '< /a>') "Reverse" from g_table g
<br><br>
(Note that I added spaces within the code so it would display properly in the browser.)
<br><br>
To clarify, that's a double quote before javascript, and then 3 single quotes before the first concatenation group, then 3 single quotes after the second concatenation group, then 3 single quotes before the third, 3 single quotes after the fourth followed by an end-paren followed by a double quote etc.
<br><br>
My question is, what do I do with these triple-single quotes within PLSQL? Probably a no-brainer for the experienced folks, but I am thinking like a mobius strip at this point.
<br><br>
Bill
Message was edited by:
[email protected]
Message was edited by:
[email protected]
Message was edited by:
[email protected]Scott,
I think that feature was made for my situation! I keep getting
Function returning SQL query: Query cannot be parsed within the Builder. If you believe your query is syntactically correct, check the generic columns checkbox below the region source to proceed without parsing.
(ORA-20001: Unable to bind :43 verify length of item is 30 bytes or less. Use v() syntax to reference items longer than 30 bytes. ORA-01006: bind variable does not exist)
I did chop the query up into little bits, i.e.
p_sql := p_sql || q'! ... !';
p_sql := p_sql || q'! ... !';
p_sql := p_sql || q'! ... !';
return p_sql;
But I'm not sure what I'm supposed to do here.
Thank you.
Bill -
How to Create a Procedure/Function to Return more than one value
How I can write a function/Procedure to which one value is passed and it will return nine values. How I can use these values
Syed,
I would use PL_SQL table versus a VARRAY for this purpose as you will have an advantage of joining PL_SQL table if you want to in your SQL statements in the procedure.
1. At the SQL prompt, create a type using,
create or replace type myTable as table of VARCHAR2(100);
2. Pass the table to your procedure as IN OUT parameter,
Create or replace procedure
myProc(pvar1 IN Number, passingArray IN OUT myTable) AS
Begin
--Fill the array with your logic
for i in 1..9
loop
passingArray.extend;
passingArray(passingArray.count) := 'what ever';
end loop;
End;
3. From your Main prog, you call Myproc
--declare a variable for type first
passingArray myTable := myTable();
begin
myProc(10, passingArray());
--At this point, You would be able to Join the PL_SQL table
--which gives you the power of using SQL with PL_SQL tables
end; -- end of main program
4. All done!I have not shown how to use PL_SQL tables in SELECT statements, as that is not the subject here.
At the end of the story, I would say, if you know the number of arguments that you are going to pass to a procedure, Simply use "that many" IN OUT parameters to finish your task(9 in your case). Although the proc call looks large with this, it is much simpler. The above approach is VERY helpful if YOU DO NOT KNOW THE NUMBER OF ARGUMENTS that you are sending AND receiving From a procedure.
Thx,
SriDHAR -
JavaFX : How to call java function that returns hashtable and manipulate
I have a requirement to {color:#0000ff}create a java object in JavaFX script code{color}. Then call a java function using the created java object. The java function returns hashtable. Then traverse through each element of hashtable. Finally I need to create a similar structure in JavaFX.
If you need to use a Java class that uses generics you need to take special steps. Since JavaFX does not support generics you need to create a java wrapper to hide the calls that use generics and call the wrapper class from FX.
-
How can I call a plsql function from an attribute?
I have an attribute defined in an element. I want execute a PLSQL function from the attribute, and display the returne value with an HTML template.
I've defined the attribute's type like PLSQL, and I've put the called of the function in the value of the attribute, but it doesn't work. The only value I obtain is an URL (I think that is the URL of the function or someting like this).
How can I call to my function from the attribute and display the returnes value in the page?
Thanks.Thanks, but it doesn't work. I have an attribute called ID_BOL and I want to associate a sequence to that attribute. I've created a function, with the sequence. This function return de value of the sequence. I want taht the attribute takes the value of the sequenece dinamically.
I've tried it, creating the type attribute like PLSQL, and calling the function from the attribute, but it doesn't work.
How can I return the sequence value to my attribute?
Thanks. -
Jobs gets hanged when a call is made to PLSQL function in Data Services XI
Hi,
I am facing the below issue after migration of BODI 11.7 to BODS XI 3.1.
The job is not proceeding after the below mentioned statements.
print('before call');
$is_job_enable=DS_TEST.TEST.MY_PKG.IS_JOB_ENABLED(job_name());
print($is_job_enable);
MY_PKG.IS_JOB_ENABLED plsql function will return Number.
$is_job_enable is a global variable declared as decimal (10, 0).
This Job works fine in Data Integrator 11.7.3 version and gets handed in Data Services XI 3.1.
I tried changing the global variable $is_job_enable to int and created new data sources before doesn't solve the problem. Can anyone tell me what is the issue?
Thanks & Regards
Maran MK
The trace file says
5260 3284 JOB 5/5/2009 4:43:17 AM Job <TEST_JOB> is started.
5260 3284 PRINTFN 5/5/2009 4:43:17 AM before call
5260 3284 SP 5/5/2009 4:43:18 AM Stored procedure call <MY_PKG.IS_JOB_ENABLED> is started.
5260 3284 SP 5/5/2009 4:43:18 AM SQL query submitted for stored procedure call <MY_PKG.IS_JOB_ENABLED> is: <BEGIN :AL_SP_RETURN :=
5260 3284 SP 5/5/2009 4:43:18 AM "TEST"."MY_PKG"."IS_JOB_ENABLED"("P_JOB_NAME" => :P_JOB_NAME); END;
5260 3284 SP 5/5/2009 4:43:18 AM >.
5260 3284 SP 5/5/2009 4:43:18 AM Stored procedure call <E> input parameter <P> has value of <TEST_JOB>.
5260 3284 SP 5/5/2009 4:43:18 AM Stored procedure call <E> return value is <1.0000000>.
5260 3284 SP 5/5/2009 4:43:18 AM Stored procedure call <MY_PKG.IS_JOB_ENABLED> is done.
The below error occurs only in Windows and not in Linux environment.
5260 3284 SYS-170101 5/5/2009 4:43:21 AM |Session TEST_JOB
5260 3284 SYS-170101 5/5/2009 4:43:21 AM System Exception <ACCESS_VIOLATION> occurred. Process dump is written to <E:\Program Files\Business Objects\Data
5260 3284 SYS-170101 5/5/2009 4:43:21 AM Services\log\BODI_MINI20090505044318_5260.DMP> and <E:\Program Files\Business Objects\Data
5260 3284 SYS-170101 5/5/2009 4:43:21 AM Services\log\BODI_FULL20090505044318_5260.DMP>
5260 3284 SYS-170101 5/5/2009 4:43:21 AM Process dump is written to <E:\Program Files\Business Objects\Data Services\log\BODI_MINI20090505044318_5260.DMP> and
5260 3284 SYS-170101 5/5/2009 4:43:21 AM <E:\Program Files\Business Objects\Data Services\log\BODI_FULL20090505044318_5260.DMP>
5260 3284 SYS-170101 5/5/2009 4:43:21 AM Call stack:
5260 3284 SYS-170101 5/5/2009 4:43:21 AM 001B:00CA9EAB, ActaDecimalImpl<RWFixedDecimal<RWMultiPrecisionInt<3> >,RWMultiPrecisionInt<3>,ActaDecimal28,char
5260 3284 SYS-170101 5/5/2009 4:43:21 AM [29]>::operator=()0315 byte(s), x:\src\rww\actadecimalimpl.cpp, line 13140004 byte(s)
5260 3284 SYS-170101 5/5/2009 4:43:21 AM 001B:00D8A267, Convert()+0999 byte(s), x:\src\eval\calc.cpp, line 0303
5260 3284 SYS-170101 5/5/2009 4:43:21 AM 001B:00DBF9E0, XVal_cast::compute()+0272 byte(s), x:\src\core\compute.cpp, line 1664
5260 3284 SYS-170101 5/5/2009 4:43:21 AM 001B:00DBC239, XStep_assn::execute()+0057 byte(s), x:\src\core\step.cpp, line 0069
5260 3284 SYS-170101 5/5/2009 4:43:21 AM 001B:00DBB30D, XStep_sblock::execute()+0029 byte(s), x:\src\core\step.cpp, line 0707
5260 3284 SYS-170101 5/5/2009 4:43:21 AM 001B:00DBB30D, XStep_sblock::execute()+0029 byte(s), x:\src\core\step.cpp, line 0707
5260 3284 SYS-170101 5/5/2009 4:43:21 AM 001B:00DBE0BC, XPlan_spec::execute()+0348 byte(s), x:\src\core\plan.cpp, line 0082
5260 3284 SYS-170101 5/5/2009 4:43:21 AM 001B:00DC5EA0, XPlan_desc::execute()+0336 byte(s), x:\src\core\xplan.cpp, line 0153
5260 3284 SYS-170101 5/5/2009 4:43:21 AM 001B:00DBD68E, XPlan_spec::compute()0206 byte(s), x:\src\core\plan.cpp, line 01450011 byte(s)
5260 3284 SYS-170101 5/5/2009 4:43:21 AM 001B:00DBD891, XPlan_spec::compute()+0225 byte(s), x:\src\core\plan.cpp, line 0244
5260 3284 SYS-170101 5/5/2009 4:43:21 AM 001B:0074533A, AE_Main_Process_Options()+31498 byte(s), x:\src\xterniface\actamainexp.cpp, line 3485
5260 3284 SYS-170101 5/5/2009 4:43:21 AM 001B:00747EDA, AE_Main()1498 byte(s), x:\src\xterniface\actamainexp.cpp, line 07680030 byte(s)
5260 3284 SYS-170101 5/5/2009 4:43:21 AM 001B:004029F9
5260 3284 SYS-170101 5/5/2009 4:43:21 AM Registers:
5260 3284 SYS-170101 5/5/2009 4:43:21 AM EAX=0000000E EBX=03E392E0 ECX=04B455A0 EDX=012346D8 ESI=02B75D88
5260 3284 SYS-170101 5/5/2009 4:43:21 AM EDI=04B455A0 EBP=00212738 ESP=002124BC EIP=00CA9EAB FLG=00210206
5260 3284 SYS-170101 5/5/2009 4:43:21 AM CS=001B DS=0023 SS=0023 ES=0023 FS=003B GS=0000
5260 3284 SYS-170101 5/5/2009 4:43:21 AM Exception code: C0000005 ACCESS_VIOLATION
5260 3284 SYS-170101 5/5/2009 4:43:21 AM Fault address: 00CA9EAB 01:00585EAB E:\Program Files\Business Objects\Data Services\bin\acta.dllHi Manoj & Tiji,
Thanks for your comments. Please find the below outcome.
print($is_job_enable); -- is not executed if PLSQL function is called.
I changed $is_job_enable to VARCHAR, still the same issue.
I created new project and executed the same in new job, still the same issue (all objects are new except Datastore).
The dmp happens only when we the PLSQL function is called. I commented the Function call, the execution proceeds further but got hanged in other PLSQL function call (different than the 1st one)
Is this bug in 12.1?
Can you tell any Hot fix available? If possible please give me the SAP Notes Number.
Is there any other way to execute the PLSQL functions/procedures in 12.1?
Thanks
Maran MK -
Can i use create function for MSSql scalar and table valude function.
Hi,
1) Can i use create function for MSSql scalar and table valued function?
2) How many type of user defined function are there in oracle 11g express?
3) And can i reture any "type" form user defined function?
yourse sincerely944768 wrote:
Q1)That means even if i return predefined types like integer, varchar2 then also PGA is used ?The data type does not determine where the variable is stored. A string (called a varchar2 in Oracle) can be stored in stack space, heap space, on disk, in a memory mapped file, in a shared memory, in an atom table, etc.
It is the who and what is defining and using that string, that determines where and how it is stored.
The Oracle sever supports 2 languages in PL/SQL. The PL (Programming Logic) language is a procedural/declarative language. It is NOT SQL. SQL is integrated with it. The PL/SQL engine uses private process memory (PGA). So PL/SQL variables exist in the PGA (but there are exceptions such as LOBs).
Q2) So please suggest me solution in oracle.Sounds to me you are looking at how to implement a T-SQL style function as an Oracle function, and once implemented, do joins on the function.
Do not use PL/SQL in SQL in place of a SQL select. It is not T-SQL.
One cannot use PL/SQL to create functions along the style of T-SQL, where the function executes a SQL using some conditional logic, and then return as if the function was a native SQL select.
T-SQL is an extension to the SQL language - making it a hybrid and very impure language implementation. PL is based on ADA - part of the Pascal family of languages. The E-SQL (embedded SQL) approach used in languages like C/C++, Cobol and Ada, has been transparently done in PL/SQL. You can write and mix PL code and variables with SQL code. And the PL/SQL engine figures out how to make the call from the PL/SQL engine to the SQL engine.
But PL/SQL is not "part" of the SQL language and does not "extend" the SQL language in a T-SQL fashion.
So you need to check your SQL-Server preconcepts in at the door, as they are not only irrelevant in Oracle, they are WRONG in Oracle.
The correct way in Oracle, in a nutshell - Use the SQL language to do data processing. Use PL/SQL to manage conditional process flow and the handling of errors. -
Function to return the Entry Value based on Assignment, Element and Date
Hi Guys,
Is there a function that returns the Entry Value for the Assignment Element, based on the Assignment Number, Element Name, Entry Segment and the End of Period date?
Example:
==============
Input Parameters:
Employee: Iana
Assignment Num: 123
Element: D480
Element Entry: Fund Name
Output Parameter:
Element Entry Value: MLC Super Fund
Thanks,
IanaFor element entry values you can use:
select petf.element_name, nvl(peevf.screen_entry_value,0) screen_entry_value
from
pay_element_entries_f peef, pay_element_types_f petf,
pay_element_entry_values_f peevf, pay_input_values_f pivf,
per_all_assignments_f paaf
where petf.element_type_id = peef.element_type_id
and :p_date_earned between pivf.effective_start_date and pivf.effective_end_date
and :p_date_earned between petf.effective_start_date and petf.effective_end_date
and peevf.input_value_id = pivf.input_value_id
and paaf.assignment_id = peef.assignment_id
and petf.business_group_id = :p_business_group_id
and peevf.element_entry_id = peef.element_entry_id
and :p_date_earned between peef.effective_start_date and peef.effective_end_date
and :p_date_earned between peevf.effective_start_date and peevf.effective_end_date
and :p_date_earned between paaf.effective_start_date and paaf.effective_end_date
and pivf.name = :p_input_value_name
and petf.element_name = :p_element_name
and peef.entry_type = 'E'
and peevf.effective_start_date = peef.effective_start_date
and peevf.effective_end_date = peef.effective_end_date
--and peef.assignment_id = :p_assignment_id
and paaf.assignment_number = :p_assignment_number;
For payroll results you can use:
select sum(prrv.result_value)
from pay_run_results prr, pay_run_result_values prrv,
pay_assignment_actions paa, pay_payroll_actions ppa,
pay_element_types_f petf, pay_input_values_f pivf,
per_all_assignments_f paaf, per_all_people_f papf
where
petf.element_type_id = pivf.element_type_id
and :p_pay_date between petf.effective_start_date and petf.effective_end_date
and :p_pay_date between pivf.effective_start_date and pivf.effective_end_date
and paa.assignment_action_id = prr.assignment_action_id
and petf.element_type_id = prr.element_type_id
and ppa.payroll_action_id = paa.payroll_action_id
and prrv.input_value_id = pivf.input_value_id
and prr.run_result_id = prrv.run_result_id
and petf.element_name = :p_element_name
and pivf.name = :p_input_value_name
and ppa.date_earned = :p_pay_date
and papf.person_id = paaf.person_id
and nvl(prr.start_date,ppa.effective_date) between paaf.effective_start_date and paaf.effective_end_date
and nvl(prr.start_date,ppa.effective_date) between papf.effective_start_date and papf.effective_end_date
and paaf.assignment_id = paa.assignment_id
and papf.employee_number = :p_employee_number; -
How to create and execute a function whose return value is a table
hi folks ,
i would like know how to create and execute a function whose return value is a table ,
am new to pl/sql ,
my statement for the function is
SELECT ct.credential_code, c.expiration_date
FROM certifications c, credential_types ct
WHERE ct.crdnt_id = c.crdnt_id
AND c.person_id = person_id;
i would like to have the result of the above query as return value for the function.
Thanks in advance ,
Ashok.chi Ps ,
Can you please do small sample ,
that would help me in clear understanding
thanks in advance
ashok.c -
Accessing function's return value
Hi there. I have created several pl/sql procedures and functions that I can run as standalone programs and I have no problem integrating them into my java code also. However I cannot access the return value of any created function from my java code. The functions appear to execute correctly because when I deliberately enter an invalid select statement I get the errors I expect to get for that instance nad if I enter a valid select statement in the function the program executes correctly but I still cannot access the function's return value. My java code where I execute the pl/sql function is as follows:
CallableStatement p = cont.conn.prepareCall("{call ? := Hellen.FUNC}");
p.setString(1, "z006"); //hellen.FUNC = function name
p.execute();
How do I access the return value of my function?
Do I need to get a ResultSet?
My function is as follows:
function func
return varchar
is tester varchar(4);
BEGIN
select cfcc_code into tester from hellen.test1 where test1.cfcc_code = 'A21';
return tester;
END;
Any help will be gratefully received, JoeYou need to do something like
p.registerOutParameter(1, java.lang.String);
p.execute();
String result = p.getString(1);Cheers, APC -
I'm attempting to dynamically generate a rather large SQL query via the "PL/SQL function body returning SQL query" report region option. The SQL query generated will possibly be over 32K. When I execute my page, I sometimes receive the "ORA-06502: PL/SQL: numeric or value error" which points to a larger than 32K query that was generated. I've seen other posts in the forum related to this dynamic SQL size limitation issue, but they are older (pre-2010) and point to the 32K limit of the DNS (EXECUTE IMMEDIATE) and DBMS_SQL. I found this post (dynamic sql enhancements in 11g) which discusses 11g no longer having the 32K size limitation for generating dynamic SQL. Our environment is on 11gR2 and using ApEx 4.2.1. I do not know which dynamic SQL method -- DNS or DBMS_SQL -- ApEx 4.2.1 is using. Can someone clarify for me which dynamic SQL method ApEx uses to implement the "PL/SQL function body returning SQL query" option?
As a test, I created a page on apex.oracle.com with a report region with the following source:
declare
l_stub varchar2(25) := 'select * from sys.dual ';
l_sql clob := l_stub || 'union all ';
br number(3) := 33;
begin
while length ( l_sql ) < 34000 loop
l_sql := l_sql || l_stub || 'union all ';
end loop;
l_sql := l_sql || l_stub;
for i in 1 .. ceil ( length ( l_sql ) / br ) loop
dbms_output.put_line ( dbms_lob.substr ( l_sql, br, ( ( i - 1 ) * br ) + 1 ) );
end loop;
return l_sql;
end;
The dbms_output section is there to be able to run this code in SQL*Plus and confirm the size of the SQL is indeed larger than 32K. When running this in SQL*Plus, the procedure is successful and produces a proper SQL statement which can be executed. When I put this into the report region on apex.oracle.com, I get the ORA-06502 error.
I can certainly implement a work-around for my issue by creating a 'Before Header' process on the page which populates an ApEx collection with the data I am returning and then the report can simply select from the collection, but according to documentation, the above 32K limitation should be resolved in 11g. Thoughts?
Shane.What setting do you use in your report properties - especially in Type and in Region Source?
If you have Type="SQL Query", then you should have a SELECT statement in the Region Source. Something like: SELECT .... FROM ... WHERE
According to the ERR-1101 error message, you have probably set Type to "SQL Query (PL/SQL function body returning SQL query)". In this situation APEX expects you to write a body of a PL/SQL function, that will generate the text of a SQL query that APEX should run. So it can be something like:
declare
mycond varchar2(4000);
begin
if :P1_REPORT_SEARCH is not null THEN
mycond:='WHERE LAST_NAME like :P1_REPORT_SEARCH ||''%''';
end if;
return 'select EMPLOYEE_ID, FIRST_NAME, LAST_NAME from EMPLOYEES ' ||mycond;
end;
And for escaping - are you interested in escaping the LIKE wildcards, or the quotes?
For escaping the wildcards in LIKE function so that when the user enters % you will find a record with % and not all functions, look into the SQL Reference:
http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/conditions007.htm
(You would than need to change the code of your function accordingly).
If you are interested in escaping the quotes, try to avoid concatenating the values entered by the user into the SQL. If you can, use bind variables instead - as I have in my example above. If you start concatenating the values into the text of SQL, you are open to SQLInjection - user can enter anything, even things that will break your SQL. If you really need to allow users to choose the operator, I would probably give them a separate combo for operators and a textfield for values, than you could check if the operator is one of the allowed ones and create the condition accordingly - and than still use bind variable for inserting the filtering value into the query. -
How to use a select list value in a PL/SQL function body returning SQLquery
Hi Friends,
I have a select list P6_TEST with values 'nav' anf 'jyo'. I am trying to create a report using "SQL Query (PL/SQL
function body returning SQL query)". In my report query can i check if P6_TEST='nav' and do something like the
code shown below.How can i do that.
DECLARE
v_sql VARCHAR2(3000);
BEGIN
IF :P6_TEST = 'nav' THEN
v_sql :=
'SELECT
* from department';
........................Thanks,
NavNav:
What you have should work. Give it a go. Post back if you run into issues.
Varad
Maybe you are looking for
-
This mistake has confused the account somehow and actions done on one phone often have an effect on the other. I took these phones back to the dealer where they were purchased a few months ago, and they were able to correct some of the issues, but we
-
I use photoshop elements 12 on Macbook air and the screen freezes when I try to use the tools. Then i have to force quit so i lose my work. anyone know how to fix this issue?
-
Hi all, i don't know if any body noticed this, when i do simple editing to the sampler insterment editor (exs24) i got a window ask me if i want to save changes ofcourse i say yes but then i got onther window open with folder and ask me to save as !!
-
Unable to see Macintosh HD with Alt Option
Hi, I am novice user in OSX Systems, and i trying to install the OS from the scratch but i don t know why ... i dont see the internal HDD to install I tried two diffrent options, after erase the HDD with GUID partition using the Disk Utility Option.
-
Mail won't launch after Mavericks upgrade OS X 10.9
This is part of the error message I receive: Process: Mail [315] Path: /Applications/Mail.app/Contents/MacOS/Mail Identifier: com.apple.mail Version: 7.0 (1816) Build Info: Mail-1816000000000000~1 Code Type: