473,385 Members | 1,983 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 18246
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.