Little knowledge of PL/SQL here, so need a bit of help.
I have the a query that I need to turn into a function (let's call it reject_list), but not sure how to do it. This is what I have so far:
create or replace function reject_list(ayrc in varchar2,mcrc in varchar2)
return string
begin
select distinct
'<tr><td>'||cap.cap_uci2||'</td>
<td>'||cap.cap_stuc||'</td>
<td>'||cap.cap_mcrc||'</td>
<td>'||cap.cap_ayrc||'</td>
<td>'||stu.stu_fnm1||'</td>
<td>'||stu.stu_surn||'</td>
<td>'||cap.cap_stac||'</td>
<td>'||cap.cap_crtd||'</td></tr>'
from
intuit.srs_cap cap
,intuit.ins_stu stu
,intuit.srs_apf apf
where
cap.cap_stuc = stu.stu_code
and cap.cap_apfs = apf.apf_seqn
and cap.cap_stuc = apf.apf_stuc
and cap.cap_mcrc = &mcrc
and cap.cap_ayrc = &ayrc
and cap.cap_idrc in ('R','CR','CFR')
and apf.apf_recd <= to_date('1501'||substr(&ayrc,1,4),'DDMMYYYY');
end;
This doesn't run - can anyone help?
Thanks :)
EDIT: This query is one that is being run in an application already but we are trying to optimize it for speed. I am not certain whether a function is the best option, but we have, in another part of the application created a function to return simple counts which improved the speed exponentially. I need guidance more than just straightforward instructions on how to turn this into a function. If a view is the best option, for example, please could someone offer some guidance on how would be the best way to do this?
The object, therefore, is to be able to have a query stored on the server which allows me to enter the parameters and return the fields listed. To make this more complicated, one thing I did not mention before is that this needs to be formatted as an HTML table. I have now added the markup that would do this into the query above, and all the fields need to be concatenated.
Any help on this is greatly appreciated.
stringisn't a valid SQL type, in Oracle at least.) Why do you need to turn your query into a function? (If it's just to be able to use the same query in multiple places without repeating it, you might be better off with a view.) In SQL Server, stored functions can return the result of a SELECT query - are you looking for the Oracle equivalent of this?subtype STRING is VARCHAR2;. Share and enjoy.SELECT DISTINCTin your query? What indexes are on the tables? Roughly how many rows are in the tables and roughly how many rows should the query return? How is this function being called, and from what language? Also, why do you need to return HTML from the database?