CURSOR variable in
Trawling back through messages, but have not seen a response.
I want to move a collection to a procedure and do something with this collection. The procedure can be called from another proc or a c# program.
Heres my demo
-create table test and place 2 records in
create table t_curtest (col1, col2 number number)
insert into t_curtest
values (1,1);
insert into t_curtest
values (2,2);
commit;
create package specification
SQL > create or replace package pkg_curtest
2 AS
3 TYPE t_curtype IS TABLE OF t_curtest % ROWTYPE;
4 procedure prc_curtest
5 (v_curvar IN t_curtype);
6 END;
7
8
9.
Package created.
SQL >
create the package body that takes in a slider and bulk collect into a table
SQL > create or replace package body pkg_curtest
2 EAST
3 procedure prc_curtest
4 (v_curvar IN t_curtype)
5 EAST
6 BEGIN
FORALL i in 1 7... v_curvar. Count
8
9 INSERT INTO t_curtest
10 VALUES v_curvar (i);
11
12 COMMIT;
13
14 END;
15 END;
16
17.
Package body created.
SQL >
Now try and move a cursor in the further procedure and we get incorrect types. what I am doing wrong? It's whole approach?
SQL > create or replace procedure call_curtest
2 AS
3 cursor c1 is select * from t_curtest; -same table we'll insert to so we know its good
4 BEGIN
5. place the cursor in a procedure call.
6 pkg_curtest.prc_curtest (c1);
7 END;
8.
CAUTION: Procedure created with compilation errors.
SQL > show errors
Errors in PROCEDURE CALL_CURTEST:
LINE/COL ERROR
-------- -----------------------------------------------------------------
6/5 PL/SQL: statement ignored
6/5 PLS-00306: wrong number or types of arguments in the call to
'PRC_CURTEST '.
This final procedure call, you declare your cursor of the same type
create or replace procedure call_curtest 2 AS 3 cursor c1 is select * from t_curtest; -- same table as we're inserting to so we know its good 4 BEGIN 5 -- pass cursor into procedure call. 6 pkg_curtest.prc_curtest(c1); 7 END;
Try declaring the cursor first as type pkg_curtest. t_curtype
FYI: Just noticed your comment - this is where your assumption is incorrect:
-same table we'll insert to so we know its good
You need not even as a TABLE. you need the same type...
Tags: Database
Similar Questions
-
Example of using a Ref Cursor variable procedure
I'm looking for an example of how to execute a stored procedure with a Ref cursor variable in SQL Developer 3.0. I am familiar with the syntax in SQL * Plus, for example:
variable my_cur refcursor;
Start
my_package.my_proc ("in param"
(: my_cur);
end;
/
print: my_cur
How would I do the same thing in SQL Developer 3.0?
Thank you!Run a procedure directly. For example, select the package in the browser-> menu-> Run. The dialogue with anonymous block box. Edit, OK it to run, then the procedure would be and all settings including Ref Cursor appear in the grid. (This functionality is there since 3.0)
-
How to inspect a cursor variable in a debug session?
In a function inside the body of a package I...
Example:
V_SITUACIONESACTYHIST C_SITUACIONESACTYHIST % ROWTYPE;
...
BEGIN
....
FOR v_SituacionesACTyHIST IN c_SituacionesACTyHIST (p_id_DECE400, p_idpers)
LOOP
IF (V_SITUACIONESACTYHIST. ESTADO_SITUACION = THE OF ') THEN
v_hay_regs_hist: = 1;
END IF;
...
END LOOP;
where the c_SituacionesACTyHIST cursor variable is declared in the package specification (that is the problem, because is a global statement?).
When you are debugging I can't inspect the value of V_SITUACIONESACTYHIST. ESTADO_SITUACION or some variable field cursor. I always get "NULL" as the value...
Why?
How can I see the value of the variables?
I have the same problem in v2.1 and 1.5.5 version of sqldeveloper.
Thank you.
Published by: pacoKAS on February 11, 2010 0:14
Published by: pacoKAS on February 11, 2010, 0:17
Published by: pacoKAS on February 11, 2010, 0:17
Published by: pacoKAS on February 11, 2010 0:19
Published by: pacoKAS on February 11, 2010 0:21
Published by: pacoKAS on February 11, 2010 0:22
Published by: pacoKAS on February 11, 2010 0:22I suggest that you do not have a variable, the same name as your cursor variable.
CREATE OR REPLACE PROCEDURE P1 AS CURSOR test_cur IS SELECT owner, table_name FROM all_tables WHERE ROWNUM <= 10; -- x test_cur%rowtype; /* This variable is not needed. */ BEGIN FOR x IN test_cur /* If you don't have another variable named x somewhere, you can see values for x */ LOOP dbms_output.put_line(x.owner || '.' || x.table_name); END LOOP; END P1;
in your example...
V_SITUACIONESACTYHIST C_SITUACIONESACTYHIST%ROWTYPE; ... BEGIN .... FOR v_SituacionesACTyHIST IN c_SituacionesACTyHIST( p_id_DECE400, p_idpers ) LOOP IF ( V_SITUACIONESACTYHIST.ESTADO_SITUACION = 'S' ) THEN v_hay_regs_hist:=1; END IF; ... END LOOP;
You declare your variable twice:
(1) V_SITUACIONESACTYHIST C_SITUACIONESACTYHIST % ROWTYPE;
(2) FOR v_SituacionesACTyHIST IN c_SituacionesACTyHISTWhen you debug, she is interested in the first version... which sucks because you don't have whatever it is assigned to it. When you use a cursor for loop like this, it implicitly declares the variable for you. You don't have to do that in your section SAID.
Published by: DylanB123 on February 16, 2010 13:04
-
How to recover full date format and time of cursor Variable
Hi gurus,
I'm having this 'cable' question.
When I run this selection (below) of a table (a table with a date data type can be used for testing purposes)
Select max (crt_heure_entree) in the test.var_table_date MAX_DATE
MAX_DATE
-----------------------
21/12/2015-15:33:57
When I run inside a PL/SQL block
Declare
CRS1 DATE;
..
...
Select max (crt_heure_entree) as max_date in crs1 infapp.compte_rendu_traitement;
dbms_output.put_line ('MAX_DATE... » || TO_DATE (crs1,' DD/MM/YYYY HH24:MI:SS'));)
...
...
END;
I get
MAX_DATE
-----------------------
21/12/2015
Problem:
I need to get the full value date and the time to do a select and insert data between call dates and times.
Because the variable retrieves just the date I have problems of constraint violation.
Question:
How can I recover the full date / time format of cursor?
Thanks if you can help.
Format before you print using TO_CHAR
Here is the link for the Format of Date patterns
https://docs.Oracle.com/CD/B28359_01/server.111/b28286/sql_elements004.htm#CDEHIFJA
-
HI all PL/SQL gurus...
I have a slider I open in a loop as follows...
for rec in c_ship_report...
loop
UTL_FILE.put_line (v_file_handle, 'LI =' |) '}'|| {v_count |'} ' ||' 1'||'}'|| {Rec.ship_to_org_id |'} ' |' 90'||'}'||' {4001' |'} ' ||
{(TO_CHAR (rec.trx_date, 'YYYYMMDD')) |'} ' ||'} ' || recomm. NUMBER_OF_PALLETS...
> >
> >
> >
> >
end of loop.
One of the variables in the cursor (CRE. NUMBER_OF_PALLETS) is a value that needs to be summarized and put on a trailer line in a file that is created by using utl_file.
How would I go about doing so inside the PLSQL procedure?
Thanks a lot for your help.
ConcerningHello
Create a local variable called total_pallets and add every time that you go through the loop:
total_pallets := 0; -- or initialize this variable when you declare it for rec in c_ship_report..... loop total_pallets := total_pallets + NVL (rec.number_of_pallets, 0); utl_file.put_line ( v_file_handle , 'LI=}' || v_count || '}1}' || rec.ship_to_org_id || '}90}4001}' || TO_CHAR ( rec.trx_date , 'YYYYMMDD' ) || '}}' || rec.NUMBER_OF_PALLETS ...; end loop.
You can use the variable as you want once the loop is completed.
-
Is a cursor variable determined by the result set persistence pause feature?
My world of PL/SQL is upside down: I'm expecting cursor set persistence any operation of inner loop can affect the result. This does not work as expected with an aggregation as subquery (see sal_dept), but adds little by little upward in determining the value of the slider by a function (see sel_debt_funct). What is the reason for this behavior? Bug feature?
Facts: Oracle 10.2.0.4
Result:CREATE OR REPLACE FUNCTION get_sal_dept( pdeptno IN emp.deptno%TYPE ) RETURN emp.sal%TYPE IS lnreturn emp.sal%TYPE; BEGIN SELECT SUM(sal) INTO lnreturn FROM emp WHERE deptno = pdeptno; RETURN lnreturn; END get_sal_dept; / BEGIN FOR r_emp IN (SELECT empno ,ename ,sal ,emp.deptno ,sal_dept ,get_sal_dept(emp.deptno) sel_debt_funct FROM emp ,(SELECT deptno ,SUM(sal) sal_dept FROM emp GROUP BY deptno) x WHERE emp.deptno = x.deptno) LOOP UPDATE emp SET sal = sal * 1.33 WHERE empno = r_emp.empno; DBMS_OUTPUT.put_line(r_emp.ename || ': ' || r_emp.sal || ' Total Deptno: ' || r_emp.deptno || ' by inline aggr:' || r_emp.sal_dept || ' by function:' || r_emp.sel_debt_funct ); END LOOP; ROLLBACK; END; / DROP FUNCTION get_sal_dept /
CLARK: 2450 Deptno Total: 10 by aggr:8750 inline by function: * 8750 *.
KING: 5000 Deptno Total: 10 by inline function aggr:8750: * 9558.5 *.
MILLER: 1300 Deptno Total: 10 by inline function aggr:8750: * 11208.5 *.
JONES: 2975 Deptno Total: 20 by inline aggr:10875 by function: * 10875 *.
FORD: 3000 Deptno Total: 20 by inline function aggr:10875: * 11856.75 *.
ADAMS: 1100 Deptno Total: 20 by inline function aggr:10875: * 12846.75 *.
...
...
Edited by: user577229 the 07.06.2011 09:27
Published by: BluShadow on June 8, 2011 08:29
addition of {noformat}{noformat} tags
If I understand your point, the key concept to understand here is related to "* statement-level Read consistency and coherence of reading at the level of transactions."
From the Manual:
+ "If a SELECTION list contains a function, then the database applies consistency of reading to the statement-level to the level of the SQL statement executed in the PL/SQL function, rather than the parent level SQL code. For example, a function can access a table whose data are changed and committed by another user. For each execution of the function, SELECT a snapshot consistent new reading is established. » +These two concepts are well explained in the "Oracle® Database Concepts":
http://download.Oracle.com/docs/CD/B19306_01/server.102/b14220/consist.htm#sthref1955 -
Ref Cursor, object variable and cusror Cursor
Hello Experts,
I am little confused with the concept of cursor objects
For the variable curosr we can attribute any select statement
For example
Suppose that I assigned 2 Select staemnt to same variable as open c1 cursor for select * Dept, then I m posting new query without closing the c1 open c1 for select * from emp what will happen? What is the role of the object cursor here? I'm really confued thereby as cursor variable points to the result set? Can you please explain how same variable works with differnet queries? We hear how even variable points to the differnet result sets thank you very much in advance, SShubhangi
I am little confused with the concept of cursor objects
Post a link to the Oracle documentation, you are using and a quote from the section that you are confused about.
For the variable curosr we can attribute any select statement
Yes - as you can put a small yellow "sticky notes" on your refrigerator or Cabinet you or on your stove. Stick to what you want - but you can only stick on ONE element at a time.
For example
Suppose that I assigned 2 Select staemnt to same variable as open c1 cursor for select * Dept, then I m posting new query without closing the c1 open c1 for select * from emp what will happen?
What happened when you tried?
Do not be afraid to break the Oracle actually trying things. It's the best way to learn.
Try what you said and post the results.
I'm really confued thereby as cursor variable points to the result set? Can you please explain how same variable works with differnet queries? We hear how same variable points to the results of differnet games
Re-read what I said just above.
Then explain how you can "point" that yellow "sitcky note" any object you want. You can put on a single object. Then you can remove this object and put it on another object.
But no matter how many times do you it can only stick to ONE object at a time.
What is confusing in this regard?
See the PL/SQL language for the OPEN statement doc
http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/open_statement.htm#i35173
As a general rule, PL/SQL analysis a cursor explicit only the first time it is opened and analysis a SQL (creating an implicit cursor) only the first time the statement is executed. All the parsed SQL statements are cached. An SQL statement is parsed once again if it is aged in the cache by a new SQL statement. Although you must close a cursor before you can reopen, PL/SQL cannot analysis associated with
SELECT
statement. If you close and reopen the cursor immediately, an analysis is certainly not necessary.Did you notice the line that begins: "Although you must close a cursor before you can reopen?
-
Get the bind variables name string SQL or the cursor
Hello
Is there way to get of the bind variables name string SQL or the cursor?
Example of
What I mean with the SQL string:DECLARE l_sql VARCHAR2(2000); desctab DBMS_SQL.DESC_TAB; curid PLS_INTEGER; BEGIN l_sql := 'SELECT * FROM emp WHERE mgr = :X and deptno = :Y'; curid := dbms_sql.open_cursor; dbms_sql.parse(curid, l_sql, dbms_sql.NATIVE); .... END;
I love to get using some functions from above code variable l_sql all the bind variable.
In this case the function should return array where is for example: X and: Y
Back to bind the cursor variable names, I mean same but rather string I pass number of cursor.
Y at - it sucks ready function or some may share a code customized for this purpose?
Thanks
Kind regards
Jari
http://dbswh.webhop.NET/dbswh/f?p=blog:Home:0Regards,
Published by: jarola December 19, 2011 02:44
I found there are wwv_flow_utilities.get_binds of the function not documented in APEX packages that do what I want.
Usage example
But I would not use these functions without papers as those who can change or there is no future versions APEX.set serveroutput on DECLARE binds DBMS_SQL.varchar2_table; BEGIN binds := wwv_flow_utilities.get_binds('select :P1_TEST from dual'); FOR i IN 1 .. binds.count LOOP dbms_output.put_line(binds(i)); END LOOP; END; / anonymous block completed :P1_TEST
Is there a documented function or the custom function that do the same thing as wwv_flow_utilities.get_binds?Some old basic example code of my friends. Also the media getting the bind variable of PL/SQL code blocks anon.
SQL> create or replace function GetBindVariables( statement varchar2 ) return TStrings is 2 --// bind variables names are terminated by one the following special chars 3 SPECIAL_CHAR constant TStrings := TStrings(' ',')','+','-','>','<','*',',','=',';',CHR(10),CHR(13)); 4 5 --// max size of a bind var name 6 MAX_VARSIZE constant integer := 100; 7 8 pos integer; 9 pos1 integer; 10 occur integer; 11 varName varchar2(100); 12 varList TStrings; 13 begin 14 varList := new TStrings(); 15 16 --// looking for the 1st occurance of a bind variable 17 occur := 1; 18 19 loop 20 pos := InStr( statement, ':', 1, occur ); 21 exit when pos = 0; 22 23 varName := SubStr( statement, pos, 100 ); 24 25 --// find the terminating char trailing the 26 --// bind variable name 27 pos1 := Length( varName ); 28 for i in 1..SPECIAL_CHAR.Count 29 loop 30 pos := InStr( varName, SPECIAL_CHAR(i) ) - 1; 31 if (pos > 0) and (pos < pos1) then 32 pos1 := pos; 33 end if; 34 end loop; 35 36 --// extract the actual bind var name (without 37 --// colon char prefix) 38 varName := SubStr( varName, 2, pos1-1 ); 39 40 --// maintain a unique list of var names 41 if not varName member of varList then 42 varList.Extend(1); 43 varList( varList.Count ) := varName; 44 end if; 45 46 --// look for the next occurance 47 occur := occur + 1; 48 end loop; 49 50 return( varList ); 51 end; 52 / Function created. SQL> SQL> select 2 column_value as BIND_VAR 3 from TABLE( 4 GetBindVariables('select * from foo where col=:BIND1 and day = to_date(:B2,''yyyy/mm/dd'')') 5 ); BIND_VAR ------------------------------ BIND1 B2 SQL>
PS. just realize this code is case-sensitive, while variable bind is not. Should throw a upper() or lower() by adding the name of the var to the list - never really a problem for me because I'm pretty tense when it use cases correctly in the code. ;-)
Published by: Billy Verreynne, December 19, 2011 06:19
-
How do I know the cursor for loop host variable contains data or not
Hi all
can someone tell me how to know cursor variable host loop for contains data or not.
example:
Start
for curr_rec in (select * from double)
loop
dbms_output.put_line(curr_rec%ROWCOUNT);
end loop;
end;
The following oracle error message is coming:
ORA-06550: line 5, column 27:
PLS-00324: cursor attribute can only be applied to non slider "CURR_REC."
Please help me.
Thank you and best regards,
Prakash P
Published by: 833560 on April 19, 2011 21:57833560 wrote:
Hi allcan someone tell me how to know cursor variable host loop for contains data or not.
example:
Start
for curr_rec in (select * from double)
loopdbms_output.put_line(curr_rec%ROWCOUNT);
end loop;
end;
The following oracle error message is coming:
ORA-06550: line 5, column 27:
PLS-00324: cursor attribute can only be applied to non slider "CURR_REC."Please help me.
Thank you best regards &,.
Prakash PPublished by: 833560 on April 19, 2011 21:57
You know, in your code curr_rec is not slider.
You cannot use curr_rec % rowcount
If you want to get the number of lines of your loop, then use an additional variableTry this please
declare countLoop NUMBER :=0; begin for curr_rec in( select * from dual) loop countloop := countloop + 1; end loop; dbms_output.put_line(countloop); end;
or
DECLARE CURSOR csr_org IS SELECT empno, ename FROM emp; num_total_rows NUMBER; BEGIN FOR idx IN csr_org LOOP dbms_output.put_line(idx.empno||' '||idx.ename); num_total_rows := csr_org%ROWCOUNT; END LOOP; IF num_total_rows > 0 THEN dbms_output.new_line; dbms_output.put_line('Total Organizations = '||to_char(num_total_rows)); END IF; END; /
Published by: Mahir M. Quluzade, April 20, 2011 10:19
-
Insert data from variables in the Ref Cursor
I do not know how to return data from ref cursor variables That's what I've tried so far...
At the end, to achieve this in Ref Cursor:CREATE OR REPLACE type num_obj as object ( t_number number , t_type varchar2(10) , t_desc varchar2(40) ); CREATE OR REPLACE type num_table as table of num_obj; procedure get_all_data(p_p1 in varchar2, p_rc OUT SYS_REFCURSOR) is l_dat1 number := 2; l_dat2 varchar2(10); l_dat3 varchar2(40); t_num_o num_obj; t_num_t num_table; begin for l_indx in 1..5 loop l_dat1 := l_dat1 + l_indx; if ( mod(l_dat1,2)=0) then l_dat2 := 'EVEN'; else l_dat2 := 'ODD'; end if; l_dat3 := 'Number ' || l_dat1 || ' is ' || l_dat2 || ' number'; l_num_o := num_obj (l_dat1, l_dat2, l_dat3); l_num_t := num_table(l_num_o); end loop; open p_rc for select * from table(l_num_t); close p_rc; end;
Can something like that, where I did wrong?t_number | t_type | t_desc --------------------------------------- 3 | ODD | Number 3 is ODD number 5 | ODD | Number 5 is ODD number 8 | EVEN | Number 8 is EVEN number 12 | EVEN | Number 12 is EVEN number 17 | ODD | Number 17 is ODD number
BTW. I did this with the function in pipeline, now I want to try a different method.The refcursor can not be closed in the procedure - you must return refcursor open to the appellant.
the appellant must read and then close it.
There are also some errors in the names of variables and an assignment to the collection.Try this version:
CREATE OR REPLACE PROCEDURE GET_ALL_DATA(P_P1 IN VARCHAR2, P_RC OUT SYS_REFCURSOR) IS l_dat1 number := 2; l_dat2 varchar2(10); L_DAT3 VARCHAR2(40); L_NUM_O NUM_OBJ; l_num_t num_table := num_table() ; BEGIN for l_indx in 1..5 loop l_dat1 := l_dat1 + l_indx; if ( mod(l_dat1,2)=0) then l_dat2 := 'EVEN'; else l_dat2 := 'ODD'; end if; l_dat3 := 'Number ' || l_dat1 || ' is ' || l_dat2 || ' number'; L_NUM_O := NUM_OBJ (L_DAT1, L_DAT2, L_DAT3); L_NUM_T.EXTEND; l_num_t( l_indx ) := l_num_o; end loop; OPEN P_RC FOR SELECT * FROM TABLE(L_NUM_T); END; /
SQL> variable xx refcursor SQL> execute GET_ALL_DATA( '', :xx ); PL/SQL procedure successfully completed. SQL> print :xx T_NUMBER T_TYPE T_DESC ---------- ---------- ---------------------------------------- 3 ODD Number 3 is ODD number 5 ODD Number 5 is ODD number 8 EVEN Number 8 is EVEN number 12 EVEN Number 12 is EVEN number 17 ODD Number 17 is ODD number
-
variable binding can be used for the table in an explicit cursor
I have an application that accesses a table on several different servers. I created a ref for the slider cursor variable and a varchar2 variable to define my query. variable I_server is a parameter to my procedure. Is it possible to rewrite the v_query using bind variable for the table/Server? I have included below v_query.
v_query: = "SELECT rp.usr_id, rp.sun_sft_cat, rp.sun_start, rp.sun_hrs," |
"rp.mon_sft_cat, rp.mon_start, rp.mon_hrs, |
"rp.tue_sft_cat, rp.tue_start, rp.tue_hrs, |
"rp.wed_sft_cat, rp.wed_start, rp.wed_hrs, |
"rp.thu_sft_cat, rp.thu_start, rp.thu_hrs, |
"rp.fri_sft_cat, rp.fri_start, rp.fri_hrs, |
"rp.sat_sft_cat, rp.sat_start, rp.sat_hrs, |
"rp.sun_sft, rp.mon_sft, rp.tue_sft, rp.wed_sft, |
"rp.thu_sft, rp.fri_sft, rp.sat_sft, nvl (ei.wip_permanent_sched_seq, 0) ' |
'FROM ' | I_server | "rp, wip_emp_information ei, |
'wes, wip_emp_status_type West wip_emp_status' |
"WHERE rp.usr_id = ei.employee_id' |"
"AND wes.employee_id = ei.employee_id' |"
"AND wes.status_type = west.status_type' |"
"AND west.description =" STOREKEEPER "' |"
"AND wes.effective_date = (SELECT MAX (wes2.effective_date)' |)"
"OF wip_emp_status EMTE.2 |
"WHERE wes2.status_type = wes.status_type' |"
"AND wes2.employee_id = wes.employee_id' |"
(' AND wes2.effective_date < = trunc (SYSDATE))' |
"AND wes.status = rp.wk AND"Y"= 1'; -wk = 1 is the schedule for next week
Rp_sched_cursor OPEN FOR v_query;If your intention is to do this:
v_query := 'SELECT rp.usr_id, rp.sun_sft_cat, rp.sun_start, rp.sun_hrs,' || ' rp.mon_sft_cat, rp.mon_start, rp.mon_hrs,' || ' rp.tue_sft_cat, rp.tue_start, rp.tue_hrs,' || ' rp.wed_sft_cat, rp.wed_start, rp.wed_hrs,' || ' rp.thu_sft_cat, rp.thu_start, rp.thu_hrs,' || ' rp.fri_sft_cat, rp.fri_start, rp.fri_hrs,' || ' rp.sat_sft_cat, rp.sat_start, rp.sat_hrs,' || ' rp.sun_sft, rp.mon_sft, rp.tue_sft, rp.wed_sft,' || ' rp.thu_sft, rp.fri_sft, rp.sat_sft, nvl(ei.wip_permanent_sched_seq, 0)' || ' FROM ' || :b0 || ' rp, wip_emp_information ei,' || --- Note the bindvariable... ' wip_emp_status wes, wip_emp_status_type west ' || ' WHERE rp.usr_id = ei.employee_id' || ' AND wes.employee_id = ei.employee_id' || ' AND wes.status_type = west.status_type' || ' AND west.description = ''WAREHOUSE EMPLOYEE''' || ' AND wes.effective_date = (SELECT MAX(wes2.effective_date)' || ' FROM wip_emp_status wes2' || ' WHERE wes2.status_type = wes.status_type' || ' AND wes2.employee_id = wes.employee_id' || ' AND wes2.effective_date <= trunc(SYSDATE))' || ' AND wes.status = ''Y'' AND rp.wk = 1'; -- wk = 1 is next week's schedule OPEN rp_sched_cursor FOR v_query USING i_server;
So the answer is: no, you can do that.
But then, my question would be: why would you do that?
I guess that you have many "different servers. A cursor on the server will not hurt you. -
Hey Experts,.
Can we consider cursor for loop as an example of cursor name
as
CREATE or REPLACE function TotalIncome (name_in IN varchar2) RETURN varchar2 IS total_val number (6); cursor c1 is SELECT monthly_income FROM Employees WHERE name = name_in; BEGIN total_val: = 0; FOR employee_rec in c1 LOOP total_val: = total_val + employee_rec.monthly_income; END LOOP; RETURN total_val; END; In this example, we have created
SShubhangi wrote:
Can we consider cursor for loop as an example of cursor name
Laughing out loud
Your code example explicitly sets a CURSOR variable in the PL/SQL block. Implied things happening opens, fetch and closing the cursor. But that the cursor is declared (in the DECLARE section), it's an explicit cursor - like the whole code block now has a way explicit to reference this slider.
An approach of implicit cursor would be as follows:
begin for c in(select col1, col2 from table1) loop .. do something.. end loop; end;
As you can see - there is no declaration of a cursor variable. A reference implementation is created instead and are accessible only within the construction that creates this reference - that is FOR loop in this case. The rest of the BEGIN... END block cannot refer to this cursor.
Do not forget the advice of other posters however. In PL/SQL cursor loops is often the WRONG approach to the treatment of data - as it deals with processing (using the PL/SQL) line and not much treatment faster and scalable set of data using SQL only.
-
How to extract Ref output cursor of procedure
Hi all
When I try to print the result of a procedure that returns a Ref Cursor, I get the below error.
Any help would be much appreciated.Version details --------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production PL/SQL Release 11.2.0.2.0 - Production "CORE 11.2.0.2.0 Production" TNS for Solaris: Version 11.2.0.2.0 - Production NLSRTL Version 11.2.0.2.0 - Production
DECLARE P_APLCTN_SID NUMBER; P_PRVDR_ID VARCHAR2(20); P_BPW_PRCS_TRN_SID NUMBER; P_MODE VARCHAR2(32767); P_PRVDR_DETAILS PK_PRVDR_FULL_SCRNG.REF_GENERIC; P_PRVDR_ADDRESS PK_PRVDR_FULL_SCRNG.REF_GENERIC; P_TAXONOMY_INFO PK_PRVDR_FULL_SCRNG.REF_GENERIC; P_LICENSE_INFO PK_PRVDR_FULL_SCRNG.REF_GENERIC; P_OWNER_INFO PK_PRVDR_FULL_SCRNG.REF_GENERIC; P_SPCLTY_INFO PK_PRVDR_FULL_SCRNG.REF_GENERIC; P_ERR_CODE VARCHAR2(32767); P_ERR_MSG VARCHAR2(32767); BEGIN P_APLCTN_SID := NULL; P_PRVDR_ID := 2247117; P_BPW_PRCS_TRN_SID := 75211306; P_MODE := 'P'; -- P_PRVDR_DETAILS := NULL; Modify the code to initialize this parameter -- P_PRVDR_ADDRESS := NULL; Modify the code to initialize this parameter -- P_TAXONOMY_INFO := NULL; Modify the code to initialize this parameter -- P_LICENSE_INFO := NULL; Modify the code to initialize this parameter -- P_OWNER_INFO := NULL; Modify the code to initialize this parameter -- P_SPCLTY_INFO := NULL; Modify the code to initialize this parameter P_ERR_CODE := NULL; P_ERR_MSG := NULL; PK_PRVDR_FULL_SCRNG.PR_MAIN ( P_APLCTN_SID, P_PRVDR_ID, P_BPW_PRCS_TRN_SID, P_MODE, P_PRVDR_DETAILS, P_PRVDR_ADDRESS, P_TAXONOMY_INFO, P_LICENSE_INFO, P_OWNER_INFO, P_SPCLTY_INFO, P_ERR_CODE, P_ERR_MSG ); DBMS_OUTPUT.PUT_LINE('P_ERR_CODE ='||P_ERR_CODE); DBMS_OUTPUT.PUT_LINE('P_ERR_MSG ='||P_ERR_MSG); FOR I IN P_PRVDR_DETAILS LOOP dbms_output.put_line('Printing Result'); END LOOP; -- COMMIT; END; Error report: ORA-06550: line 33, column 12: PLS-00221: 'P_PRVDR_DETAILS' is not a procedure or is undefined ORA-06550: line 33, column 3: PL/SQL: Statement ignored 06550. 00000 - "line %s, column %s:\n%s" *Cause: Usually a PL/SQL compilation error. *Action:
Prakash wrote:
I do not use these ref Cursor directly in plsql, I only returns ref cursor in Java result.
For some scenarios of the result set is empty, I can't test it on my side.A cursor DBMS_SQL is PL/SQL, what a Ref cursor is Java. So you can test ref Cursor created for Java, by converting it to a cursor DBMS_SQL , describing the projection (see which columns and types are returned) and then get out of the slider.
You can also use SQL * more. Create a host (bind) ref cursor variable in SQL * Plus, the use of SQL * more to make the call as your code Java would do and then use the SQL * Plus PRINT command to get out of the slider.
-
by passing the variable char in the sliders
HI I try to move the tank for the cursor variable, but it is not taking, if I hardcode the values of the slider that he takes
Here's detailed... any body can say why it is not taken and tell me how to pass the values through it...
declare
v_Name tank (6);
cursor c1 (c_name tank) is
Select name, parent, child, relationship status
First name = '% '.
Connect prior parent child =
Union
Select name, parent, child, relationship status
First name = '% '.
connect by prior child = parent
order by 2;
v_c1 c1% rowtype;
Start
v_Name: = ('A');
Open c1 (v_name); - here the value of v_name does not... If like hard-code open c1('c'); then work... I need to pass - value not hardcode
Fetch c1 in v_c1;
dbms_output.put_line (v_Name);
dbms_output.put_line (' name ' |' parent ' |' child ' | ' status "");
While c1%
loop
dbms_output.put_line (v_c1.name |) » '|| v_c1.parent | | » '|| v_c1. Child | | » '|| v_c1. Status);
Fetch c1 in v_c1;
end loop;
Close c1;
enTry it with a varchar2 variable (6)
declare v_name varchar2(6) ; cursor c1(c_name varchar2) is select name, parent,child,status from relation start with name='%' connect by prior parent=child union select name, parent, child , status from relation start with name='%' connect by prior child=parent order by 2; v_c1 c1%rowtype; begin v_name :=('A'); open c1(v_name);---Here the v_name value is not taking.. if hardcode like open c1('c') ; then working.. i need to pass -- value not hardcode fetch c1 into v_c1; dbms_output.put_line(v_name); dbms_output.put_line('name '||'parent '||'child '||'status '); while c1%found loop dbms_output.put_line(v_c1.name||' '||v_c1.parent||' '|| v_c1.child||' '||v_c1.status); fetch c1 into v_c1; end loop; close c1; end
-
I will execute bind_test.sql with the following parameters to sql-plus. The script runs without error. However, it does not insert a row in the table.
bind_test. 20100912 1 1001 SQL;
bind_test. SQL
----------------------------------------------------------
Set serveroutput on
declare
X VARCHAR2 (31);
NUMBER OF Y;
NUMBER OF Z;
Start
dbms_output. Enable (10000);
X: = "& 1";
Y: = & 2;
Z: = & 3;
Insert in the test
values (TO_DATE (X, 'YYYYMMDD'), Y, Z, null, null, null);
commit;
dbms_output.put_line ('var1 = "|") X | "var2 =" | THERE | "var3 = ' |" (Z);
end;
/
----------------------------------
Output:
10 old: X: = "& 1";
10 new: X: = '20100912';
old 11: Y: = & 2;
11 new: Y: = 1;
12 old: Z: = & 3;
12 News: Z: = 1001;
var1 = 20100912 var2 = 1 var3 = 1001
PL/SQL procedure successfully completed.
---------------------------------------
Select * from test;
no selected line
Why it is not insert a line? What could be the reason?
Thanks in advance.
Amituser5922214 wrote:
I have a big script with multiple INSERT and DELETE statements. I have been asked by DBA to use bind variables rather than direct assignment parameter values in which the condition.
Impossible.
Use of variable bind from a client means:
(1) customer create a unique SQL cursor with bind variable, for example INSERT INTO FOOTABLE VALUES (: 1,: 2: 3)
(2) customer from a loop of data read
2.1) reading the customer data (from file, network, device, whatever)
customer liaison variables 2.2) cursor (assigning values to 1 to 3 SQL cursor variables)
2.3) client running the cursor
line insertions 2.4) database
loop repetitions of 2.5) client for all data
(3) customer closed the SQL cursorThis can be done using a SQL script - as a SQL script is not a loop where a single insertion cursor is used. It's a unique script with 100 or 1000 of SQL insert statements. Where each insert statement will result in a cursor SQL must be created.
SQL * also does not support the approach of customer liaison above variable. It is a command line interface very PRIMITIVE and unsuitable for running scripts from loading/data entry.
In your case - the right approach would be to have the data into a CSV file, and then load this file using SQL * Loader... where this software will use customer approach above (in fact he still does better because it uses in bulk link and link not row as described above).
Maybe you are looking for
-
Redirect mail some contacts so that they find themselves in a different Inbox I have
Hello! I represent a couple of different companies and I have 7 inboxes. The problem is that some of the executives of these companies contact me via my standard workmail instead of the certain Inbox set we have for them. So I want to be able to redi
-
Pavilion 15-n270sa: need to for my Pavilion 15-n270sa sm bus drivers
I'll try to find the drivers for SM Bus controller and the PCi drivers can someone help
-
Synaptics Touchpad of my laptop HP Pavilion 15 does not
My touchpad driver works today afternoon. It was working perfectly and suddenly he stopped and I have recently (last week) bought it. I've uninstalled and reinstalled the driver but its still does not. Please help me... Also, please note my details f
-
KB952069 microsoft xp service Pack 3 security
in windows update security sets the dates have not completely downloaded what I can do? xp SP 3 security
-
HP-15 af008ax: ram upgrade
Hello hp, I need help, I am about to buy a laptop the hp15 af008ax and a 4 GB ram hynix that I wanted to ask you that it will be compact able with the computer laptop or shoul I buy another? Please answer quickly