Table of record type in cursor
declare
type r_original is record
(column_name varchar2(30),
column_id number(2),
column_TYPE varchar2(30),
client_spec varchar2(2));
type t_original is table of r_original index by pls_integer;
l_original t_original;
begin
select column_name,column_id,
decode(data_type,'DATE','timestamp','TIMESTAMP(6)','timestamp','NUMBER' ,'int','VARCHAR2','string','string') data_type,
'N' as client_spec bulk collect into l_original
from dba_tab_columns
where table_name = l_s2
and owner = l_s1
order by column_id ;
-----------------this cursor i want to select value from l_original
for rec in ( select data_type FROM l_original)--,column_id, data_type COLUMN_VALUE -
loop
null ;- dbms_output.put_line (rec.column_name || rec.data_type);
END LOOP;
end
DA wrote:
or is there any way to compare two nested tables with out using two loopsWe can use SET operations to compare PL/SQL collections but there is a catch. They only work with simple collections i.e. those which have a single element like this:
type nnt is table of number(8,0);However operations such as MULTISET EXCEPT work with multi-attribute collections such as you've defined. Attempting to do so will hurl PLS-00306.
What you need to do is define SQL Types for the record and the nested table. When you declare the object representing the record you need to include a MAP member function which tells the database how to compare two two instances of that type. Find out more.
Adrian Billington wrote a good introduction to comparing collections. [url http://www.oracle-developer.net/display.php?id=303]Read it here.
Nevertheless, the most efficicient way of filtering records remains the queries we start with.
Cheers, APC
Edited by: APC on Aug 8, 2012 8:09 AM
Similar Messages
-
Can stored function return record type or cursor type?
Hi everybody,
I am working with a stored function now.
Can the function output more that ONE result? i.e. cursor or record type.
Thanks.
Brigitta.Brigitta,
If you are calling the stored function from SQL then the function can only return one of the base datatypes, as Murali has said. However, if you are calling the function from PLSQL you can return any complex datatype, eg:
package test_package is
type rec_test is
( col_a number
, col b varchar2(30) );
type tab_test is
table of rec_test
index by binary ineteger;
function test_function (.....)
return tab_test;
end test_package;and to call this function:
declare
l_table test_package.tab_test;
begin
l_table := test_package.test_function(....);
end;Hope that helps! -
How to use temporarly table wid record type
Hi,
how to use temporarly table wid the record type wid this example
declare
type empcurtyp is ref cursor;
type rectype is record (veid t.emp_id%type, vename t.ename%type);
TYPE tabtype IS TABLE OF rectype;
empcv empcurtyp;
vtab tabtype;
begin
open empcv for select emp_id,ename from t;
loop
fetch empcv into vtab;
exit when empcv%notfound;
dbms_output.put_line(vtab.vename||vtab.veid);
end loop;
close empcv;
end;
here we hav table t and i m taking only two fields of the table t which r emp_id and ename.Try this
declare
type rectype is record (veid t.emp_id%type, vename t.ename%type);
type empcurtyp is ref cursor return rectype;
TYPE tabtype IS TABLE OF rectype;
empcv empcurtyp;
vtab empcv%rowtype;
begin
open empcv for select emp_id,ename from t;
loop
fetch empcv into vtab;
exit when empcv%notfound;
dbms_output.put_line(vtab.vename||vtab.veid);
end loop;
close empcv;
end; -
RESB Table ..Record Type
This is the first time i am using this table.I have noticed that RESB table has a Record type field RSART in its primary key.Can anyone explain me what is the significance of this field and what are the possible values?
I have currently 9368387 records in my RESB table and none has a value for this field.
The docu says that this field is not used in any Dynpro. -
Stored Procedure with in out parameter of table of records type
Hi
I am tring to create a strore procedure inside a package like this:
procedure name_p(root in table.column%type, tab in out table_of_records_type);
I get the error:
PLS-00306: Wrong number or types of arguments in call to 'name_p'
I am working with oracle 8.1.7.
I dont really understand why this is happening.
Can anyone suggest anything.
Thnx
EdAn example :
TEST@db102 SQL> select ename, job from emp
2 where empno = 7902;
ENAME JOB
FORD ANALYST
TEST@db102 SQL> create or replace procedure show_emp (
2 v_empno in number,
3 v_ename out varchar2,
4 v_job out varchar2 )
5 is
6 begin
7 select ename, job into v_ename, v_job
8 from emp
9 where empno = v_empno;
10 end;
TEST@db102 SQL> /
Procedure created.
TEST@db102 SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[ora102 work db102]$ IN=7902
[ora102 work db102]$ set `sqlplus -s test/test@db102 << !
var out1 varchar2(30);
var out2 varchar2(30);
set pages 0
set feed off
exec show_emp($IN,:out1,:out2);
print
exit
`[ora102 work db102]$ echo $1 $2
FORD ANALYST
[ora102 work db102]$ -
Create JPub class for table of records/record types and access them
Hi,
I have the following object types in the database:
PERSON_REC with 3 fields and
PERSON_TAB table of PERSON_REC
I have created a Java class for PERSON_REC using JPub. The created class implements CustomDatum and CustomDatumFactory. How do I do it for table of records type i.e PERSON_TAB??
I have a stored procedure that has PERSON_TAB as a OUT parameter. How do retrieve the value from callablestatement? Is there a sample code anywhere. Kindly direct me.
I have seen sample code and documentation for PERSON_REC type from JPub but not for table of records; also there is no sample code for accessing them from JDBC. Please help me..
Thanks and regards,
Vadi.Vadi,
Try searching this forum's archives for the words "STRUCT" and "ARRAY".
Good Luck,
Avi. -
Hi,
Inside of a stored procedure I created:
- a record type:TYPE gr_rec IS RECORD (contact_id number)
- a table of records: TYPE gr_tb IS table of gr_rec INDEX BY BINARY_INTEGER
and then I populated the table in a loop: tb(i).contact_id := a.contact_id.
My question is:
Is it posible to perform a select statement on the table of records to get only distinct records?
If not, how can I filter these records, as I use the procedure as a block data source in a form and I need only distinct records.
Note: I can not obtain select rows from the query that populates the table.
Thank you, MonicaLook at this function:
create or replace type TYP_REC_EMP as object
EMPNO NUMBER(4),
ENAME VARCHAR2(10),
JOB VARCHAR2(10),
MGR NUMBER(4),
HIREDATE DATE,
SAL NUMBER(7,2),
COMM NUMBER(7,2),
DEPTNO NUMBER(2)
create or replace type TYP_TAB_REC_EMP is table of TYP_REC_EMP
CREATE OR REPLACE FUNCTION Ret_Cur RETURN TYP_TAB_REC_EMP
IS
TAB TYP_TAB_REC_EMP := TYP_TAB_REC_EMP(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
CURSOR C_EMP IS
SELECT *
FROM EMP ;
i PLS_INTEGER := 0 ;
BEGIN
FOR CEMP IN C_EMP LOOP
TAB.extend ;
i := i + 1 ;
TAB(i) := TYP_REC_EMP
CEMP.EMPNO,
CEMP.ENAME,
CEMP.JOB,
CEMP.MGR,
CEMP.HIREDATE,
CEMP.SAL,
CEMP.COMM,
CEMP.DEPTNO
END LOOP ;
RETURN TAB ;
END;
/And the Sql*plus query :
SQL*Plus: Release 9.0.1.3.0 - Production on Ve Mar 24 09:18:37 2006
(c) Copyright 2001 Oracle Corporation. All rights reserved.
Connecté à :
Oracle9i Enterprise Edition Release 9.2.0.5.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.5.0 - Production
SQL>
SQL> SELECT DISTINCT(empno),deptno FROM TABLE(ret_cur()) WHERE deptno=20
2 /
EMPNO DEPTNO
7369 20
7566 20
7788 20
7876 20
7902 20
SQL> Francois -
Block on PL/SQL Table of Record
Hi,
I am using Developer 6 with Oracle 8i, I based my block on PL/SQL procedure returning table of record, the form is running fine, but when ever I try to get data set, more then 200 rows, first it gows for query, working for a moment and then closed the form with out giving any result. And the least possible queryable data is 1000 to 30000.
It is working fine with less then 200 rows.
The form is also working fine with Ref Cursor with any of rows, but what I am doing is only possible with Table of record type.
Please give me your good advise what should I do.
Please accept my thanks in advance.
FahimThis should not happen. If you are not sure that your stored procedure is bug-free, you could generate and use stored procedures using my SQLPlusPlus and give it a try.
You can email me directly if your problem still not gets solved.
regards,
M. Armaghan Saqib
+---------------------------------------------------------------
| 1. SQL PlusPlus => Add power to SQL Plus command line
| 2. SQL Link for XL => Integrate Oracle with XL
| 3. Oracle CBT with sample GL Accounting System
| Download free: http://www.geocities.com/armaghan/
+---------------------------------------------------------------
null -
Say I have the following package:
CREATE OR REPLACE PACKAGE temp_test_pkg IS
TYPE test_type IS RECORD (
num number,
chr varchar2(10));
TYPE test_arr_type IS TABLE OF test_type INDEX BY PLS_INTEGER;
PROCEDURE test_proc(p_tst OUT test_type);
PROCEDURE test_proc2(p_tst OUT test_arr_type);
END temp_test_pkg;And I want to call the test_proc and test_proc2 functions from a Pro*C application. How can I do this? I have not seen any method to pass record types, or even worse tables of record types, in Pro*C and so far the only thing I can think of is to break up the record into individual arguments, which is ugly.
I have looked into the Object Type Translator and I don't think it will work without making changes to the packages since everything will have to be re-typed as object types. I can not do this, so unless OTT will work without changing the types that "solution" is out.All interesting to know, but it all confirms what I thought all along: object types and its associated object cache were designed to manipulate table data not temporary data that was created and passed just to satisfy the temporary need to get data into a Pro*C/C application.
Thanks! But it looks like object types bring with them an amount of overhead that is not going to be suitable for our task. We'd constantly be bringing in the objects, consuming them, and then flushing them out of the cache because we'll be recreating them again next time (in the PL/SQL procedure) and they won't ever be the same. In order for this to change we'd need to redesign the entire thing, and while that is certainly something to keep in mind, for now we don't have the time!
If and when we decide to redesign, I will certainly take all this into consideration!
For my own edification, however, how much faster did you find the OCCI implementation over the Pro*C implementation? We don't use the OCI layer for anything yet, so this would be a first, and so I may have to sell its use.
Thanks!
-- Brian -
Hi All,
I have to show one output in ALV.One of the o/p fields is "Record Type" which has possible entries as 1.Current Stock 2. Safety Stock 3. Process Order 4.Planned Order.
Is there any field in any table for record type with above mentioned possible entries.Even if a field for Order type is there please mention.
Thanks in Advance,
Saket.Hi
Please check this
/BI0/OIRECORDTP Record type
CFRECTY Record type
FE_RRCTY Record type
MAFID Record type
P106_RTYPE Record type
PAR_TIREG Record type
PES_190TIP Record type
PPT_TSREC Record type
RECNO Record type
RECTP_EBES Record type
RSART Record type
SISATZ Record type
VVISATZA Record type -
DB proc - do you need to create a table to pass a ref cursor record type?
I want to pass a limited selection of columns from a large table through a DB procedure using a REF CURSOR, returning a table rowtype:
CREATE OR REPLACE package XXVDF_XPOS_DS021_ITEMS AS
TYPE XXVDF_XPOS_DS021_ITEM_ARRAY
IS REF CURSOR
return XXVDF_XPOS_DS021_ITEM_TABLE%ROWTYPE;
Do I need to create this dummy table?
I can't get a TYPE to work, where the type is an OBJECT with the desired columns in it.
So a dummy empty table will sit in the database...
Is there another way?
thanks!You can use RECORD type declaration:
SQL> declare
2 type rec_type is record (
3 ename emp.ename%type,
4 sal emp.sal%type
5 );
6 type rc is ref cursor return rec_type;
7 rc1 rc;
8 rec1 rec_type;
9 begin
10 open rc1 for select ename, sal from emp;
11 loop
12 fetch rc1 into rec1;
13 exit when rc1%notfound;
14 dbms_output.put_line(rec1.ename || ' ' || rec1.sal);
15 end loop;
16 close rc1;
17 end;
18 /
SMITH 800
ALLEN 1600
WARD 1250
JONES 2975
MARTIN 1250
BLAKE 2850
CLARK 2450
SCOTT 3000
KING 5000
TURNER 1500
ADAMS 1100
JAMES 950
FORD 3000
MILLER 1300or use, for example, VIEW to declare rowtype:
SQL> create view dummy_view as select ename, sal from emp;
View created.
SQL> declare
2 type rc is ref cursor return dummy_view%rowtype;
3 rc1 rc;
4 rec1 dummy_view%rowtype;
5 begin
6 open rc1 for select ename, sal from emp;
7 loop
8 fetch rc1 into rec1;
9 exit when rc1%notfound;
10 dbms_output.put_line(rec1.ename || ' ' || rec1.sal);
11 end loop;
12 close rc1;
13 end;
14 /
SMITH 800
ALLEN 1600
WARD 1250
JONES 2975
MARTIN 1250
BLAKE 2850
CLARK 2450
SCOTT 3000
KING 5000
TURNER 1500
ADAMS 1100
JAMES 950
FORD 3000
MILLER 1300 Rgds. -
Calling Oracle Stored proc with record type and table Type
I have a oracle SP which takes record type and table Type which are used for order management.
Is there anay way to populate parameters with these datatypes and call the stored procedure using ODP.NET?
Please help.
Thanks in advanceHi,
ODP supports associative arrays and REF Cursors. There is no support for PLSQL table of records.
Jenny -
How does a record type and table type works
Hi,
How a record type and table type work for the ref cursor,
below i m giving an example but its giving me errors
can any one help me for this?
declare
type empcurtyp is ref cursor;
type rectype is record (veid t.emp_id%type, vename t.ename%type);
TYPE tabtype IS TABLE OF rectype;
empcv empcurtyp;
vtab tabtype;
begin
open empcv for select emp_id,ename from t;
loop
fetch empcv into vtab;
exit when empcv%notfound;
dbms_output.put_line(vtab.vename||vtab.veid);
end loop;
close empcv;
end;
here we hav table t and i m taking only two fields of the table t which r emp_id and ename.Hi,
What errors are you getting with this? From experience you don't need a loop to put the records into the ref cursor its usually done on block.
HTHS
L :-) -
Using cursor on table of records
I'm trying to use cursors on a passed in table of records and I
get a compilation error on the cursor definition that states
that the table must be defined (but I'm passing the table in).
Here are the types:
create type input_record_t as object (
field1 varchar2(10),
field2 varchar2(20));
create type input_table_t is table of input_record_t;
procedure process_data (
input_data in input_table_t) is
cursor data_cursor is select * from input_data; /* error */
begin
/* processin here */
end;
I've also tried:
cursor data_cursor (data_table in input_table_t) is select
* from data_table; /* also error */
How do I define a cursor on a passed in table of records? Any
help would be appreciated.Same thing I am doing
Its working finr in applications(If i call from VB or ASP I am
getting result set)
I want to see the result set in SQL plus window,How can i call it
SQL > execute packperson.oneperson(1,?);
SQL > execute packperson.oneperson(1);
SQL > execute packperson.oneperson(1,NULL);
Nothing is working
Need help please
Thanks
are you trying to assign records to a plsql table type?
CREATE OR REPLACE PACKAGE packperson
AS
TYPE tfname is TABLE of VARCHAR2(15)
INDEX BY BINARY_INTEGER;
PROCEDURE oneperson
(onessn IN integer,
fname OUT tfname);
END packperson;
CREATE OR REPLACE PACKAGE BODY packperson
AS
PROCEDURE oneperson
( onessn IN integer,
fname OUT tfname)
IS
CURSOR person_cur
IS
SELECT ssn, fname, lname
FROM person
where ssn = onessn;
percount NUMBER DEFAULT 1;
BEGIN
FOR singleperson IN person_cur
LOOP
fname(percount) := singleperson.fname;
percount := percount + 1;
END LOOP;
END;
END; -
How create a record type and a pl/sql table of that record type in database
Hi
I want to create a record type and then I want to create a PL/SQL table in the oracle 9i database.
I have done it in PL/SQL block.
But when I am trying to do it in database it is throwing me some error.
Could you please tell me how can I do that?
Regardsuser576726 wrote:
Hi
I want to create a record type and then I want to create a PL/SQL table in the oracle 9i database.
I have done it in PL/SQL block.
But when I am trying to do it in database it is throwing me some error.
Could you please tell me how can I do that?
RegardsRECORD type is supported only in PL/SQL for SQL you need to use OBJECT type.
Maybe you are looking for
-
I have been having trackpad problems on my macbook pro (bought in 2010) for the past couple of days. Not only does it move erratically by itself, but the left click does not respond as it should. Whenever I use the left click, it works as a right cli
-
Problem Adding Audio to iMovie (Filevault Problem?)
Ok... I made an iMovie project when I returned from a trip. I then turned on Filevault in Lion for full disk encryption (I've been waiting for this feature because I need it for my business). I went back to make some edits in my video... and iMovie
-
In the HR portal,When the user requests for a booking , The Manager Can Approve or Cancel that booking based on the Requirement.But In HR portal,when the manager is logged in, when he opens the booking .it is just showing the Forward and cancel assig
-
Getting specific area of an image
Is there away to display a specific area of an image?i have an image icon that uses a jpeg,but i do not want it to use the whole image for the icon.i know that imagebuffer has the method getsubimage but does imageicon have something similar?How can i
-
There are still batch split items with quantity X for item
Our current system is ECC6. The deletion of item in the delivery (TO confirmed) is different before ECC6 (4.6C). In 4.6, unless quantity of batch split items are zeroed out in the delivery, the item cannot be deleted. Message "There are still batch s