472,354 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

Declaring a cursor ROWTYPE%

11
Hi all,

I need to fetch data from two tables into a cursor(Using inner Join), and i want to declare a ROWTYPE variable for this cursor.

Pls Guide. Its urgent.

thanks in advance
Jun 15 '07 #1
8 18100
debasisdas
8,127 Expert 4TB
Can you please post what/how you have tried to solve it.
Jun 15 '07 #2
Ora
11
Can you please post what/how you have tried to solve it.
CREATE or REPLACE PROCEDURE SIDS
AS
blocking_rec gv$lock%ROWTYPE;
CURSOR blocking_sid_cursor
IS
SELECT * FROM gv$lock a, gv$lock b
WHERE (a.block <>0 AND b.request > 0 AND a.id1 = b.id1 AND a.id2 = b.id2);

BEGIN
OPEN blocking_sid_cursor;
LOOP
FETCH blocking_sid_cursor INTO blocking_rec;
EXIT WHEN blocking_sid_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('SID is : ' || blocking_rec.SID);
END LOOP;
CLOSE blocking_sid_cursor;
END SIDS;

This is the error I am getting.
SQL> show error
Errors for PROCEDURE SIDS:

LINE/COL ERROR
-------- -----------------------------------------------------------------
13/1 PLS-00394: wrong number of values in the INTO list of a FETCH
statement

13/1 PL/SQL: SQL Statement ignored
SQL>




Pls Help Me
Jun 15 '07 #3
debasisdas
8,127 Expert 4TB
please use this in the declareation block

Expand|Select|Wrap|Line Numbers
  1. blocking_rec blocking_sid_cursor%ROWTYPE;
  2.  
Jun 15 '07 #4
debasisdas
8,127 Expert 4TB
Try running this code
====================

[code]
CREATE or REPLACE PROCEDURE SIDS
AS
CURSOR blocking_sid_cursor IS SELECT a.* FROM gv$lock a, gv$lock b WHERE (a.block <>0 AND b.request > 0 AND a.id1 = b.id1 AND a.id2 = b.id2);
blocking_rec blocking_sid_cursor%ROWTYPE;
BEGIN
OPEN blocking_sid_cursor;
LOOP
FETCH blocking_sid_cursor INTO blocking_rec;
EXIT WHEN blocking_sid_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('SID is : ' || blocking_rec.SID);
END LOOP;
CLOSE blocking_sid_cursor;
END SIDS;
[/code}

Hope that solves your problem.

Note :--You are not supposed to manipulate with this system table unless you are aware of possible danger or you are a DBA.
Jun 15 '07 #5
Ora
11
Try running this code
====================

[code]
CREATE or REPLACE PROCEDURE SIDS
AS
CURSOR blocking_sid_cursor IS SELECT a.* FROM gv$lock a, gv$lock b WHERE (a.block <>0 AND b.request > 0 AND a.id1 = b.id1 AND a.id2 = b.id2);
blocking_rec blocking_sid_cursor%ROWTYPE;
BEGIN
OPEN blocking_sid_cursor;
LOOP
FETCH blocking_sid_cursor INTO blocking_rec;
EXIT WHEN blocking_sid_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('SID is : ' || blocking_rec.SID);
END LOOP;
CLOSE blocking_sid_cursor;
END SIDS;
[/code}

Hope that solves your problem.

Note :--You are not supposed to manipulate with this system table unless you are aware of possible danger or you are a DBA.
SQL> CREATE or REPLACE PROCEDURE SIDS
2 AS
3 blocking_rec blocking_sid_cursor%ROWTYPE;
4 CURSOR blocking_sid_cursor
5 IS
SELECT * FROM gv$lock a, gv$lock b
6 7 WHERE (a.block <>0 AND b.request > 0 AND a.id1 = b.id1 AND a.id2 = b.id2);
8 BEGIN
9 OPEN blocking_sid_cursor;
10 LOOP
11 FETCH blocking_sid_cursor INTO blocking_rec;
12 EXIT WHEN blocking_sid_cursor%NOTFOUND;
13 DBMS_OUTPUT.PUT_LINE('SID is : ' || blocking_rec.SID);
14 END LOOP;
15 CLOSE blocking_sid_cursor;
16 END SIDS;
17 /

Warning: Procedure created with compilation errors.

SQL> show errors
Errors for PROCEDURE SIDS:

LINE/COL ERROR
-------- -----------------------------------------------------------------
3/14 PLS-00320: the declaration of the type of this expression is
incomplete or malformed

3/14 PL/SQL: Item ignored
11/1 PL/SQL: SQL Statement ignored
11/32 PLS-00320: the declaration of the type of this expression is
incomplete or malformed

13/1 PL/SQL: Statement ignored
13/37 PLS-00320: the declaration of the type of this expression is
incomplete or malformed

LINE/COL ERROR
-------- -----------------------------------------------------------------

SQL>

Its Not working . Pls help me
Jun 15 '07 #6
debasisdas
8,127 Expert 4TB
may i know u are executing the code in which schema ???
Jun 15 '07 #7
Ora
11
may i know u are executing the code in which schema ???
Hey Debasis its working now i ran the different code. Ur amazing . Thanks alot.
Jun 15 '07 #8
debasisdas
8,127 Expert 4TB
You are most welcome

feel free to post your queries/doubts here in the forum.
Jun 15 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jim Garrison | last post by:
Oracle has a tech article describing how a Java stored procedure can return a REF CURSOR: http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jdbc/refcur/index.html Here's the...
0
debasisdas
by: debasisdas | last post by:
SAMPLE CODE USING RECORD =========================== declare cursor c1 is select * from dept; type drec is record (a dept.deptno%type, b dept.dname%type, c dept.loc%type); type ttype is...
0
debasisdas
by: debasisdas | last post by:
RESTRICTIONS ON CURSOR VARIABLES ================================= Currently, cursor variables are subject to the following restrictions: Cannot declare cursor variables in a package spec. ...
0
debasisdas
by: debasisdas | last post by:
This thread contains some useful tips/samples regarding some advance concepts in cursors. FEW MORE EXAMPLES =================== declare er emp%rowtype; cursor c1 is select * from emp; begin...
0
debasisdas
by: debasisdas | last post by:
Using FOR LOOP in CURSOR----no need to open and close. ----------------------------------------------------------------------------------------- DECLARE CURSOR DD IS SELECT * FROM EMP WHERE...
0
debasisdas
by: debasisdas | last post by:
Sample example to show FOR UPDATE CURSOR ----------------------------------------------------------------------------- DECLARE CURSOR EMPREC IS SELECT * FROM EMP FOR UPDATE OF SAL; MYREC...
0
debasisdas
by: debasisdas | last post by:
SAMPLE CODE TO SHOW USE OF REFCURSOR ======================================= EXAMPLE #1 ---------------------- declare --declare the fer cursor. type my_ref_cur_typ is ref cursor; --declare...
0
debasisdas
by: debasisdas | last post by:
Cursor Variable Returning %ROWTYPE ----------------------------------------------------------- DECLARE TYPE TmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE; tmp_cv TmpCurTyp;TYPE EmpCurTyp IS REF...
2
by: geebanga88 | last post by:
Hi was wondering if you are allowed to output a group function such as SUM from a cursor. For example: DECLARE cursor customer_total_owing IS SELECT c_first, c_last,...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.