Selecting from a nested table
Hi All,
Is it possible to select * from nested_table_variable;
I want in this format so that I can return the values to to java using refcursor.
Please help me
Ya, something like this --
satyaki>
satyaki>create or replace type pl_hok as object
2 (
3 GrA varchar2(5),
4 GrB varchar2(5)
5 );
6 /
Type created.
satyaki>
satyaki>
satyaki>create or replace type pl_hok_rec as table of pl_hok;
2 /
Type created.
satyaki>
satyaki>
satyaki>create or replace function pipe_sel(
2 st_dt in date,
3 en_dt in date
4 )
5 return pl_hok_rec pipelined
6 is
7 cursor c1
8 is
9 select distinct empno
10 from emp
11 where hiredate between st_dt and en_dt;
12
13 r1 c1%rowtype;
14
15 cursor c2
16 is
17 select distinct mgr
18 from emp
19 where hiredate between st_dt and en_dt;
20
21 r2 c2%rowtype;
22 pragma autonomous_transaction;
23 begin
24 open c1;
25 open c2;
26
27 loop
28 fetch c1 into r1;
29 fetch c2 into r2;
30
31 exit when c1%notfound and c2%notfound;
32 pipe row(pl_hok(to_char(r1.empno),to_char(r2.mgr)));
33 end loop;
34
35 close c2;
36 close c1;
37
38 return;
39 exception
40 when others then
41 dbms_output.put_line(sqlerrm);
42 end;
43 /
Function created.
satyaki>
satyaki>
satyaki>select GrA,GrB from table(pipe_sel(to_date('01-jan-1980','dd-mon-yyyy'),to_date('20-aug-2007','dd-mon-yyyy')));
GROUP GROUP
7006 7369
7369 7566
7499 7698
7521 7782
7566 7788
7654 7839
7698 7902
7782
7788
7839
7844
GROUP GROUP
7876
7900
7902
7934
9898
16 rows selected.
satyaki>Regards.
Satyaki De.
Similar Messages
-
Producing nested xml with querying attributes from a nested table
How can one produce nested xml querying columns from a nested table? Looking at the object documentation, I can readily unnest the tables. Using your examples in the book, unnesting is select po.pono, ..., l.* from purchaseorder_objtab po, table (po.lineitemlist_ntab) l where l.quantity = 2;
what if I don't want to unnest and don't want a cursor. I would like to produce nested xml.Gail,
Although you can use XSU (XML-SQL Util) in 8.1.7, I would recommend that you upgrade to 9i for much better support (both in functionality and performance) of XML in the database. For example, in Oracle9i there are:
- a new datatype - XMLType for storing and retrieving XML documents
- DBMS_XMLGEN package and SYS_XMLGEN, SYS_XMLAGG functions for generating XML document from complex SQL queries
- A pipelined table function to break down large XML documents into rows.
You can check out some examples using SYS_XMLGEN and DBMS_XMLGEN for your specific needs at http://download-west.oracle.com/otndoc/oracle9i/901_doc/appdev.901/a88894/adx05xml.htm#1017141
Regards,
Geoff -
Unable to retrieve data from a nested table in Oracle 8i from JSP
How do i retrieve data from a nested table in Oracle 8i from my JSP code?
When i try to execute the query , a general error is thrown.
Kindly advice as soon as possible.How do i retrieve data from a nested table in Oracle 8i from my JSP code?
When i try to execute the query , a general error is thrown.
Kindly advice as soon as possible. -
How to assign tasks in Approval Workflow to a set of users selected from a Lookup table
Hi all,
I am new to Project Server and I am using Project Server 2013 On premises deployement. Please help me on how to achieve the below scenario:
I have a requirement where, the initial PDP will have 2 fields (Reviewers and Approvers), wherein the engineer himself will select who the reviewer and approver from the Lookup tables.
Now I have to start task process with these selected people for approval.
Say for example , engineer has selected Alice and Bob as 2 reviewers, then
In the workflow I have :
Start Task process with
Project Data: Reviewers (which is giving error as
[System.ArgumentException: AssignedTo at Microsoft.Activities.Hosting.Runtime.Subroutine.SubroutineChild.Execute(CodeActivityContext context) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager
bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation) ]
Then I tried logging the value of Project Data: Reviewers, It logged the value as Alice, Bob (which looks pretty good),
Then I tried assigning only 1 person as Reviewer, then also I get the same error.
So can anybody please tell me where I went wrong. Is it not possible to fetch the data from the values selected as Project Data from the Lookup tables ? If not then what is the workaround I can use to achieve this ?
Thanks,
ShankyHi Paul,
Yes I am using SP designer for Workflows. And yes, You were right, there was a mismatch in the names of AD account and the Lookup table, now with 1 person selected from the lookup table it is assigning the task properly. However with multiple selection,
it is failing.
As Robert mentioned, the fetched value is a text as "Alice, Bob", which makes 2 usernames as a single text. So when I try to assign a task to this group, which returns value as "Alice, Bob", workflow fails to find such AD user, as it
is an invalid value.
So is there any way I can seperate this out to form 2 different username ? I checked for string extraction function in th Workflow, but nothing helped me for this scenario.
Any input will be helpful.
Thanks,
Shanky -
Selecting from 2 different tables
is this possible?
i just want to select from two different tables in one select statement and they have the same WHERE clauseSELECT
a.pkggrp,
a.pkgtype,
a.area,
a.process,
a.ww,
count(a.ww) as LOTSGATED,
sum(a.samplesize) as SUMSAMPLESIZE,
sum(a.total_defects) as SUMTOTALDEFECTS,
sum(case a.auditresult when 'pass' then 1 else 0 end) COUNTPASS,
sum(case a.auditresult when 'fail' then 1 else 0 end) COUNTFAIL,
case sum(case a.auditresult when 'fail' then 1 else 0 end)
when 0 then 0
else round(sum(case a.auditresult when 'fail' then 1 else 0 end) / count(a.ww) * 100,2)
end LRR,
case sum(case a.auditresult when 'fail' then 1 else 0 end)
when 0 then 0
else round(sum(case a.auditresult when 'fail' then 1 else 0 end) / sum(a.samplesize) * 1000000,0)
end PPM,
count(c.itrnum)
FROM
t_prodproc_monitoring a, t_itr c
WHERE
a.ww=c.ww
and a.ww between 1 and 50
and c.ww between 1 and 50
GROUP BY
a.pkggrp,
a.pkgtype,
a.area,
a.process,
a.ww
ORDER BY
a.pkggrp,
a.pkgtype,
a.area,
a.process,
a.ww ascthis gave me a
"c". "ww": invalid identifier -
Hi Guys,
I was just hoping to get your opinion on something.
I have a procedure in Production that is taking longer and longer to finish and sticks on one certain section of code.
The code is an INSERT into the main dimension table.
This same procedure runs fine on TEST and the section of code completes an awful lot quicker.
The traffic on Production is a lot heavier and there have been applications developed by people other than myself which SELECT from this dimension table. I'm assuming, based on the fact the code in Test and Production are identical, that this increased traffic could be eating up the bandwith and slowing the jobs.
So, I was thinking - if I create Views and let the other applications hit the views as opposed to the main table, will this help speed it up. I did this before on a Teradata platform using a 'dirty read' which worked quite well but Oracle doesn't seem to offer this option.
What do you guys think? Could this work or do I need to take a different approach.
Thank You.GerardMcL wrote:
I meant ordinary views.
I was wondering if there was a way of putting some locking code in or asking for a dirty read that would speed up the SELECT from the table?There is no such thing as a dirty read with Oracle -- Teradata, SQL Server, Sybase, IBM, etc., have different locking architectures where reads can block write and writes can block reads, and that is not an issue with Oracle.
If there's a query performance problem, which is what that will be if the SELECTs are slow, then if you could follow the following links, that will help diagnosis immensely:
[How to Post A Tuning Request|http://forums.oracle.com/forums/thread.jspa?threadID=863295&tstart=0]
And:
[When your Query takes too long|http://forums.oracle.com/forums/thread.jspa?messageID=1812597#1812597]
There is such as thing as stale reads, against Materialized Views, which are views that actually materialize and store the results of a query, and which then can subsequently be queried. -
SELECTing from a large table vs small table
I posted a question few months back about teh comparison between INSERTing to a large table vs small table ( fewer number of rows ), in terms of time taken.
The general consensus seemed to be that it would be teh same, except for teh time taken to update the index ( which will be negligible ).
1. But now, following teh same logic, I m confused why SELECTINg from a large table should be more time taking ("expensive" ) than SELECTing from a small table.
( SELECTing using an index )
My understanding of how Oracle works internally is this :
It will first locate the ROWID from teh B-Tree that stores the index.
( This operation is O(log N ) based on B-Tree )
ROWID essentially contains teh file pointer offset of teh location of the data in teh disk.
And Oracle simply reads teh data from teh location it deduced from ROWID.
But then the only variable I see is searching teh B-Tree, which should take O(log N ) time for comparison ( N - number of rows )
Am I correct above.
2. Also I read that tables are partitioned for performance reasons. I read about various partiotion mechanisms. But cannot figure out how it can result in performance improvement.
Can somebody please helpuser597961 wrote:
I posted a question few months back about teh comparison between INSERTing to a large table vs small table ( fewer number of rows ), in terms of time taken.
The general consensus seemed to be that it would be teh same, except for teh time taken to update the index ( which will be negligible ).
1. But now, following teh same logic, I m confused why SELECTINg from a large table should be more time taking ("expensive" ) than SELECTing from a small table.
( SELECTing using an index )
My understanding of how Oracle works internally is this :
It will first locate the ROWID from teh B-Tree that stores the index.
( This operation is O(log N ) based on B-Tree )
ROWID essentially contains teh file pointer offset of teh location of the data in teh disk.
And Oracle simply reads teh data from teh location it deduced from ROWID.
But then the only variable I see is searching teh B-Tree, which should take O(log N ) time for comparison ( N - number of rows )
Am I correct above.
2. Also I read that tables are partitioned for performance reasons. I read about various partiotion mechanisms. But cannot figure out how it can result in performance improvement.
Can somebody please helpIt's not going to be that simple. Before your first step (locate ROWID from index), it will first evaluate various access plans - potentially thousands of them - and choose the one that it thinks will be best. This evaluation will be based on the number of rows it anticipates having to retrieve, whether or not all of the requested data can be retrived from the index alone (without even going to the data segment), etc. etc etc. For each consideration it makes, you start with "all else being equal". Then figure there will be dozens, if not hundreds or thousands of these "all else being equal". Then once the plan is selected and the rubber meets the road, we have to contend with the fact "all else is hardly ever equal". -
No value is select from user define table
Hi ALL,
i am using B1if , i am sending data B1 to isr , i am using user define table but problem no value is select from user define table .
my table ID is @SSRPOD
<payload operation="">
<ns0:MT_POD_B1_System xmlns:ns0="http://xxxx.com/SC/B1/Dlvr/CustDlvr/ExtPrfOfDlvr">
<POD>
<Header>
<SalesOrderNumber>
<xsl:value-of select="$msg/BOM/BO/@SSRPOD/row/U_SalOrdNo" />
</SalesOrderNumber>
<ArrivalDate>
<xsl:value-of select="$msg/BOM/BO/@SSRPOD/row/U_TaxDate" />
</ArrivalDate>
<Detail>
<DOLineQuantity>
<xsl:value-of select="$msg/BOM/BO/@SSRPOD/row/U_Quantity" />
</DOLineQuantity>
<UOM>
<xsl:value-of select="$msg/BOM/BO/@SSRPOD/row/U_Unitmsr" />
</UOM>
</Detail>
</Header>
</POD>
</ns0:MT_POD_B1_System>
</payload>
I have set following things.
Inbound Channel
scenirio step identifier :z.xxxx
Inbound Channel(IPO):INB_B1_EVNT_ASYN_EVT
InboundType:Asynchronous
Process Trigger:B1Event
Identification Method: B1Event
Identification Parameter:n.a
Identifier:?????
Identifier Namespace:??????
can anyone help me?
Edited by: Sinha_Sinha on Feb 3, 2012 7:47 AMFound an authorization object was missing, that enabled the case types to show but hitting the GO button brought a page that can not be viewed in IE. on to the next hurdle..........
-
How to select data from one nested table and into another nested table
create or replace
TYPE ctxt_code_rec as object
ctxt_header varchar2(10),
header_description varchar2(300),
status varchar2(30),
adjacent_code varchar2(300),
adjacent_desc Varchar2(400),
adjacent_flag varchar2(4000),
adjacent_text_href varchar2(4000)
create or replace
type ctxt_code_table as table of CTXT_CODE_REC
d_table ctxt_code_table ;
v_tab ctxt_code_table ;
Iam trying to select data from d_table to v_tab
using and bulk collect into
select m.*
bulk collect into p_code_result
from table(l_loop_diag_code_table1)m
order by 1;
Receiving error:
ora 94007 : not enoughvalues
Could you please let me know how to solve it?
Thanks,
in advance>
create or replace
TYPE ctxt_code_rec as object
ctxt_header varchar2(10),
header_description varchar2(300),
status varchar2(30),
adjacent_code varchar2(300),
adjacent_desc Varchar2(400),
adjacent_flag varchar2(4000),
adjacent_text_href varchar2(4000)
create or replace
type ctxt_code_table as table of CTXT_CODE_REC
d_table ctxt_code_table ;
v_tab ctxt_code_table ;
Iam trying to select data from d_table to v_tab
using and bulk collect into
select m.*
bulk collect into p_code_result
from table(l_loop_diag_code_table1)m
order by 1;
Receiving error:
ora 94007 : not enoughvalues
Could you please let me know how to solve it?
>
Not unless you provide the code you are actually using.
There is no definition of 'p_code_result' in your post and you say you 'trying to select data from d_table' but there is no code that loads 'd_table' in what you posted.
And the SELECT query you posted actuall selects from an object named 'l_loop_idag_code_table1' which isn't mentioned in your code.
Post the actual code you are using and all of the structures being used.
Also explain why you even need to use nested tables and PL/SQL for whatever it is you are really doing. -
Select from local (tmp) Table in Function - Table not found
Hi,
I want to create a cursor which selects from a Table which does not exist in database.
I create this table as local table (how is it called? nested table?).
Not shown in the code but I want to fill this local table later.
After filled my cursor is going to use this filled table.
When try to run I get the error Table or View does not exist at the "FROM TempTab_var T1;" of my cursor.
This is my simplified code:
CREATE OR REPLACE FUNCTION PC_RL_MTA_PMT
RETURN PC_RL_MTA_TYPE_PMT
IS
result_out PC_RL_MTA_TYPE_PMT;
TYPE TempTab_record_type IS RECORD
(ID int);
TYPE TempTab_type IS TABLE OF TempTab_record_type
INDEX BY BINARY_INTEGER;
TempTab_var TempTab_type;
CURSOR TempCursor3_var IS
SELECT ID AS ID_var
FROM TempTab_var T1;
BEGIN
RETURN result_out;
END PC_RL_MTA_PMT;
Any Ideas whats wrong?
Thanks very much in advance.And a further example from my library of examples, just to help you out...
SQL> CREATE OR REPLACE TYPE num_descript AS OBJECT(num number, descript varchar2(30))
2 /
Type created.
SQL> CREATE OR REPLACE TYPE tbl_num_descript AS TABLE OF num_descript
2 /
Type created.
SQL> CREATE OR REPLACE PACKAGE reftest AS
2 FUNCTION pipedata(p_choice number) RETURN tbl_num_descript PIPELINED;
3 END;
4 /
Package created.
SQL> CREATE OR REPLACE PACKAGE BODY reftest AS
2 FUNCTION pipedata(p_choice number) RETURN tbl_num_descript PIPELINED IS
3 v_obj num_descript := num_descript(NULL,NULL);
4 v_rc sys_refcursor;
5 BEGIN
6 IF p_choice = 1 THEN
7 OPEN v_rc FOR SELECT empno as num, ename as descript FROM emp;
8 ELSIF p_choice = 2 THEN
9 OPEN v_rc FOR SELECT deptno as num, dname as descript FROM dept;
10 END IF;
11 LOOP
12 FETCH v_rc INTO v_obj.num, v_obj.descript;
13 EXIT WHEN v_rc%NOTFOUND;
14 PIPE ROW(v_obj);
15 END LOOP;
16 CLOSE v_rc;
17 RETURN;
18 END;
19 END;
20 /
Package body created.
SQL> select * from table(reftest.pipedata(1));
NUM DESCRIPT
7369 SMITH
7499 ALLEN
7521 WARD
7566 JONES
7654 MARTIN
7698 BLAKE
7782 CLARK
7788 SCOTT
7839 KING
7844 TURNER
7876 ADAMS
7900 JAMES
7902 FORD
7934 MILLER
14 rows selected.
SQL> select * from table(reftest.pipedata(2));
NUM DESCRIPT
10 ACCOUNTING
20 RESEARCH
30 SALES
40 OPERATIONS -
I want to insert data into a gta from a nested table
Hi,
I want to insert data into a global temporary table from nested table.
How do i do it?cursor cc is select * from t1;
TYPE temp_rec_tab IS TABLE OF temp_rec_tap_cur%ROWTYPE;
TYPE rec_num_tab1 is table of temp_records_tap.record_num%type;
v_test_tab temp_rec_tab;
---- v_rec_num num_tab;
v_rec_num rec_num_tab1;
v_filename temp_records_tap.file_name%TYPE;
v_error_code tap_reject.ERROR_CODE%TYPE;
v_rej_value tap_reject.field_rej%TYPE;
v_count NUMBER;
BEGIN
OPEN cc;
LOOP
BEGIN
FETCH cc
BULK COLLECT INTO v_test_tab LIMIT 1000;
FORALL i IN v_test_tab.FIRST .. v_test_tab.LAST SAVE EXCEPTIONS
INSERT INTO tt2
VALUES v_test_tab (i)
RETURNING record_num
BULK COLLECT INTO v_rec_num;
EXCEPTION
WHEN OTHERS
THEN
NULL;
END;
EXIT WHEN temp_rec_tap_cur%NOTFOUND;
FORALL i in v_rec_num.first..v_rec_num.last
INSERT INTO record_num_session values v_rec_num(i); ------- v_num(i) INVALID IDENTIFIER ??????
END LOOP;
END; -
Unable To Select From SQL Server table with more than 42 columns
I have set up a link between a Microsoft SQL Server 2003 database and an Oracle 9i database using Heterogeneous Services (HSODBC). It's working well with most of the schema I'm selecting from except for 3 tables. I don't know why. The common denominator between all the tables is that they all have at least 42 columns each, two have 42 columns, one has 56, and the other one, 66. Two of the tables are empty, one has almost 100k records, one has has 170k records. So I don't think the size of the table matters.
Is there a limitation on the number of table columns you can select from through a dblink? Even the following statement errors out:
select 1
from "Table_With_42_Cols"@sqlserver_db
The error message I get is:
ORA-28500: connection from ORACLE to a non-Oracle system returned this message [Generic Connectivity Using ODBC]
ORA-02063: preceding 2 lines from sqlserver_db
Any assistance would be greatly appreciated. Thanks!Not a very efficient and space friendly design to do name-value pairs like that.
Other methods to consider is splitting those 1500 parameters up into groupings of similar parameters, and then have a table per group.
Another option would be to use "vertical table partitioning" (as oppose to the more standard horizontal partitionining provided by the Oracle partition option) - this can be achieved (kind of) in Oracle using clusters.
Sooner or later this name-value design is going to bite you hard. It has 1500 rows where there should be only 1 row. It is not scalable.. and as you're discovering, it is unnatural to use. I would rather change that table and design sooner than later. -
Giving Error When Selecting From a Custom Table
There is a custom report 'Z*' which archives data.
In this report, while selecting data(needs to be archived) from a custom table 'Z*_T', giving runtime error in Production Server.
The select statement is written below :
*data izX like z_t occurs 1000 with header line._
*select * from z*t into table i_zX.*_
How can I change the select statement so that it will work properly?Sas..
From your example code it appears you are trying to use a wild card for both your dbtable and the internal table.
To do this, you will lilkely need to use a Field Symbol for the target internal table and your FROM will need to be a varible
FROM (dbtabname)
The ABAP Helps gives this example for the Select Table
DATA TABNAME(10).
DATA: BEGIN OF WA,
ID LIKE SCUSTOM-ID,
NAME LIKE SCUSTOM-NAME,
REST(134),
END OF WA.
TABNAME = 'SCUSTOM'.
SELECT * INTO WA FROM (TABNAME).
WRITE: / WA-ID, WA-NAME.
ENDSELECT. -
Creating and selecting from a dynamic table
Hi,
Iam trying to create a table dynamically and selecting from it in same plsql block, but am getting "table doesnot exist" error. however if i just create a table dynamically and then do a select on it seperately it works..
below is sample code for the same,
working
Line: -----
DECLARE
loc VARCHAR2(20):='bglr';
l_cnt pls_integer;
BEGIN
-- create an employee information table
EXECUTE IMMEDIATE
'CREATE TABLE ' || 'emp_bglr' ||
empno NUMBER(4) NOT NULL,
ename VARCHAR2(10),
job VARCHAR2(9),
sal NUMBER(7,2),
deptno NUMBER(2)
end;
select count(*) from emp_bglr ...works and return me 0 rows
Line: -----
but when i include select in plsql block ..it throws "Table does not exists" error...(iam running below plsql block after dropping the created table)
not working
Line: -----
DECLARE
loc VARCHAR2(20):='bglr';
l_cnt pls_integer;
BEGIN
-- create an employee information table
EXECUTE IMMEDIATE
'CREATE TABLE ' || 'emp_bglr' ||
empno NUMBER(4) NOT NULL,
ename VARCHAR2(10),
job VARCHAR2(9),
sal NUMBER(7,2),
deptno NUMBER(2)
--COMMIT;
END;
Select count(*) into l_cnt from emp_bglr;
dbms_output.put_line('cnt is '||l_cnt);
end;
Line: -----Becuase your code is first checked for syntax/object existance during compilation and throws an error saying the table does not exist.
Try this:
SQL> ed
Wrote file afiedt.buf
1 DECLARE
2 loc VARCHAR2(20):='bglr';
3 l_cnt pls_integer;
4 BEGIN
5 -- create an employee information table
6 EXECUTE IMMEDIATE 'CREATE TABLE emp_bglr(
7 empno NUMBER(4) NOT NULL,
8 ename VARCHAR2(10),
9 job VARCHAR2(9),
10 sal NUMBER(7,2),
11 deptno NUMBER(2)
12 )';
14 Select count(*) into l_cnt from all_objects where object_name = 'EMP_BGLR';
15 dbms_output.put_line('tab cnt is '||l_cnt);
16 IF (l_cnt = 1) THEN
17 l_cnt := 0;
18 EXECUTE IMMEDIATE 'SELECT count(*) from apps.emp_bglr' into l_cnt;
19 dbms_output.put_line('data cnt is '||l_cnt);
20 END IF;
21* end;
SQL> /
tab cnt is 1
data cnt is 0
PL/SQL procedure successfully completed.
SQL> Edited by: AP on Aug 5, 2010 5:51 AM
Edited by: AP on Aug 5, 2010 5:52 AM -
Select * from {tablename} : invalid table name error
Hi,
I want to get data from a table and the table should be passed at runtime from selecting a table from the drop down list.In case of insertion of values I am getting no errors.But when I pass the table name as an argument I am getting invalid table name error.I think there is any syntax errors.I appreciate any help.
Regards,
Sivaramyou cannot use parameter for table name in PreparedStatement.
you can either generate the sql dynamically, such as String sql="select * from "+tablename, or you can check whether the database vendor has special api for this.
Maybe you are looking for
-
For some reason on my 2011 Mac Book Pro the digital video out does not work? It works just fine using the minii adapter for analog video out, but not for digital? Any advice much appreciated! Thx Mark
-
How do I disable or delete the country code prefix
I'm in Mexico and want to call another Mexican city ant skype keeps adding 52 before my number. Apparently it thinks I'm in the States and will need this code. How on earth do I just type in a phone number without a code? I don't need a country code
-
How do I display my iPad on my TV?
So I have a first gen iPad and I bought a VGA connector for the iPad but when I connect it the only thing that will display is a movie for a few seconds and the a message shows up on the iPad that says that my device has not been approved to display
-
W540 -- mSATA as boot disk?
Well, I guess there is no getting around the inevitable. If I choose to stay with Lenovo to replace my beloved W700 (which thankfully still works well after 5 years of service), there seems to be no alternative to the W540, clearly inferior in many
-
How do i install mac os x 10.7
I want to download and install 10.7 but it is not in my App store anywhere?