SQL & PL/SQL :: How To Select From Nested Collection In A Ref Cursor

Aug 19, 2010

I've create two types:

create or replace type VAL_REC as object
(WAARDE number(20,5) ) ;

create or replace type VAL_TAB is VARRAY(200) of VALREC ;

create or replace type WSN_REC as object
( START_DATE date
, END_DATE date
, DATA VAL_TAB) ;

create or replace type WSN_TAB as table of WSN_REC ;

In a PL/SQL table collecton WSN_TAB is filled. Now I want to create a query (ref cursor) that gives the result:

START_DATE END_DATE WAARDE(1) WAARDE(2) WAARDE(3) etc.
2010-08-15 2010-08-16 20 20 40
2010-08-16 2010-08-17 23 45 40

View 16 Replies


ADVERTISEMENT

SQL & PL/SQL :: Sorting Collection In Nested Table

Sep 11, 2012

I'm trying to sort a collection in a nested table in PL/SQL so these value can be used later for a display and for export to Excel. The sort is failing.

-- PLS-00642: local collection not allowed in SQL statements

-- PL/SQl: ORA-00902: invalid datatype

The error message are also noted below in the code on the line that fails.

A quick overview of this code- Using a nested table MyNestedTable the values from several select queries are combined into MyRecordsetZero using CURSOR, and MULTISET UNION. I'm trying to either sort MyRecordsetZero or populate MyRecordsetSorted with the sorted values for futher use.

IMPORTANT: The code is running in an enviroment that does not have permission to create.

Versions:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Developer: 8.0.0.1480

DECLARE
-- Declare the variable MyTID to be used by select statements and
-- set its data type and max character count
MyTID varchar2(10);
[code]....

View 13 Replies View Related

SQL & PL/SQL :: Sorting Nested Table / Collection

Nov 10, 2011

In test.pks file I declared the following type

TYPE tab_tests is table of NUMBER(15);

In test.pkb, I have the following procedure

PROCEDURE report (
i_cid IN NUMBER
)
IS
test1 tab_tests := tab_tests();
test2 tab_tests;
BEGIN

-- I populate test1 with the data and it works fine. But when I tried to make a sorted nested table with the following command.

I got this error 'ORA-00902: invalid datatype',

a nested table than the following, like a built in Oracle collection method?

execute immediate 'select cast( multiset (select * from table(test1) order by 1) as tab_tests) INTO test2 FROM dual';
END;

View 16 Replies View Related

PL/SQL :: Referencing Element In Nested Collection

Jun 27, 2013

I have a table called dept table with nested collection as below. Nested Table Collection:

create or replace
type courselist as table of varchar2(64) Table Using Nested Table Collection: 
CREATE TABLE "FCSDWH_STG"."DEPT"
   ( "NAME" VARCHAR2(20 BYTE),
  "DIRECTOR" VARCHAR2(20 BYTE),
  "OFFICE" VARCHAR2(20 BYTE),
  "COURSES" "FCSDWH_STG"."COURSELIST"
   )  Content Of Table:NameDirectorofficecoursesAccountingJames CharlesUNOFCSDWH_STG.COURSELIST('natural science','chemistry','Computer Science','Computer Science') 

I am trying to select and print an element from nested table collection using below plsql block.

MY_COURSE VARCHAR2(64 CHAR);
BEGIN
SELECT courses INTO MY_COURSE FROM TABLE(SELECT COURSES FROM DEPT) where courses='chemistry';
DBMS_OUTPUT.PUT_LINE(MY_COURSE);
END; Error Message:
PL/SQL: ORA-00904: "COURSES": invalid identifier

View 3 Replies View Related

SQL & PL/SQL :: Collection Over Cursor?

Jun 30, 2010

What is the advantage of collections over CURSOR? What is the use for collections and when collections is used?

View 1 Replies View Related

SQL & PL/SQL :: Populating Ref Cursor From Collection?

Aug 17, 2011

I have an existing Procedure that uses a ref cursor as a parameter. The procedure currently simply selects data into the ref cursor using an OPEN FOR and then exits.

