Using table() in select , select .... from .... table( ) where ....
Hi Folks,
I hope someone out there can help me out with this one. It has me stumped:
Basically we have an XML document stored in an XMLType which we need to process relationally.
I have the following cursor definition:
CURSOR c_section13h(cp_jsatfa_xml_id IN NUMBER) IS
SELECT
jx.JSATFA_ID
,to_number(jx.jsatfa_xml_id)
,extractvalue( value(t), '/Email ') as "EMAIL"
FROM jsatfa_xml jx
,table ( xmlsequence (extract (jx.xml_doc, '/document/Section13/Accommodation/Row/Email'))) t
WHERE jx.jsatfa_xml_id = cp_jsatfa_xml_id;This returns:
jx.jsatfa_id, jx.jsatfa_xml_id, Email1
jx.jsatfa_id, jx.jsatfa_xml_id, Email2
jx.jsatfa_id, jx.jsatfa_xml_id, Email3
jx.jsatfa_id, jx.jsatfa_xml_id, Email4
This in itself works. However I would like to pull out a second item (e.g. Telephone) from the xml_document in the form:
jx.jsatfa_id, jx.jsatfa_xml_id, Email1, Telephone1
jx.jsatfa_id, jx.jsatfa_xml_id, Email2, Telephone2
jx.jsatfa_id, jx.jsatfa_xml_id, Email3, Telephone3
jx.jsatfa_id, jx.jsatfa_xml_id, Email4, Telephone4
At present I have to use a second cursor to process the second entry. This is because is is not possible to have more than one table() definition in the from clause as Cartesian products result. I.E the following causes a cartesian:
CURSOR c_section13h(cp_jsatfa_xml_id IN NUMBER) IS
SELECT
jx.JSATFA_ID
,to_number(jx.jsatfa_xml_id)
,extractvalue( value(t), '/Email ') as "EMAIL"
,extractvalue( value(t1), '/Telephone') as "TELEPHONE"
FROM jsatfa_xml jx
,table ( xmlsequence (extract (jx.xml_doc, '/document/Section13/Accommodation/Row/Email'))) t
,table ( xmlsequence (extract (jx.xml_doc, '/document/Section13/Accommodation/Row/Telephone'))) t1
WHERE jx.jsatfa_xml_id = cp_jsatfa_xml_id;The specific XML data is tabular data (i.e. its square). Currently I am processing each column (e.g. email, telephone) with a separate cursors.
Ideally I'd like to be able to place the jsatfa_id and jsatfa_xml_id within the table( ) clause so that they can be joined without creating Cartesian products. These IDs are not in the xml.
Does anyone have any ideas
I hope this makes sense, if it doesn't please let me know.
- Kris
http://kristianjones.blogspot.com
Message was edited by:
Kris Jones
Message was edited by:
Kris Jones
Here is one way to do that:
michaels> WITH jsatfa_xml AS
(SELECT 1 jsatfa_xml_id, XMLTYPE
<document>
<Section13>
<Accommodation>
<Row>
<TelephoneNumber>telnum</TelephoneNumber>
<TelephoneNumber>telnum2</TelephoneNumber>
<TelephoneNumber />
<TelephoneNumber />
<TelephoneNumber />
</Row>
<Row>
<Email>[email protected]</Email>
<Email />
<Email />
<Email />
<Email />
</Row>
<Row>
<Comments>no comment</Comments>
<Comments />
<Comments />
<Comments />
<Comments />
</Row>
</Accommodation>
<Row>
</Row>
<Row>
</Row>
</Section13>
</document>'
) xml_doc
FROM DUAL)
--- End Test XML
SELECT jsatfa_xml_id, email, phone
FROM jsatfa_xml t,
XMLTable('Email' PASSING EXTRACT(xml_doc,'/document/Section13/Accommodation/Row/Email')
COLUMNS POS FOR ORDINALITY,
EMAIL VARCHAR2(30) PATH 'node()'
) t2,
XMLTable('TelephoneNumber' PASSING EXTRACT(xml_doc,'/document/Section13/Accommodation/Row/TelephoneNumber')
COLUMNS POS FOR ORDINALITY,
PHONE VARCHAR2(30) PATH 'node()'
) t3
WHERE t2.pos = t3.pos
AND jsatfa_xml_id = 1
JSATFA_XML_ID EMAIL PHONE
1 [email protected] telnum
1 telnum2
1
1
1
5 rows selected.
Similar Messages
-
Select LONG_RAW from table.
I've got a table with a column of long_raw datatype.
Whenever I'm selecting data from that table it displays (blob)
I need to get the data out of the column through pl/SQL
1. why is it saying (blob) when the column is of long_raw datatype?
2.Can I select the content from a long_raw column and display it?
Regards,
Satrajityou need to use the oracle built-in package UTL_RAW. here are some examples:
SQL> create table sample_long_raw
2 (long_msg long raw);
Table created.
SQL> describe sample_long_raw;
Name Null? Type
LONG_MSG LONG RAW
SQL> insert into sample_long_raw
2 values ('hello');
values ('hello')
ERROR at line 2:
ORA-01465: invalid hex number
SQL> insert into sample_long_raw
2 values (utl_raw.cast_to_raw('hello'));
1 row created.
SQL> select * from sample_long_raw;
L
6
SQL> create or replace function get_long_raw (row in rowid) return varchar2 is
2 longhold varchar2(4000);
3 begin
4 for r in (select LONG_MSG from sample_long_raw where rowid = row) loop
5 longhold := utl_raw.cast_to_varchar2(r.long_msg);
6 end loop;
7 return longhold;
8 end;
9 /
Function created.
SQL> select get_long_raw (rowid) from sample_long_raw;
GET_LONG(ROWID)
hello
SQL> hope this helps. -
Select count(*) from table in oracle 11g with direct path read takes time
select count(*) from table takes long time, even more than couple of hours..
direct path read is the wait event which is almost is at 99%..
can u someone provide some info on this.. on solution.. thankxknowledgespring wrote:
table has millions of records... 130 millions..
select count(*) from BIG_SIZE_TABLE; --- executed in sql plus command prompt.
Rows Execution Plan
0 SELECT STATEMENT MODE: ALL_ROWS
0 SORT (AGGREGATE)
0 TABLE ACCESS MODE: ANALYZED (FULL) OF 'BIG_SIZE_TABLE' (TABLE)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 1 0.00 0.00
enq: KO - fast object checkpoint 1 0.01 0.01
Disk file operations I/O 18 0.00 0.00
direct path read 58921 0.34 418.54direct path read time waited is : 58921 total time waited: 418.54
That 418 seconds - not the hours you reported earlier. Is it possible that your connection to the database broke ?
On a typical system, by the way, you can usually turn one direct read for tablescan into 1MB, so your scan seems to have covered about 59 GB, which seems to be in the right sort of ballpark for 130M rows.
we have another query and when we test the query execution using v$sql, is_bind_sensitive =N, how to make is_bind_sensitive=Y all the time.. There is a hint /*+ bind_aware */ - I'd have to check whether or not it's documented at present. It might help.
I would be interested in hearing why you think the hint should be bind sensitive when the optimizer doesn't.
Regards
Jonathan Lewis -
Select data from table not in another table
Hi,
I want to select data from table A which is not in table B.
Currently I am doing:
select
snoA,
nameA,
dobA
from A
where snoA not in
(select snoB from A, B
where snoA = snoB
and nameA = nameB)
But above is very slow.
Can I do something like:
select
snoA,
nameA,
dobA
from A, B
where
EXCLUDE ( snoA = snoB and nameA = nameB)
Please note that I need the where condition on both the columns.
any help will be appreciated.
-- HarveyWhat are the approximate data volumes in A and B?
What is "very slow"?
What version of Oracle?
What is the query plan?
Without knowing anything about your system, my first thought would be to see if a NOT EXISTS happened to be faster for your data
SELECT snoA,
nameA,
dobA
FROM a
WHERE NOT EXISTS (
SELECT 1
FROM b
WHERE a.snoA = b.snoB
AND a.nameA = b.nameB )Of course, I'm not sure why you are joining A & B in your NOT IN subquery. It would seem like you would just need a correlated subquery, i.e.
SELECT snoA,
nameA,
dobA
FROM a
WHERE snoA NOT IN (
SELECT snoB
FROM b
WHERE a.snoA = b.snoB
AND a.nameA = b.nameB )That should be more efficient than the original query. The NOT EXISTS version may or may not be more efficient than the NOT IN depending on data volumes.
Justin -
Select datas from table in horizontal
Hi all,
I have this table PARAPROV where the fields is
CODI_PROV NOT NULL VARCHAR2(3)
CODI_REGI NOT NULL VARCHAR2(3)
CODI_SIGL_PROV NOT NULL VARCHAR2(2)
And I run this statment
select codi_sigl_prov SIGLA from paraprov
where codi_regi = (select codi_regi
from paraprov where codi_sigl_prov='LT');where the result is
SIGLA
FR
LT
RI
RM
VT
How can I have as result, one record, like this?
SIGLA
FR/LT/RI/RM/VT
It's possible?
Thank's a lot
Paolo from MadridSQL>
SQL> With t As
2 (
3 Select 'FR' col From dual Union All
4 Select 'LT' From dual Union All
5 Select 'RI' From dual Union All
6 Select 'RM' From dual Union All
7 Select 'VT' From dual
8 )
9 Select ltrim(max(SYS_CONNECT_BY_PATH(col,'/')),'/') "Col"
10 From
11 (
12 Select col,
13 row_number() over (Order By col) As curr,
14 row_number() over (Order By col) -1 As prev
15 From t
16 )
17 Connect By prev = Prior curr
18 Start With curr = 1;
Col
FR/LT/RI/RM/VT
SQL> -
Select data from table depending on date range
i have first table with following data, This is calender for a year
I have 2nd table , user created period from 1st table
I want to select acctstartdate from 1st tale which are not within 2nd table period.
I want to select acctstartdate as jan to aug only. I dont want to select acctstartdate for sept and oct-dec.
Same with acctenddate. I want to select Jan-aug only
How to do this ??
h2007Do you mean this?
SELECT *
FROM Table1 t1
WHERE NOT EXISTS (SELECT 1
FROM Table2
WHERE ACCTYRID = t1.ACCTYRID
AND ACCTYR = t1.ACCTYR
AND (t1.ACCTSTARTDATE BETWEEN ACCTSTARTDATE AND ACCTENDDATE
OR t1.ACCTENDDATE BETWEEN ACCTSTARTDATE AND ACCTENDDATE
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
How do I execute "Select count(*) from table " in OCI
Hi,
I am new to OCI and so this question may seem stupid. I would like to know how to execute the query "select count(*) from <table>" using OCI V8 functionality? Also after how do I get the result into a integer datatype? I have gone through most of the demo programs but is is of little help to me.
Thanks in advance...
Regards,
Shubhayan.Hi,
Here is sample code to give you some idea how to do it. If you want some more info let me know.
Pankaj
ub4 count;
// Prepare the statement.
char szQry = "SELECT count() FROM T1";
if(OCI_ERROR == OCIStmtPrepare(pStmthp, pErrhp, (unsigned char*)szQry, strlen(szQry), OCI_NTV_SYNTAX , OCI_DEFAULT) )
cout << "Error in OCIStmtPrepare" << endl;
exit(1);
// Bind the output parameter.
OCIDefine *pDefnpp;
if(OCI_ERROR == OCIDefineByPos ( pStmthp, &pDefnpp, pErrhp, 1,
&count, sizeof(ub4), SQLT_INT,
(dvoid *) 0, (ub2 *) 0, (ub2 *) 0,
OCI_DEFAULT) )
cout << "Error in OCIDefineByPos" << endl;
exit(1);
if(OCI_ERROR == OCIStmtExecute(pSvchp, pStmthp, pErrhp, 1, 0, NULL, NULL, OCI_DEFAULT) )
cout << "Error in OCIStmtExecute" << endl;
exit(1); -
Probel while selecting data from table
Hi,
As per my below code i want to select data from table AFKO where PLNBEZ = it_mat-matnr, and GETRI IS BLANK , but data is not comingin IT_AFKO
**********************CODE
select AUFNR RSNUM GAMNG PLNBEZ From AFKO into table it_afko for all entries in it_mat
where PLNBEZ = it_mat-matnr
and GETRI = ' '.
regards,
zafarHi,
Try below code
select AUFNR RSNUM GAMNG PLNBEZ From AFKO into table it_afko for all entries in it_mat
where PLNBEZ = it_mat-matnr
and GETRI = '00000000'.
Hope you need the records for which GETRI is not updated.
Regards
Vinod -
Can a procedure select data from tables on other schemas?
Can a procedure select data from tables on other schemas?
If it is posible, which syntax should I use to identify the tables and schemas on the SELECT query?Yes , it is possible..unless the current user has the right privileges on others' db objects schema.
Now , as regards the syntax....
1) The more descriptive way is to use the format ... <owner_schema>.<obj_name>.
2) If you have declared public synonyms of other schema's objects then you can refer to them as just <obj.name>.... but the <owner_schema>.<obj_name> is not wrong.
3) If the db objects reside on another database you must have declared a db link.... then the syntax is <owner_schema>.<obj_name>@<db_link_name>.
Regards,
Simon -
Select values from table%ROWTYPE variable into a cursor
I have a stored procedure which has an OUT parameter of table1%ROWTYPE.
In future we might have to add more OUT parameters of table2%ROWTYPE etc. But at any point of time only one will have values.
So instead of having table%ROWTYPE as OUT parameter, can I send these single row ( with variable values) in a cursor, so that declaration part atleast will not change.
Is it possible to select values from table%ROWTYPE variable into a cursor.
cursorOUT IS
SELECT * FROM varREC;
where varREC is table.ROWTYPE variable.
Or which is the better solution in this situation.
Thanks.SQL> var a refcursor
SQL> declare
2 bb emp%ROWTYPE;
3 begin
4 select * into bb from emp where rownum = 1;
5 open :a for select bb.ename ename, bb.empno empno from dual;
6 end;
7 /
PL/SQL procedure successfully completed.
SQL> print a
ENAME EMPNO
SMITH 7369Rgds. -
Select aentries from table Z-Table for all sales order line items
Hi friends,
can anyone please explain me about the "Select entries from table Z-Table for all sales order line items".
Thanks.Moderator message - Welcome to SCN.
But
Moderator message - Please search before asking. Press F1 on SELECT and look at the FOR ALL ENTRIES addition. - post locked
Rob -
hi
SELECT fcpp.concurrent_request_id req_id, fcp.node_name, fcp.logfile_name
FROM fnd_conc_pp_actions fcpp, fnd_concurrent_processes fcp
WHERE fcpp.processor_id = fcp.concurrent_process_id
AND fcpp.action_type = 6
AND fcpp.concurrent_request_id = &&request_id
;its returning logfile name ...
AND
select count(*) from fnd_conc_pp_actions where action_type=6;its returning 460 rows.
i want to know what is action_type?
and how to know about all attribute about this fnd tables?
regardsHelios- Gunes EROL wrote:
Hi;
For your question please check e-trm site. You can find relation&explanation&integration and more on e-trm site.(etrm.oracle.com)
Regard
Heliosetrm is not opening. -
Dear team support,
I have a problem with my WhatsApp Messenger.
my whatsapp wont save message history. couse error.
Error: Sqlite Error (schema update):
net.rim.device.api.database.DatabaseException: SELECT name FROM sqlite_master WHERE type = 'index' AND name = 'chat_history_jid_index': disk I / O error (10).
Please advise me how can i solve my memory card issue..
Thanksls -l /var/run/lighttpd/
And how are you spawning the php instances? I don't see that in the daemons array anywhere.
EDIT: It looks like the info in that page is no longer using pre-spawned instances, but lighttpd adaptive-spawn. The documentation has been made inconsistent it looks like.
You will note that with pre-spawned information, the config looks different[1].
You need to do one or the other, not both (eg. choose adaptive-spawn, or pre-spawn..not both).
[1]: http://wiki.archlinux.org/index.php?tit … oldid=8051 "change" -
Whats the meaning of plus in query : select employeename from emp where emp
Hi All,
Can someone please explain me whats the meaning of plus sign in following SQL. I have nevercome across this syntax
select employeename from emp where empid(+) >= 1234.Example of equivalent queries using oracle syntax and ansi syntax
SQL> ed
Wrote file afiedt.buf
1 select d.deptno, d.dname, e.ename
2 from dept d, emp e
3* where d.deptno = e.deptno (+)
SQL> /
DEPTNO DNAME ENAME
20 RESEARCH SMITH
30 SALES ALLEN
30 SALES WARD
20 RESEARCH JONES
30 SALES MARTIN
30 SALES BLAKE
10 ACCOUNTING CLARK
20 RESEARCH SCOTT
10 ACCOUNTING KING
30 SALES TURNER
20 RESEARCH ADAMS
30 SALES JAMES
20 RESEARCH FORD
10 ACCOUNTING MILLER
40 OPERATIONS
15 rows selected.
SQL> ed
Wrote file afiedt.buf
1 select d.deptno, d.dname, e.ename
2* from dept d left outer join emp e on (d.deptno = e.deptno)
SQL> /
DEPTNO DNAME ENAME
20 RESEARCH SMITH
30 SALES ALLEN
30 SALES WARD
20 RESEARCH JONES
30 SALES MARTIN
30 SALES BLAKE
10 ACCOUNTING CLARK
20 RESEARCH SCOTT
10 ACCOUNTING KING
30 SALES TURNER
20 RESEARCH ADAMS
30 SALES JAMES
20 RESEARCH FORD
10 ACCOUNTING MILLER
40 OPERATIONS
15 rows selected.
SQL> -
Select ename from emp where ename like LIKE 's%';
Hi friends,
select ename from emp where ename like LIKE 's%';
output am geting like this naseer
anusha
basha
But I want to display like this naeer anuha baha784585 wrote:
Hi friends,
select ename from emp where ename like LIKE 's%';
output am geting like this naseer
anusha
basha
But I want to display like this naeer anuha baha
Use REPLACE function:
SQL> select replace('naseer','s','') replace from dual;
REPLACE
naeerKamran Agayev A.
Oracle ACE
My Oracle Video Tutorials - http://kamranagayev.wordpress.com/oracle-video-tutorials/ -
About SELECT VALUE FROM NLS_INSTANCE_PARAMETERS WHERE PARAMETER =""
I am developing a web application based on Oacle 10g .But after the DBServe was startedup for about 5~6 hours, the max connection process exceeded. From the DB Administration Tool it shows that there were many INACTIVE Connections which executed
SELECT VALUE FROM NLS_INSTANCE_PARAMETERS WHERE PARAMETER ='NLS_DATE_FORMAT'
But it seems that this is called by the JDBC driver, not my application. How to avoid this, or release the inactive connection?
By the way,who and when call that sql?
Thanks a lot.By the way,who and when call that sql?Also for this you can take an 10046 level 8 sql trace and format the output with sys=yes option of tkprof - http://tonguc.wordpress.com/2006/12/30/introduction-to-oracle-trace-utulity-and-understanding-the-fundamental-performance-equation/
Since we are talking about a web application you may use a database logon trigger to start sql trace for your application user, or if possible you may set sql_trace database parameter to true at instance level for a while and since you are at 10g you can use new package dbms_monitor and trcsess utility - http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/sqltrace.htm#sthref2001
Best regards.
Maybe you are looking for
-
Adding value's from a main and subreport
Post Author: Nick7 CA Forum: Formula I have a valuation report containing a subreport, and I want to create a formula that adds the grand total of the main report to the grand total of the subreport to give me an overall total figure. The value's ar
-
WebEngine post processing after Export
Is it possible to have a webengine post export processing (like a trigger to a function in webengine script galleryInfo.lrweb) after the successful Export step? I would like to do some script file copy to the album exported folder based on user selec
-
IPhoto Library Not Found after Upgrade to Leopard
I was running the newest iPhoto under Tiger and I just upgraded to Leopard. I tried to open iPhoto and a message said, "iPhoto library not found." It was there before I upgraded from Tiger. I mostly use Adobe Bridge so I didn't have much in iPhoto bu
-
SMS credit left in oracle convergence 2
I want to show SMS credit left for user in event reminder of calendar and alert to be sent through sms only if there is sms credit available.
-
Cannot make firefox and acrobat default applications
Help please. I have tried everything I know to force my MBP to use Acobat and Firefox as the default applications for web and PDF, but to no avail, after I shutdown and restart, all reverts to safari and preview. I tried to change the application in