Sort(Order by) a cursor by cursor parameter
Hello,
I want to make cursor to query three column data, and order by the paramter when calling store procedure. But the cursor did not order by column name at all.
Any help will be appreciated.
ggu.
My package/procedure:
CREATE OR REPLACE PACKAGE test_PKG AUTHID DEFINER
AS
TYPE REF_CUR IS REF CURSOR;
PROCEDURE test_proc(COLN IN VARCHAR2, OUTCUR OUT REF_CUR);
END test_PKG;
CREATE OR REPLACE PACKAGE BODY TEST_PKG
AS
PROCEDURE test_proc(COLN in varchar2, outcur out ref_cur) IS
BEGIN
IF NOT OUTCUR%ISOPEN
THEN
open OUTCUR FOR
SELECT CPS.PYROL_ID,
CPS.VEND_ID,
CPS.CONT_ID
FROM EPRS.CNTRCTR_PYROL_SUBMIT CPS
ORDER BY COLN; <------What should be here?
END IF;
end test_proc;
end test_pkg;
var results refcursor;
execute test_PKG.test_PROC('Vend_ID', :results);
print results;
It gave me results:
PYROL_ID VEND_ID CONT_ID
193 06883 009214070
196 11756 202101064
205 06507 072202046
206 06507 042202046
207 06507 032202046
208 06883 012202046
I could make the question more clear;
I want to query a table, for example, with three columns. The query results should be sorted by one specific column. I want to leave the column to be ordered by as a parameter, how to implment it?
Thanks.
Similar Messages
-
Sort Order problem in a cursor
Hi,
I have a cursor where the sort order needs to be specified dynamic. I have declared variables (say x and y) which contains the numbers. When I use them in the order by clause, though no compilation error, but the sorting does not occur.
Eg. Cursor C1 is
Select col1,col2
from tab1
where ...
ORDER BY x (the value of x is 2).
Your help is greatly appreciated. (This cursor is in Oracle Forms)
ThanksHow come this works:
select samp1,samp2
from (select 'abc' samp1, 123 samp2 from dual union all
select 'mno' samp1, 456 samp2 from dual union all
select 'def' samp1, 3 samp2 from dual union all
select 'pqr' samp1, 12 samp2 from dual union all
select 'jkl' samp1, 64 samp2 from dual union all
select 'stu' samp1, 10 samp2 from dual union all
select 'vwx' samp1, 88 samp2 from dual union all
select 'ghi' samp1, 7 samp2 from dual union all
select 'yzz' samp1, 1 samp2 from dual
) testdata
order by &x
Enter value for x: 2
old 12: order by &x
new 12: order by 2
SAM SAMP2
yzz 1
def 3
ghi 7
stu 10
pqr 12
jkl 64
vwx 88
abc 123
mno 456
9 rows selected.
select samp1,samp2
from (select 'abc' samp1, 123 samp2 from dual union all
select 'mno' samp1, 456 samp2 from dual union all
select 'def' samp1, 3 samp2 from dual union all
select 'pqr' samp1, 12 samp2 from dual union all
select 'jkl' samp1, 64 samp2 from dual union all
select 'stu' samp1, 10 samp2 from dual union all
select 'vwx' samp1, 88 samp2 from dual union all
select 'ghi' samp1, 7 samp2 from dual union all
select 'yzz' samp1, 1 samp2 from dual
) testdata
order by &x
Enter value for x: 1
old 12: order by &x
new 12: order by 1
SAM SAMP2
abc 123
def 3
ghi 7
jkl 64
mno 456
pqr 12
stu 10
vwx 88
yzz 1
9 rows selected.Isn't this what is wanted?
-Marilyn -
Problem in passing ref cursor values as parameter in where clau.Most Urgent
Problem:
1) I have used normal cursor (C_hubmsgid_set) with some select statement such as grouping and all.
After executing the query it will return some resultset to the specified cursor.
2) I am trying to use another cursor which is ref cursor but the problem is
I want to give all the resultset based on all the conditions to the ref cursor.
But the cursor will get only the last record due to overwriting .how to get all
the result set in a ref cursor like
cursor c1 is select .....
loop
open refcursor for
Select * from ....where condition
end loop
After this the refcursor( p_sysaudithistory_cur) which should have all the resultset matched by the where condition.
3. It should be java compatible one.
4. I am not able to match cursor row = IN Pameter value
Below is the query:
CREATE OR REPLACE PROCEDURE SP_TEST_audit_history2 (
p_start IN date,
p_end IN date,
p_msgcode IN varchar2,
p_partnername IN varchar2,
p_status IN varchar2,
p_locationname IN varchar2,
p_custbusunit IN varchar2,
p_sysaudithistory_cur OUT plutotypes.ref_cursor,
p_status1 OUT NUMBER) AS
l_status NUMBER := 0;
CURSOR C_hubmsgid_set IS
SELECT DISTINCT MAX(tfm.datetime) datetime, tfm.hubmsgid
FROM tfm_status tfm, vw_msgcode_part_locn vw
WHERE
tfm.datetime >= NVL(p_start, TO_DATE('01/01/1981','DD/MM/YYYY')) AND
tfm.datetime <= NVL(p_end, TO_DATE('31/12/9999','DD/MM/YYYY')) AND
tfm.msgcode LIKE NVL(p_msgcode,'%') AND
vw.msgcode = tfm.msgcode
AND vw.partnername LIKE NVL(p_partnername,'%')
AND tfm.status LIKE NVL(p_status,'%')
AND vw.locationname LIKE NVL(p_locationname,'%')
AND vw.custbusunit LIKE NVL(p_custbusunit,'%')
AND rownum < 250
GROUP BY tfm.hubmsgid
ORDER BY datetime DESC;
/* Loop through the Cursor */
BEGIN
BEGIN
OPEN p_sysaudithistory_cur
FOR
SELECT
tfm.hubmsgid ,
tfm.status || '-'|| nvl2(tfm.exception_id,'FAILED','OK') ,
tfm.datetime,
tfm.exception_id
FROM tfm_status tfm
WHERE tfm.hubmsgid = c_hubmsgids.hubmsgid /* here only i am getting error*/
AND tfm.datetime = c_hubmsgids.datetime
AND tfm.status like NVL(p_status,'%')
and rownum =1;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_status := 1;
END;
p_status1 := l_status;
END;
Thanks in advance
prasanth a.s.Please don't post duplicate questions. All it does is clutter the forums and result in fragmented threads and duplicate responses. Please see my response in the original thread at the link below.
Please solve this Refcursor issue PLEASE -
Stored procedure with cursor as out parameter
Can any one help me by showing how to write a procedure with cursor as out parameter and caputuring it in java using jdbc.
Thanks in advance,
shravan bharadwajI know that in the SQLJ distribution (which is also downloadable) there is an example in the demo directory called RefCursDemo that shows the SQL code and how to call it - albeit from SQLJ and not JDBC. There may also be a demo in the JDBC distribution, though I am not sure about that.
-
Hi,
is it possible to use a REF cursor as a parameter for a job? I need jobs created with DBMS_SCHEDULER.create_job to process data which has always the same format but comes from different sources. The job must be generic and thus should not know where the data comes from. The job calls a PL/SQL procdure which takes the REF cursor as a parameter.
Regards,
Pat
Edited by: Gwydion on Jun 16, 2010 7:13 AMGwydion wrote:
I tried a different way: Instead of a ref cursor, I tried to pass a PL/SQL table containing the data that the job should process. Bad idea in general as this is not very scalable. A PL/SQL "+table+" is nothing table-like at all. The correct term is array or collection. This structure is primitive in that it cannot be indexed or structured like a SQL table. It also resides in "expensive" memory (the PGA/private memory of a server process) - unlike a SQL table data that will reside in the SGA buffer cache when used. The db buffer cache is shared memory - usable by all processes and thus "inexpensive" memory in comparison.
So passing and processing any largish data structure that way (via PGA memory) is inherently an unscalable approach. Also, this data set needs to persist until the job process kicks off - thus it needs to be stored somewhere. Why store this data again when it is based on table and row table that already exist in the database? Why duplicate the data?
You also need to consider data concurrency and integrity. By the time that job/scheduler background process kicks off and receives this data set structure to use for processing... the row data that this set was based on may have changed.. or may not even exist anymore.
For example, let's say that the data set contains a list of invoice numbers that need to be processed. Some of those invoices may have been canceled in the meantime. Or deleted from the system. Whatever invoice numbers this background server process now needs to deal with, can now be invalid.
You therefore need to carefully consider exactly what issues and requirements you're trying to address with this approach you are attempting. There are numerous problems areas that it needs to deal with.
Which begs the question - why are you considering this approach? What problem are you trying to address? Why not simply pass the parameters to the job it needs to use to call the procedure that creates the ref cursor? This is a much simpler and elegant solution than to pass the actual data returned by the ref cursor to the job. -
Function, cursor item as parameter in oracle 9i
Hello,
i have a block that make treatment for every cursor iteration
in fact, i wanna make a function that take as parameter the cursor iteration
so there is two possibilitities , i call this function when looping under the cursor,
or when i has a specified row on the table Contrat, let's say a result of select * from contrat where ...
here is the cursor definition :
CURSOR contrat_cursor (per_param IN NUMBER)
IS
SELECT *
FROM CONTRAT
WHERE PER_ID = per_param;
any one know how make this
Regards
Elyesin fact i have a loop over a cursor :
LOOP
tmp_var:=0;
FETCH contrat_cursor INTO contrat_rec;
EXIT WHEN contrat_cursor%NOTFOUND;
treatment1 -- i want to put all this trt1 in a function , and the function , since it depend on contrat_rec, will have a parameter
end loop;
in other context i need this function to make some trt in one row of the table contrat
so i can get this row with select * from contrat where ...
my question, is this ok when i give contrat_cursor%ROWTYPE as parameter to the function
and in the second context, when i get back i row from table contrat , how can i give this row as paramer , in contrat_cursor%ROWTYPE form
i wish it was clear
Regards
Elyes -
Using ref cursor in after parameter form in reports
hi everyone,
I have problem in usage of ref cursor in after parameter form. My actual requirement is I have user parameter :p_minval, :p_maxval. The values into these user parameters will be coming dynamically using sql_statement as shown below
select min(empid),max(empid) into :p_minval, :p_maxval from emp where empid in (:p_emp);
I will be writing this query in the after parameter form
:p_emp is a lexical parameter as per me but the after parameter form is taking it as a bind variable. so I decided to define a ref cursor and then use it for retrieve. But when I use ref cursor it is returning pl/sql error 591 saying that this is not supported by client side can anyone help me plz..
The following is the code i tried to use in after parameter form
function afterPform return boolean is
type rc is ref cursor;
l_rc rc;
sqlstmt varchar2(512);
begin
sqlstmt:='select min(empid),max(empid) from emp where empid in ('||:p_emp||')';
open l_rc for
select max(empid) from emp where empid in ('||:p_emp||')';
fetch l_rc into :p_maxval;
close l_rc;
return(true);
end;
thanks & regards
venkatI ran into the same problem. any body knows why?
-
Passing Ref Cursor as IN parameter
I have a situation where I have to send whole table into the stored procedure, I read from the oracle new feature for .Net documentation, It is possible to pass an ref cursor as IN parameter to an stored procedure. Please help me in this, it is urgent!
I am using Visual Studio.Net 2003, ODP.Net.Array binding is the best method for large inserts from .NET.
The problem with the associative array is:
-you must write a PL/SQL procedure to actually do the inserts.
-while this will get the data to the PL/SQL engine on the server in a block, it still must cross the into the SQL engine one row at at time.
-Array binding is simpler (you use a normal insert).
-There's a built-in knob to control the batch size.
-The array of row data is copied all the way into the SQL engine together, so it's faster.
Remember, array binding is how the SQL*Loader's conventional-path inserts work.
According to Tom Kyte "you can achive 100's of rows per second into heavily indexed tables that are concurrently being read and updated by other processes."
David -
Cursor like input parameter in function
Hi, All !
I have a question. I want use cursor like input parameter in function. How can I do this? Please give my an example.in fact i have a loop over a cursor :
LOOP
tmp_var:=0;
FETCH contrat_cursor INTO contrat_rec;
EXIT WHEN contrat_cursor%NOTFOUND;
treatment1 -- i want to put all this trt1 in a function , and the function , since it depend on contrat_rec, will have a parameter
end loop;
in other context i need this function to make some trt in one row of the table contrat
so i can get this row with select * from contrat where ...
my question, is this ok when i give contrat_cursor%ROWTYPE as parameter to the function
and in the second context, when i get back i row from table contrat , how can i give this row as paramer , in contrat_cursor%ROWTYPE form
i wish it was clear
Regards
Elyes -
Return Cursor as OUT Parameter
I have one Implicit Cursor which will store the table Data.May I have any Chance to send Implicit Cursor as OUT parameter?.
1) cursors (implicit or explicit) do NOT STORE table data. tables store table data.
2) why does implicit vs explicit matter to you? just write the code in the way that works
3) to return a cursor, use a refcursor
create procedure y ( rc in out sys_refcursor ) as
begin
open rc for select * from dual;
end;
SQL> var rc refcursor
SQL> exec y ( :rc )
PL/SQL procedure successfully completed.
SQL> print rc
D
X
1 row selected. -
Change the sort order (ascending/descending) based on parameter field
I have created a formula on a subreport to change sorting based on variables.
select {?Pm-@Sorting}
case "property_type_desc ASC" :
{owned_property.property_type_desc}
case "property_type_desc DESC" :
{owned_property.property_type_desc}
default:
({owned_property.property_type_cd}; )
how can I change the sort order ascending and descending using the formula??
Thanks, JessicaTry this
1. Create a parameter with 2 default values in the picklist: Descending and Ascending.
NOTE:
In Crystal Reports version 5 or 6, it is not possible to have a pick a parameter value from a list. The user must enter a specific value, guided by the prompting text. For example : To Sort in Ascending order type A, to sort in Descending order type D.
u2022 On the 'Insert' menu, click 'Parameter', then click 'New'.
u2022 Type the name and prompting text for the parameter in the corresponding boxes.
u2022 In the 'Type' box, click 'String'.
u2022 Click 'Set Default'.
u2022 In the 'Value to add' box, type 'Descending' then click '>' to move it to the 'Default Values' list.
u2022 Repeat the above step for 'Ascending'.
u2022 Click 'OK', then click 'OK' again to return to the report.
2. Create 2 formulas based on the field you want to change the sort direction on:
u2022 On the 'Insert' menu, click 'Formula', then click 'New'.
u2022 Create this formula:
@Asc
If {?Parameter} = "Ascending" then
u2022 Save this formula and close the Formula Editor. This brings you back to the Formula tab of the Insert Fields dialog box.
u2022 Click 'New' and create this formula:
@Des
If {?Parameter} = "Descending" then
u2022 Save this formula and close the Formula Editor.
u2022 Click 'Close' to return to the report.
4. Sort the report based on these two formulas.
u2022 On the 'Report' menu, click 'Sort Records'.
u2022 In the 'Report Fields' list, click {@Asc} and move it to the 'Sort Fields' list.
u2022 Under 'Sort Direction', click 'Ascending'.
u2022 In the 'Report Fields' list, click {@Des} and move it to the 'Sort Fields' list.
u2022 Under 'Sort Direction', click 'Descending'.
u2022 Click 'OK' to return to the report.
Once you preview the report you will be prompted to select a parameter value, which will determine how the report is sorted.
Regards,
Raghavendra -
Xsl:sort order parameter
Does the oracle xml parser support this syntax (works with Xalan)
<xsl:sort order="{$order}" select="sortnode" />
I need to parameterize the order="ascending/descending". I am sucessfully passing in my parameter (I can output it with <xsl:value-of select="$order"/>), but it doesn't seem to have any effect on the actual sorting.This is Bug 1798018. It was supposed to be fixed in 9.0.2C, but
I just retested it and the problem still persists.
The order and data-type attributes of <xsl:sort> don't
behave properly as Attribute Value Templates. -
Defining sort order using parameter fields
Post Author: vandersee
CA Forum: General
I've created a report, the contents of which is sorted depending on a parameter selected (method used is as described in the help topic entitled "Defining sort order using parameter fields". Is it possible to vary the Sort Direction (ascending/descending) using parameters also, so that if I choose to sort by field A it will be ascending, but descending if I choose to sort by field B?Post Author: V361
CA Forum: General
You can create a Parameter {?Sort Order} make it a string, and add items A to Z and Z to A and a formula and sort the group using the formula.
Group Expert, select the group, select options, check use a formula as group sort order
if {?Sort Order} = "A to Z" then crAscendingOrder else crDescendingOrder
And your group will sort based on what is selected in the parameter. -
MDO select query: how to control sort order using parameter
Hi experts, is there a way of controling the sort order of an MDO select query using some parameter?
I was thinking about using some statement like CASE [Param.1] WHEN 'abc' THEN [ORDER_NO]...END in sort section of the query but it is not working.
Of course I colud go for various select queries...but I am wondering if it can be done using only one?
Any ideas?
Thanks for any helpHi Marco,
Yes this can be achieved dynamically using SortExpr under dynamic link assignment in MDOAction block if you are using a transaction to call it.
Please check below thread:
Re: MDO Query Action Block In MII Transaction
Or else, this [Param.1] thing should work as well provided it doesn't get the logic part in it, just pass the columns names separated by comma. Haven't tried it though, will check it for you.
Best Regards,
Swaroop -
REF CURSOR as IN parameter to stored procedure
Currently, ODP.NET supports REF CURSOR parameter as OUT parameter only.
Based on the project requirements it is necessary to pass
multiple records to the stored procedure.
In this case REF CURSOR as IN parameter is useful.
What are the plans to implement REF CURSOR as IN parameter to stored procedure?
What is the work around in case it is necessary to pass several different
record types as arrays to stored procedure?ODP.NET does not limit REF Cursor parameters to IN parameters. This is a known PL/SQL limitation.
An excerpt from Application Developer's Guide:
"If you pass a host cursor variable to PL/SQL, you cannot fetch from it on the server side unless you also open it there on the same server call". -
Hello,
We have an LOV field on our OTL timecard called Rate Up. It is a custom timecard created by someone who is long gone. We would like it sorted in a particular order. We identified a database view that is likely the source of the data, but adding an ORDER BY in the view did not work.
This is probably really simple when one knows how. How can we put a sort order on this LOV?
Thank you,Both of these suggestions are really close. I thank Avinash and Giuseppe for their advice.
I found a validation set named XXEP_OTL_RATEUP_CODE_TK, but it is already sorted. We use this validation set on the Oracle Forms style OTL Timekeeper screens, but not on the web self service screens, where our sort problem exists.
I enabled diagnostics without any useful information, but a trace gave me the following sql statement which uses hxc_cui_custom4_v. I added an order by into the view, cleared cache, logged off and on, tried a different PC with a different user, but no luck sorting. So where is this select specified, so I can add an order by?
Thank you,
PARSING IN CURSOR #192 len=1188 dep=0 uid=435 oct=3 lid=435 tim=3702128553905 hv=3217417118 ad='b8abd5f8'
select distinct display_value displayvalue, value
from hxc_cui_custom4_v a,
(select trunc(FND_DATE.CANONICAL_TO_DATE(:1)) "TC_DATE" from dual) b
where person_id = :2
and b.TC_DATE between emp_per_start_date and emp_per_end_date
and b.TC_DATE between emp_asg_start_date and emp_asg_end_date
and b.TC_DATE between emp_pgr_start_date and emp_pgr_end_date
and b.TC_DATE between emp_sps_start_date and emp_sps_end_date
and b.TC_DATE between emp_gd_start_date and emp_gd_end_date
and b.TC_DATE between emp_pgd_start_date and emp_pgd_end_date
and b.TC_DATE between emp_pgs_start_date and emp_pgs_end_date
and b.TC_DATE between emp_pspp_start_date and emp_pspp_end_date
and b.TC_DATE between all_pgr_start_date and all_pgr_end_date
and b.TC_DATE between all_sps_start_date and all_sps_end_date
and b.TC_DATE between all_gd_start_date and all_gd_end_date
and b.TC_DATE between all_pgd_start_date and all_pgd_end_date
and b.TC_DATE between un_pur_start_date and un_pur_end_date
and b.TC_DATE between un_purv_start_date and un_purv_end_date
and b.TC_DATE between un_puci_start_date and un_puci_end_date
and b.TC_DATE between un_puci2_start_date and un_puci2_end_date
END OF STMT
EXEC #192:c=0,e=521,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,tim=3702128553897
FETCH #192:c=1430000,e=1552659,p=0,cr=25048,cu=0,mis=0,r=10,dep=0,og=1,tim=3702130106837
FETCH #192:c=0,e=52,p=0,cr=0,cu=0,mis=0,r=10,dep=0,og=1,tim=3702130109204
FETCH #192:c=0,e=21,p=0,cr=0,cu=0,mis=0,r=10,dep=0,og=1,tim=3702130109625
FETCH #192:c=0,e=14,p=0,cr=0,cu=0,mis=0,r=10,dep=0,og=1,tim=3702130109853
FETCH #192:c=0,e=42,p=0,cr=0,cu=0,mis=0,r=10,dep=0,og=1,tim=3702130111605
FETCH #192:c=0,e=22,p=0,cr=0,cu=0,mis=0,r=10,dep=0,og=1,tim=3702130112010
FETCH #192:c=0,e=19,p=0,cr=0,cu=0,mis=0,r=10,dep=0,og=1,tim=3702130112207
FETCH #192:c=0,e=194,p=0,cr=0,cu=0,mis=0,r=7,dep=0,og=1,tim=3702130112570
Maybe you are looking for
-
HT4095 why is it taking so long to download tv series
why is it taking so long to download tv series
-
Oracle 9i and 10g Agents on one server
Hello, What are the conflicts if I installed 10g agent on the server that 9i agent already occupy. I want to use 9i and 10g OEM. Thank you in advance.
-
How to set/change ip-address on ethernet interface
I have an IP address set on my wireless interface (with Internet access - no problem here), but I want to use my Ethernet interface to connect to a NAS device, on a "private/hidden" network - different network (10.0.1.xx) What is the best way to do t
-
Quicktime file import failure in CS5 After Effects and PPro
Running a Dell PC with a fresh install of Win 7 Pro, Intel Quad Core 2 with 4GB. Ram.When I try to import quicktime files into AE or PPro, I get a file import failure or corrupted file message. I am using quicktime version 7.6.6. I have tried unin
-
Updating gallery causes gallery to disappear?!?
I have a few galleries in iPhoto (7.1.1), if I try to update one of them by either adding a photo or even changing to sort by date (currently set to manual sort), the status icon by the gallery spins for a few seconds and then I find myself viewing m