I have a need to extend the processing of the procedure. This will mean retrieving extra columns in the select and also removing some of the retrieved records.

I have the constraint that the definition of the REF CURSOR (which is based on a record type as follows) cannot be modified.

TYPE t_charge
IS
RECORD (
id number,
date_from invoice_detail.from_date%TYPE,
date_to invoice_detail.to_date%TYPE,
description invoice_detail.desc_text%TYPE,
amount invoice_detail.amount%TYPE
);
TYPE t_charge_cursor IS REF CURSOR RETURN t_charge;

The procedure does this

PROCEDURE get_bill_lines (
p_bill_id IN NUMBER,
bill_lines_list OUT t_charge_cursor )
IS
OPEN bill_lines_list FOR
SELECT id, from_date, to_date, desc_text, amount
from invoice_table
where id = p_bill_id;

I am thinking instead of selecting directly into the bill_lines_list parameter I will use a local REF CURSOR to select into a COLLECTION. I can then do some work on the collection, similar to below:

PROCEDURE get_bill_lines (
p_bill_id IN NUMBER,
bill_lines_list OUT t_charge_cursor )
TYPE t_local_charge
IS
RECORD (

[code].....

This all works fine, but the question is, how do I then put the collection into the bill_lines_list REF CURSOR where the '*** HERE ***' comment is so I can send the existing REF CURSOR structure back? (Remember I cannot change any definition that is referenced externally)

View 4 Replies View Related

PL/SQL :: Using Collection As Input For Cursor?

Oct 29, 2013

In PL/Sql, I create a new collection using TYPE. Then populate it with BULK COLLECT.The next step I need is to load data from the collection to pass as WHERE condition to a ref cursor.How I can do this?Every test I did fais. It seems to me that I cannot use some kind of SELECT to retrieve all data from the collection, but I might use a cursor to read row by row. (I'm on Oracle 11gR2 DB )

View 3 Replies View Related

SQL & PL/SQL :: Getting For Nested Cursor

Mar 1, 2012

DROP TABLE BatchEnrollment;
CREATE TABLE BatchEnrollment (
servicepointid VARCHAR(100),
curtailprogramid VARCHAR(100)
)

[Code]....

------------

Question I am getting error.

View 2 Replies View Related

PL/SQL :: Open Ref Cursor Using Collection As Bind Variable

Feb 26, 2013

Is it possible to bind collection while opening a ref cursor. Find below the code that I am trying. My goal is to open cursor once using collection variable. Can it be done using DBMS_SQL ?

DECLARE
TYPE typ_emp_rec_in IS RECORD
(
deptno NUMBER,
sal NUMBER
[code]......

View 4 Replies View Related

ODP.NET :: Nested Cursor From Stored Procedure

Jul 31, 2012

I'm trying to fetch data from Ref Cursor OUT parameter filling by stored procedure. Using latest version of ODP.NET provider (11.2.0.3.0).

My stored procedure:

TYPE cursor_type IS REF CURSOR;

PROCEDURE test_proc (p_recordset out cursor_type) AS
BEGIN
OPEN p_recordset FOR
SELECT 1,2, CURSOR (SELECT 3,4 FROM dual)
FROM dual
END;
END test_proc;

If i'm removing "*CURSOR (SELECT 3,4 FROM dual)*" from the procedure, all works just fine. But when the nested cursor exists in procedure, i'm getting the following exception:

System.NullReferenceException occurred
Message=Object reference not set to an instance of an object.
Source=Oracle.DataAccess
StackTrace:
at Oracle.DataAccess.Client.OracleDataReader.GetOraDbTypeEx(Int32 i)
[code]........

My c# code:

using (OracleConnection conn = new OracleConnection(connString))
*{*
OracleCommand command = new OracleCommand();
command.Connection = conn;
command.CommandType = System.Data.CommandType.StoredProcedure;
command.CommandText = "test_proc";
[code].......

If i'm changing procedure signature from out parameter, to return value, code throws the same exception.

View 4 Replies View Related

SQL & PL/SQL :: Error In Reading Data From Collection Variable For Ref Cursor

Jun 19, 2013

While reading data from collection variable using ref cursor . I am getting the below two errors.

PLS-00382:Expression is of wrong type
ORA-22905 Cannot access rows from a non-nested table item.

CREATE OR REPLACE PACKAGE APPS_GLOBAL.GIIOMEGAORDERLIST
AS
TYPE BU_LIST_TYPE IS TABLE OF VARCHAR(50);
TYPE OFFER_DETAIL IS RECORD
(
GII_BU VARCHAR(50),
GII_OFFER NUMBER,
[code]........

View 4 Replies View Related

SQL & PL/SQL :: How To Loop Through Nested Cursors Based On Value From 1st Cursor

Jul 21, 2011

I loop through the 1st cursor (account_csr), while in the 1st csr loop, based on some conditions being true, I want to loop through a 2nd cursor (acctper_csr) but I only want to retrieve data/rows in the 2nd cursor where the account_id column in 1st cursor = account_id column in the 2nd cursor. This will enable me to pull all the account_periods for each account I loop through in the first cursor.

I have attempted several different ways and cannot make this work. Thought I could somehow define a variable and store the account_id from 1st cursor and use on the 'where' clause in the 2nd cursor definition. Have not been able to make this work successfully.

Following is the sample of my

--First cursor (accounts)
CURSOR account_csr is
SELECT *
FROM s_dev_xref1.account A
WHERE a.source = 1

[Code]...

View 7 Replies View Related

SQL & PL/SQL :: Use Collection In Select Statement As Table?

May 26, 2011

i'm trying to use a collection in a select statement as a table, but i've got an error which i don't understand.

This exemple is very simple. I'm trying to validate the solution. The object will contain the result of a query from a big table, and i have 4 request to make on it. I don't want to select 4 times the big table to get the result, but i need the whole result to make my requests (intersect, minus and union)

CREATE OR REPLACE
TYPE zy_w AS OBJECT(
CODE_INFORMATIONVARCHAR2(4),

[Code]....

****************
Rapport d'erreur :
ORA-06550: Ligne 12, colonne 3 :
PL/SQL: ORA-00947: nombre de valeurs insuffisant
ORA-06550: Ligne 5, colonne 3 :
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:
%s"
*Cause: Usually a PL/SQL compilation error.
*Action:

View 9 Replies View Related

SQL & PL/SQL :: Use A Select Statement On Collection Table?

Sep 1, 2011

there is a possible to use a select statement on collection table?

View 1 Replies View Related

Insert With Nested Select

Jul 24, 2007

I have here my SQL

-> INSERT into myTable (col1, col2, col3) values(SELECT table_seq.nextval from dual, 'value2', 'value3');

That's not working...

View 8 Replies View Related

Tuning Select With Nested Table?

Feb 18, 2011

I have created table with nested table:

CODECREATE OR REPLACE TYPE ADDR_T AS OBJECT (
ADDR1 VARCHAR2 (50),
ADDR2 VARCHAR2 (50)
);
CREATE OR REPLACE TYPE t_ADDr AS TABLE OF ADDR_T;

[code]....

I have added some records and created index on ID column. I want to get result of CODEselect id, p.addr1,p.addr2 from nested_table n,table(n.COL1) p where id=1

Explain plan for that is:

CODESELECT STATEMENT  ALL_ROWSCost: 8  Bytes: 231  Cardinality: 3              
4 HASH JOIN  Cost: 8  Bytes: 231  Cardinality: 3          
2 TABLE ACCESS BY INDEX ROWID TABLE SYS.NESTED_TABLE Cost: 2  Bytes: 13  Cardinality: 1      
1 INDEX RANGE SCAN INDEX SYS.FDSFAS Cost: 1  Cardinality: 1  
3 TABLE ACCESS FULL TABLE (NESTED) SYS.COL1_TAB Cost: 5  Bytes: 163,840  Cardinality: 2,560

How to avoid full table scan on nested table? Cardinality is sum of all records in nested column in all rows in main table, why?

View 2 Replies View Related

SQL & PL/SQL :: Can A Nested Select Be Passed As A Parameter

Mar 22, 2010

Is it possible to pass a nested select statement as a parameter to a procedure? In other words, I am currently successfully doing this:

SELECT BASE_PAY INTO N FROM EMPLOYEES WHERE ID=p_ID;
SetPackageValueProc(PkgID,'YearlyBasePay',N);
And I'd like to do something along the lines of this:
SetPackageValueProc(PkgID,'YearlyBasePay',(SELECT BASE_PAY FROM EMPLOYEES WHERE ID=p_ID));

View 21 Replies View Related

SQL & PL/SQL :: Create Nested Query Within Select Of Attributes

Dec 21, 2011

I'm trying to create a sort of nested-query within my select of attributes . i.e.

select A.a,
B.b,
(select count(C.*)
from C
where C. = B.d
group by C.y)
from A a,
B b
where A.d = B.d
and ...

Over-simplifying my query:

select B.desc "Location",
F.desc "Source",
A.amt "Amount",
sum(G.G_CNT) "No. Units",
c.desc "Status"
[code]....

I need to incorporate a count of the number of units from TableG that have a certain status. I tried the following but when I tried to run it, I get an error saying that it's not a Group By expression -the red part is highlighted in TOAD.

select B.desc "Location",
F.desc "Source",
A.amt "Amount",
sum(G.G_CNT) "No. Units",
(select count(*)
from TableG G2
where G2.D_ID = D.ID
and G2.status = 10
group by G2.D_ID)"Count",
c.desc "Status"
[code]....

Any thoughts how I can incorporate a query in my select of attributes?how to Group By something.

View 8 Replies View Related

Performance Tuning :: Nested Select / Instead Of Trigger And Views - No Index Used?

Sep 8, 2009

SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for Solaris: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production

5 rows selected.

I have a problem with views and nested selects which I cannot explain. Here is a trimed down version of the research I have done. notice the following:

1) all code is executed from the same user CDRNORMALCODE. this user has all views and procedural code
2) all data is owned by a different user CDRDATA. This user has no views and no code.

My problem is this:

If I reference the table directly with a delete statement that uses a nested select (i.e. IN clause with select), the index I expect and want is used.But if I execute the same delete but reference even the most simple of views (select * from <table>) instead of the table itself, then a full table scan is done of the table.

Here is an execute against the table directly (owned by cdrdata). Notice the reference to the table in the table schema on line 3. Also please notice INDEX RANGE SCAN BSNSS_CLSS_CASE_RULE_FK1 at the bottom of the plan.

SQL> show user
USER is "CDRNORMALCODE"
SQL>
SQL> explain plan for
2 delete

[code]...

OK, here is an update. The views I am useing normally have instead of triggers on them. If I remove the instead of trigger the problem looks like it goes away, when I put the trigger back the problem comes back.But why would an instead-of-trigger change the query plan for a view?

SQL> DELETE FROM PLAN_TABLE;

5 rows deleted.

SQL> explain plan for
2 delete
3 from BSNSS_CLSS_MNR_CASE_RULE_SV

[code]...

View 10 Replies View Related

SQL & PL/SQL :: Cursor Select Statement?

Apr 28, 2010

I have a cursor in a procedure that selects columns from a table on a remote Oracle database using a database link. It all works fine when the table name and database link name is 'hard coded' into the procedure but what I would like to achieve is have the select statement lookup the table name and database link name from a column in another table. See example below

CURSOR c_total_bookings IS
SELECT personnel_id,
surname,
forenames,
birth_date,

[code]...

What I would like to do is replacecompany_bookings@remote.linkwith a variable that takes its value from another table.

View 1 Replies View Related

SQL & PL/SQL :: SELECT From Within A CURSOR LOOP

Nov 19, 2010

I am not an Oracle programmer but I have been given a task to produce a number of Text files from an Oracle table based on a selection from the table itself.The table consists of many records with a currency code and I need to extract the data into named files based on the currency code.My first idea was to use Cursors and try a select statement matching on the returned value of the cursor but no Joy I can't make it work - perhaps I need to take a new approach.

Current / latest attempt below

DECLARE
CURSOR tmp_splitter_cur IS
SELECT DISTINCT end_consumer_country
FROM tmp_splitter
WHERE 1 = 1;
currency_rec tmp_splitter_cur%ROWTYPE;
[code]....

View 6 Replies View Related

SQL & PL/SQL :: Make Cursor To Take Select Statement?

Jul 9, 2012

How to make cursor to take a select statement

then check the rowcount

in certain case: assign another selete statement to the cursor

View 3 Replies View Related

Forms :: Select Not Fetching Data Within A Cursor

Feb 8, 2011

SELECT
contgrp_num,
cpgrp_desc,
strategy_id,
perftyp_cd,
stiertyp_id_calcbase,
stiertyp_id,
cpgrp_flg_aggr,
pgrptyp_cd

[Code]..

The above query is not returning any value. But, when I put this within a begin-end block, its fetching data.

why its not returning any data without the begin-end block.

The entire code has an outer begin-end block within which the cursor is also defined.

View 1 Replies View Related

Performance Tuning :: Cursor Embedded In Select

Jul 21, 2010

I've been examining som old queries in an existing db due to more and more problems regarding performance. The sql is used as backend for a java/jboss web application with the possibility for users to enter data. With more and more data, there starting to come complaints about the performance.

I stumbled upon a select query with an embedded cursor similar to this :

select id, name ...,
cursor(select id, sequence.... from table2),
cursor(select id, name.... from table3)
from table1
join table4 on (table1.id = table4.id)
where .....

The javacode is a prepared statement with the actual sql as a string and the content of the cursors saved in conjunction with each row.

when i use sqldeveloper to show the explain plan without the cursors, the cost is 2428
when i use sqldeveloper to show the explain plan with just 1 of the cursors, the cost is ~165000

Is there a better way to do this instead of cursors ?

View 2 Replies View Related

SQL & PL/SQL :: Insert Into Select Or Cursor For 100k Rows

Jan 22, 2012

I am trying to insert 100K rows, I have written this proc using cursor. But it is saying anonymous block completed, and no rows are inserted. If I just run the select it returns the rows.Could if just insert into select would be fine or should I use cursor.

CREATE OR replace PROCEDURE Insert_data (l_from_date IN VARCHAR2,
l_to_date IN VARCHAR2)
IS
lc_err_msg VARCHAR2 (2000);
ln_count NUMBER := 0;
CURSOR ins_d IS
SELECT a.col1 AS url,
b.col1 AS ref_url,
COUNT (*) AS total_views
[code]....

View 5 Replies View Related

SQL & PL/SQL :: Cursor Select For Update / Multiple Columns Of Different Tables

Apr 8, 2010

i have two tables test1 and test2. i want to update the column(DEPT_DSCR) of both the tables TEST1 and TEST2 using select for update and current of...using cursor.

I have a code written as follows :

DECLARE
v_mydept1 TEST1.DEPT_CD%TYPE;
v_mydept2 TEST2.DEPT_CD%TYPE;
CURSOR C1 IS SELECT TEST1.DEPT_CD,TEST2.DEPT_CD FROM TEST1,TEST2 WHERE TEST1.DEPT_CD = TEST2.DEPT_CD AND TEST1.DEPT_CD = 'AA' FOR UPDATE OF TEST1.DEPT_DSCR,TEST2.DEPT_DSCR;
[code].......

The above code when run says that it runs successfully. But it does not updates the desired columns[DEPT_DSCR].

It only works when we want to update single or multiple columns of same table...i.e. by providing these columns after "FOR UPDATE OF"
I am not sure what is the exact problem when we want to update multiple columns of different tables.

View 5 Replies View Related

SQL & PL/SQL :: PLS-00402 - Alias Required In SELECT List Of Cursor To Avoid Duplicate Column

Oct 25, 2013

I am getting [Error] PLS-00402 (182: 1): PLS-00402: alias required in SELECT list of cursor to avoid duplicate column names error in my SP.I have created alias for each column and still i am getting the error.

for my_rec_lot in
(SELECT LLP.BOOK_VALUE LLP_BOOK_VALUE,LLP.COMMISSION LLP_COMMISSION,LLP.CURRENCY LLP_CURRENCY,LLP.EXCHANGE_RATE LLP_EXCHANGE_RATE,LLP.EXPENSES LLP_EXPENSES,

[Code].....

View 6 Replies View Related

PL/SQL :: Related Collection Within A Collection

Sep 20, 2012

There is a nested table with in a nested table type and i want to print the value and again assign a new value to the next subscript and i have tried a lot but couldn't find any solution.

declare
type type_name is table of varchar2(10);
type type_name1 is table of type_name;
names type_name1:=type_name1(type_name('hello'));
begin
-----HOW TO PRINT A VALUE--------
-----HOW TO ASSIGN A NEW VALUE TO NEW SUBSCRIPT
null;
end;

1) need to print the values of names(1)
2)Assign a value to names(2)

View 3 Replies View Related

PL/SQL :: How To Create One-column Collection From Another Multi-column Collection

Mar 22, 2013

I am describing a SQL statement to get it's column list:DECLARE

cur     NUMBER;
col_cnt INTEGER;
rec_tab DBMS_SQL.DESC_TAB;

[Code]....

Now I need to get out the columns list from rec_tab.col_name and put it to my_colls collection. Have Oracle any build-in to do that?

View 4 Replies View Related

Precompilers, OCI & OCCI :: Pro*C - Cursor Leak With Cursor Array

Sep 7, 2007

I'm dealing with an ORA-1000 error in a Pro*C application where all the cursors are correctly closed (or so it seems to me).

Here is the code for a simple program which reproduces the problem:

Each cursor is opened in a PL/SQL package:

CREATE OR REPLACE PACKAGE emp_demo_pkg AS
TYPE emp_cur_type IS REF CURSOR;
PROCEDURE open_cur(curs IN OUT emp_cur_type, dept_num IN NUMBER);
END emp_demo_pkg;

[Code]....

While testing the initialization parameter open_cursors is set to 50.

It's my understanding that Oracle doesn't close the cursors until it needs the space for another cursor, which in my test case seems to happen when I enter a value of 50 or bigger for "number of loops". To see how oracle is reusing the cursors, while the test program is running I run SQL*Plus and query v$sesstat for the session that's running the test with the following sentence:

select name, value
from v$sesstat s, v$statname n
where s.statistic# = n.statistic#
and sid = 7
and name like '%cursor%';

Even before I enter a value for number of loops I can see that the session opened 4 cursors and closed 2 of them:

NAME VALUE
---------------------------------------------------------------- ----------
opened cursors cumulative 4
opened cursors current 2

Entering a value of 5 for number of loops yields

NAME VALUE
---------------------------------------------------------------- ----------
opened cursors cumulative 11 <----- 7+
opened cursors current 8 <----- 6+

With a value of 30

NAME VALUE
---------------------------------------------------------------- ----------
opened cursors cumulative 36 <----- 25+ (apparently, Oracle reused at least 5 cursors)
opened cursors current 33 <----- 25+

With a value of 47

NAME VALUE
---------------------------------------------------------------- ----------
opened cursors cumulative 53 <----- 17+
opened cursors current 50 <----- 17+

Now I reached the upper limit set by the initialization parameter open_cursors.

Entering a value of 48, I get the ORA-1000 error.

ORA-01000: maximum open cursors exceeded
ORA-06512: at "SCOTT.EMP_DEMO

Since I open and close the cursor in the same loop iteration, I expect to find in every iterarion 1 explicit cursor and a number of implicit cursors (the PL/SQL call along with the so-called recursive cursors), but I don't expect the sum of all of them to be greater than 50. If my understanding is correct Oracle should be reusing the 50 cursors previously marked as "closeable", not raising the ORA-1000 error.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved