Query on Resource_View
I have a function that accepts an xmltype (pXml) as an agrument and will return the Resource Type (Link(L), File(D), or Folder(F)). The first part of the function works fine:
EXTRACTVALUE(pXML, '/Resource/XMLRef') IS NULL
EXTRACTVALUE(pXML, '/Resource/RefCount') = '01'
I return an "F" for the first test and an "D" for the second test. However, when a link is involved, I am getting problems, different ones for different approaches. I need to relate the passed in pXml (an xmltype) to the Resource_View. The simpliest(I thought) approach was this query to get a unique identifier from the Resource_View:
FOR ResT IN
(SELECT ResId
FROM Resource_View
WHERE EXTRACTVALUE(Res, '/Resource/XMLRef') = EXTRACTVALUE(pXml, '/Resource/XMLRef'))
LOOP
vResId := ResT.ResId;
EXIT;
END LOOP;
The above fails with:
ORA-00932: inconsistent datatypes: expected REF got CHAR
ORA-06512: at "LEGALSERVICES.GETRESTYPE_FUN", line 37
Apparently I am NOT dealing with the same datatype. Somehow the extractvalue method operates differently on Resource_View.ResId and pXml. How can I extract some identifier from pXml to relate against the resource view? I can also use an Object_Id(SYS_NC_ROWINFO$) because I ultimately will query against the xdb.xdb$resource to resolve the irksome problem whereby the extracted display name and xmlref values are identical for both a link its target file. I just need some unique identifier from the passed in xml document. I also could use a path if that can be somehow extracted from the passed in xml document (document already in the xdb repository).
I think you will have to do a hexToRef when pworking with pXML
Similar Messages
-
Querying RESOURCE_VIEW using XQuery
Hi all:
Anybody knows the best way to query RESOURCE_VIEW using XQuery to show directory listing information as an example.
For example, I want to produce an XML Document with something like this using XQuery:
<directoryListing>
<dir anyPath="/public/JURRICULUM/cms/en">
<DisplayName xmlns="http://xmlns.oracle.com/xdb/XDBResource.xsd">en</DisplayName>
</dir>
<dir anyPath="/public/JURRICULUM/cms/en/live">
<DisplayName xmlns="http://xmlns.oracle.com/xdb/XDBResource.xsd">live</DisplayName>
</dir>
<dir anyPath="/public/JURRICULUM/cms/es">
<DisplayName xmlns="http://xmlns.oracle.com/xdb/XDBResource.xsd">es</DisplayName>
</dir>
<dir anyPath="/public/JURRICULUM/cms/es/live">
<DisplayName xmlns="http://xmlns.oracle.com/xdb/XDBResource.xsd">live</DisplayName>
</dir>
</directoryListing>
I made this result by executing this query:
SELECT XMLQuery('declare namespace res = "http://xmlns.oracle.com/xdb/XDBResource.xsd";
<directoryListing>
{for $i in $directoryListing/dir
where $i/res:Resource/@Container="true"
return
<dir anyPath="{$i/@ANY_PATH}">
{$i/res:Resource/res:DisplayName}
</dir>}
</directoryListing>'
PASSING (
select XMLAgg(XMLElement("dir",XMLATTRIBUTES(any_path,resid),res))
from resource_view where
under_path(res,'/public/JURRICULUM/cms')=1
) as "directoryListing" RETURNING CONTENT).getStringVal()
FROM dual
I had injected resource_view's content as an argument.
Another way is to use ora:view() extension function, but I can't use under_path functionality for example.
Is there some extension funcion like doc() or collection() but instead of returning the content of the document, returning the information of resource_view asociated to the URI?
Is the above query optimal in term of execution plan?
I tested it with JDeveloper and shows an execution plan similar to the query on resource_view alone.
Best regards, Marcelo.Hi all:
I had implemented an XQuery extension library ready to run inside the Oracle JVM, but it can run outside as well.
The code is on the XQuery forums:
How to write an XQuery Extension library
I tested outside the database and the result is:
/usr/java/jdk1.5.0_04/bin/java -hotspot -classpath ... com.prism.cms.xquery.Application1 /public/PCT_ADMIN/cms/es/3-AcercaParque/ 7934
testXQL elapsed time: 3094
testXQ elapsed time: 2164
Running as Java Stored Procedure, it looks like this:
SQL> exec testXQ('/public/PCT_ADMIN/cms/es/3-AcercaParque/','7934')
testXQL elapsed time: 943
testXQ elapsed time: 854
PL/SQL procedure successfully completed.
Obviously running as Java Stored procedure its around 3.5 faster than a regular application.
Injecting the resource_view content as an argument instead of using an XQuery extension library seem to be equals (943 ~ 854), so I'll use the extension library mechanish for clearlying on the code.
Best regards, Marcelo -
Querying res column of RESOURCE_VIEW
Mark ,
i want to create a resource on the repository, and then create views based on xpath, update some tables and then delete the resource.
Now when i place the xml file in a xmltpye column every thing works fine. But it seems to be bit tricky wheni want to query from RES column. Might be problem with multiple namespace being used for each resource, not sure about it.
Now till here i am able to query successfully as you see the output.
SQL> select
2 extract(res, '/Resource/Contents').getclobval()
3 from resource_view
4 where any_path like '/public/labor/sequencedata.xml'
5 /
<Contents xmlns="http://xmlns.oracle.com/xdb/XDBResource.xsd">
<SequenceData>
<Header>
<id>285062</id>
<TemplateName>1 dup</TemplateName>
<TemplateVersion>1</TemplateVersion>
<CreUser>AJB2KOR</CreUser>
<CreDate>02-SEP-05</CreDate>
</Header>
<Variables>
<SetPhaseVariables/>
<MeasPhaseVariables>
<MeasPhaseVariable>
<Name>TimeStamp</Name>
<Unit>Sec</Unit>
</MeasPhaseVariable>
</MeasPhaseVariables>
<MonitoredVariables>
<MonitoredVariable>
<Name>Svar b</Name>
<Unit>b</Unit>
</MonitoredVariable>
<MonitoredVariable>
<Name>Svar c</Name>
<Unit>c</Unit>
</MonitoredVariable>
</MonitoredVariables>
</Variables>
<LoadPoint LevelNumber="1" id="114103" Description="LOADPOINT: (werwrwrw)">
<LoopCount InnerLoop="1" OuterLoop="1">
<MonitoredVariables/>
<SetPhase>
<MonitoredVariables/>
<SetPhaseVariables/>
</SetPhase>
<WaitPhase>
<WaitingTime>0</WaitingTime>
<MonitoredVariables/>
</WaitPhase>
<MeasPhase>
<MeasPhaseLoopRun/>
<Manual>N</Manual>
<MeasPhaseVariables/>
</MeasPhase>
</LoopCount>
</LoadPoint>
</SequenceData>
</Contents>
now when i want to navigate one more level below to the SequenceData it does not work.
SQL> select
2 extract(res, '/Resource/Contents/SequenceData').getclobval()
3 from resource_view
4 where any_path like '/public/labor/sequencedata.xml'
5 /
SQL>Hi Raghu
You were on the right lines.. See below
SQL> set long 1000 pages 0
SQL> --
SQL> var targetPath varchar2(256)
SQL> --
SQL> begin
2 :targetPath := '/public/testcase.xml';
3 end;
4 /
PL/SQL procedure successfully completed.
SQL> declare
2 res boolean;
3 contents xmltype := xmltype(
4 '<SequenceData>
5 <Header>
6 <id>285062</id>
7 <TemplateName>1 dup</TemplateName>
8 <TemplateVersion>1</TemplateVersion>
9 <CreUser>AJB2KOR</CreUser>
10 <CreDate>02-SEP-05</CreDate>
11 </Header>
12 <Variables>
13 <SetPhaseVariables/>
14 <MeasPhaseVariables>
15 <MeasPhaseVariable>
16 <Name>TimeStamp</Name>
17 <Unit>Sec</Unit>
18 </MeasPhaseVariable>
19 </MeasPhaseVariables>
20 <MonitoredVariables>
21 <MonitoredVariable>
22 <Name>Svar b</Name>
23 <Unit>b</Unit>
24 </MonitoredVariable>
25 <MonitoredVariable>
26 <Name>Svar c</Name>
27 <Unit>c</Unit>
28 </MonitoredVariable>
29 </MonitoredVariables>
30 </Variables>
31 <LoadPoint LevelNumber="1" id="114103" Description="LOADPOINT: (werwrwrw)">
32 <LoopCount InnerLoop="1" OuterLoop="1">
33 <MonitoredVariables/>
34 <SetPhase>
35 <MonitoredVariables/>
36 <SetPhaseVariables/>
37 </SetPhase>
38 <WaitPhase>
39 <WaitingTime>0</WaitingTime>
40 <MonitoredVariables/>
41 </WaitPhase>
42 <MeasPhase>
43 <MeasPhaseLoopRun/>
44 <Manual>N</Manual>
45 <MeasPhaseVariables/>
46 </MeasPhase>
47 </LoopCount>
48 </LoadPoint>
49 </SequenceData>');
50 begin
51 if (dbms_xdb.existsResource(:targetPath)) then
52 dbms_xdb.deleteResource(:targetPath);
53 end if;
54 res := dbms_xdb.createResource(:targetPath,contents);
55 end;
56 /
PL/SQL procedure successfully completed.
SQL> commit;
Commit complete.
SQL> /
Commit complete.
SQL> select extract(res, '/Resource/Contents', 'xmlns="http://xmlns.oracle.com/xdb/XDBResource.xsd"').getclobval()
2 from resource_view
3 where equals_path(res, :targetPath) = 1
4 /
<Contents xmlns="http://xmlns.oracle.com/xdb/XDBResource.xsd"><SequenceData xmln
s=""><Header><id>285062</id><TemplateName>1 dup</TemplateName><TemplateVersion>1
</TemplateVersion><CreUser>AJB2KOR</CreUser><CreDate>02-SEP-05</CreDate></Header
<Variables><SetPhaseVariables/><MeasPhaseVariables><MeasPhaseVariable><Name>TimeStamp</Name><Unit>Sec</Unit></MeasPhaseVariable></MeasPhaseVariables><Monitored
Variables><MonitoredVariable><Name>Svar b</Name><Unit>b</Unit></MonitoredVariabl
e><MonitoredVariable><Name>Svar c</Name><Unit>c</Unit></MonitoredVariable></Moni
toredVariables></Variables><LoadPoint LevelNumber="1" id="114103" Description="L
OADPOINT: (werwrwrw)"><LoopCount InnerLoop="1" OuterLoop="1"><MonitoredVariables
/><SetPhase><MonitoredVariables/><SetPhaseVariables/></SetPhase><WaitPhase><Wait
ingTime>0</WaitingTime><MonitoredVariables/></WaitPhase><MeasPhase><MeasPhaseLoo
pRun/><Manual>N</Manual><MeasPhaseVariables/></MeasPhase></LoopCount></LoadPoint
</SequenceData></Contents>
SQL> select extract(res, '/r:Resource/r:Contents/SequenceData', 'xmlns:r="http://xmlns.oracle.com/xdb/XDBResource.xsd"').getclobval()
2 from resource_view
3 where equals_path(res, :targetPath) = 1
4 /
<SequenceData><Header><id>285062</id><TemplateName>1 dup</TemplateName><Template
Version>1</TemplateVersion><CreUser>AJB2KOR</CreUser><CreDate>02-SEP-05</CreDate
</Header><Variables><SetPhaseVariables/><MeasPhaseVariables><MeasPhaseVariable><Name>TimeStamp</Name><Unit>Sec</Unit></MeasPhaseVariable></MeasPhaseVariables><
MonitoredVariables><MonitoredVariable><Name>Svar b</Name><Unit>b</Unit></Monitor
edVariable><MonitoredVariable><Name>Svar c</Name><Unit>c</Unit></MonitoredVariab
le></MonitoredVariables></Variables><LoadPoint LevelNumber="1" id="114103" Descr
iption="LOADPOINT: (werwrwrw)"><LoopCount InnerLoop="1" OuterLoop="1"><Monitored
Variables/><SetPhase><MonitoredVariables/><SetPhaseVariables/></SetPhase><WaitPh
ase><WaitingTime>0</WaitingTime><MonitoredVariables/></WaitPhase><MeasPhase><Mea
sPhaseLoopRun/><Manual>N</Manual><MeasPhaseVariables/></MeasPhase></LoopCount></
LoadPoint></SequenceData>
SQL> select xdburitype(:targetPath).getClob()
2 from dual
3 /
<SequenceData>
<Header>
<id>285062</id>
<TemplateName>1 dup</TemplateName>
<TemplateVersion>1</TemplateVersion>
<CreUser>AJB2KOR</CreUser>
<CreDate>02-SEP-05</CreDate>
</Header>
<Variables>
<SetPhaseVariables/>
<MeasPhaseVariables>
<MeasPhaseVariable>
<Name>TimeStamp</Name>
<Unit>Sec</Unit>
</MeasPhaseVariable>
</MeasPhaseVariables>
<MonitoredVariables>
<MonitoredVariable>
<Name>Svar b</Name>
<Unit>b</Unit>
</MonitoredVariable>
<MonitoredVariable>
<Name>Svar c</Name>
<Unit>c</Unit>
</MonitoredVariable>
</MonitoredVariables>
</Variables>
<LoadPoint LevelNumber="1" id="114103" Description="LOADPOINT: (werwrwrw)">
<LoopCount InnerLoop="1" OuterLoop="1">
<MonitoredVariables/>
<SetPhase>
<MonitoredVariables/>
<SetPhaseVariables/>
</SetPhase>
<WaitPhase>
<WaitingTime>0</WaitingTime>
<MonitoredVariabl
SQL>The problem is that we will assume the default namespace is the targetNamespace for SB XMLType, which is fine until you try and access a node that is in the 'noNamespace' namespace. Making use of that assumption is bad programming practice, you should always explicitly provide namespace declarations for all namespaces when querying XML.
BTW as you can see you can also get direct access to the contents of a resource using xdburitype. -
Resource_view based query??
Hello,
I searched the documentation (XML dev guide/XDK). I did not find info about
querying based on resource_view. I tried to expand the query
select extractvalue
value(ct),
'/xs:complexType/@name',
'xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xdb="http://xmlns.oracle.com/xdb"'
) COMPLEX_TYPE,
extractvalue
value(ct),
'/xs:complexType/@xdb:SQLType',
'xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xdb="http://xmlns.oracle.com/xdb"'
) SQL_TYPE
from resource_view,
table
xmlsequence
extract
res,
'/r:Resource/r:Contents/xs:schema/xs:complexType',
'xmlns:r="http://xmlns.oracle.com/xdb/XDBResource.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xdb="http://xmlns.oracle.com/xdb"'
) ct
where equals_path(res,'/sys/schemas/HL7_KSMITH/PORR_MT040001ALLMax') = 1
Where can I find much info in this area?
What are /@name and /@xdb:SQLType conventions in this query?
Do we able query resource_view based on xs:element, xs:sequence and xs:attribute etc for a registered schema?
Do we able query resource_view for all nodes of a registered schema?
Let me know your thought. I appreciate your help.
Regards
Ram IyerRam
@indicates that the Xpath references an attribute.
Eg in the case of the node
<xs:complexType name="LineItemType" xdb:SQLType="LINEITEM_T">
<xs:sequence>
<xs:element name="Description" type="DescriptionType" xdb:SQLName="DESCRIPTION"/>
<xs:element name="Part" type="PartType" xdb:SQLName="PART"/>
</xs:sequence>
<xs:attribute name="ItemNumber" type="xs:integer" xdb:SQLName="ITEMNUMBER" xdb:SQLType="NUMBER"/>
</xs:complexType>
@name will return the value LineItemType and @xdb:SQLType will return the value LINEITEM_T
This is basic XML Knowledge. -
Querying RESOURCE_VIEW using /Resource/XMLRef as key
Hi:
I am trying to query resource_view efficiently but instead of using equals_path or under_path which uses the domain index XDB.XDBHI_IDX using /Resource/XMLRef column.
For example, for a resource stored in a object relational table with a registered schema:
select extractValue(res,'/Resource/VCRUID'),any_path from resource_view
where extractValue(res,'/Resource/XMLRef')=make_ref(cms_docs,'27F5F5642ACA600AE040A8C00301464E');I am getting this execution plan:
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 152 | 9 (0)| 00:00:01 |
|* 1 | TABLE ACCESS BY INDEX ROWID| XDB$RESOURCE | 1 | 152 | 9 (0)| 00:00:01 |
|* 2 | DOMAIN INDEX | XDBHI_IDX | 1 | | | |
Predicate Information (identified by operation id):
1 - filter("P"."SYS_NC00024$"=MAKE_REF("CMS_DOCS",HEXTORAW('27F5F5642ACA600AE040A
8C00301464E') ))
2 - access("XDB"."UNDER_PATH"(SYS_MAKEXML('8758D485E6004793E034080020B242C6',734,
"XMLEXTRA","XMLDATA"),'/',9999)=1)
17 rows selected.For a query using sys_op_r2o operator, used to create the index XDB.XDB$RESOURCE_OID_INDEX on XDB$RESOURCE table:
select extractValue(res,'/Resource/VCRUID'),any_path from resource_view
where sys_op_r2o(extractValue(res,'/Resource/XMLRef'))=hextoraw('27F5F5642ACA600AE040A8C00301464E');I am getting a similar execution plan:
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 152 | 9 (0)| 00:00:01 |
|* 1 | TABLE ACCESS BY INDEX ROWID| XDB$RESOURCE | 1 | 152 | 9 (0)| 00:00:01 |
|* 2 | DOMAIN INDEX | XDBHI_IDX | 1 | | | |
Predicate Information (identified by operation id):
1 - filter("P"."SYS_NC00024$"=HEXTORAW('27F5F5642ACA600AE040A8C00301464E') )
2 - access("XDB"."UNDER_PATH"(SYS_MAKEXML('8758D485E6004793E034080020B242C6',734,
"XMLEXTRA","XMLDATA"),'/',9999)=1)
16 rows selected.What a I am doing wrong :(
Best regards, Marcelo.Hi:
Gathering the stats with null solve the problems, here the commands logged as XDB:
SQL> begin
2 DBMS_STATS.GATHER_TABLE_STATS (
3 ownname => 'XDB',
4 tabname => 'XDB$RESOURCE',
5 estimate_percent => null);
6 end;
7 /
SQL> begin
2 DBMS_STATS.GATHER_INDEX_STATS (
3 ownname => 'XDB',
4 INDNAME => 'XDBHI_IDX',
5 estimate_percent => null);
6 end;
7 /
SQL> begin
2 DBMS_STATS.GATHER_INDEX_STATS (
3 ownname => 'XDB',
4 INDNAME => 'XDB$RESOURCE_OID_INDEX',
5 estimate_percent => null);
6 end;
7 /Many thanks for the hint. Marcelo.
PD: I tested it on 11g beta 4 Linux 32 -
How to use xs:date() in an update query?
I cannot test xs:date attributes in an "update" query. In a "select" query, all work fine.
This is the sample schema:
<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid XML Studio 1.0.8.0 (http://www.liquid-technologies.com) -->
<xs:schema xmlns:tns="http://OracleTest" xmlns:xdb="http://xmlns.oracle.com/xdb" elementFormDefault="qualified" targetNamespace="http://OracleTest" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="MyComplexType">
<xs:sequence>
<xs:element minOccurs="0" name="FirstChild">
<xs:complexType>
<xs:attribute name="A" type="xs:string" />
<xs:attribute name="B" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="ID" type="xs:string" />
<xs:attribute name="DateAttr" type="xs:date" />
</xs:complexType>
<xs:element xdb:defaultTable="MyElement" name="MyElement" type="tns:MyComplexType" />
</xs:schema>
This is a sample XML document:
<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid XML Studio 1.0.8.0 (http://www.liquid-technologies.com) -->
<tns:MyElement ID="ID1" xmlns:tns="http://OracleTest" DateAttr="2008-03-14" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://OracleTest http://OracleTest.xsd">
<tns:FirstChild A="a" B="b" />
</tns:MyElement>
If I check the DateAttr attribute in a xquery, it works fine:
select xmlquery('declare default element namespace "http://OracleTest"; collection("/Testing")/MyElement[@DateAttr=xs:date(''2008-03-14'')]' returning content).getclobval() from dual
If I execute an update, like this:
UPDATE RESOURCE_VIEW SET RES = deleteXML(RES, '/oraxdbr:Resource/oraxdbr:Contents/Testing/MyElement[@DateAttr=xs:date(''2008-03-14'')]','xmlns:oraxdbr="http://xmlns.oracle.com/xdb/XDBResource.xsd" xmlns="http://OracleTest"')
WHERE equals_path(RES, '/Testing/test1.xml') = 1
I get the error:
SQL Error: ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00607: Invalid reference: 'date'.
31011. 00000 - "XML parsing failed"
Where is the problem?
Thank you!
MirkoHi,
Correct me if I'm wrong, but didn't xs:date() came with xpath 2.0?
deleteXML supports xpath 1.0 .
XMLQuery supports xpath 2.0.
That's why the error "Invalid reference: 'date'".
what function supports which version read Re: Which version of XPathAnts -
Extract binary data from resource_view (/Resrouce/Contents/binary)
Hi,
I've uploaded an image (png) as a resource using ftp. Now I'd like to extract the contents of the png file using the resource_view.
In my test the uploaded file was placed in /public/tmp and was named test.png.
Using the following query I tried to get the data:
SELECT extract(res,'/Resource/Contents/binary') AS content, extractValue(res,'/Resource/ContentType') AS ContentType
FROM resource_view
WHERE equals_path(res,'/public/tmp/test.png') = 1 The output was something like:
<binary xmlns="http://xmlns.oracle.com/xdb/XDBResource.xsd">89504E470D0A1A0A0000000D494844520000023E00000181080300000051984BA3000003
00504C5445000000BF000000BF00BFBF000000BFBF00BF00BFBFC0C0C0C0DCC0A4C8F0111111222222444444555555777777AAAAAADDDDDDEEEEEE00001100002200
00440000550000770000880000AA0000BB0000DD0000EE00110000220000440000550000770000880000AA0000DD0000EE0011000022000044000055000077000088...</binary>
image/pngThis looks a lot like ASCII :-) Following the XSD the binary data is hexBinary encoded.
My question is how to get the binary representation?
(oh, I'm running 11g on 64bits Windows)
Edited by: Tijink on Feb 2, 2009 3:20 AMFirst create a function to convert the hexvalues in the string to a blob:
create or replace function myclob2blob( p_clob in clob )
return blob
is
t_blob blob;
begin
dbms_lob.createtemporary( t_blob, true );
for i in 0 .. trunc( length( p_clob ) / 4000 )
loop
dbms_lob.append( t_blob, to_blob( hextoraw( to_char( substr( p_clob, i * 4000 + 1, 4000 ) ) ) ) );
end loop;
return t_blob;
end;
/And then query the binary data using this function
select extractvalue( rv.res, '/Resource/DisplayName' ) displayname
, extractvalue( rv.res, '/Resource/ContentType' ) ContentType
, myclob2blob( bin ) bin
from resource_view rv
, xmltable( '/' passing extract( rv.res, '/Resource/Contents/binary' )
columns bin clob path '/*'
where equals_path( rv.res, ''/public/tmp/test.png' ) = 1 Anton -
Error while running a query-Input for variable 'Posting Period is invalid
Hi All,
NOTE: This error is only cropping up when I input 12 in the posting period variable selection. If I put in any other value from 1-11 I am not getting any errors. Any ideas why this might be happening?
I am getting the following error when I try and run a query - "Input for variable 'Posting Period (Single entry, mandatory)' is invalid" - On further clicking on this error the message displayed is as follows -
Diagnosis
Variable Posting Period (Single Value Entry, Mandatory) is used as a lower limit (X) and an upper limit () in an interval selection. This limit has the value #.
System Response
Procedure
Enter a different value for variable Posting Period (Single Value Entry, Mandatory). If the value of the other limit is determined by another variable, you can change its value also.
Procedure for System AdministrationOK.
Well, if the variable is not used in any interval selection, then I would say "something happened to it".
I would make a copy of the query and run it to check if I get the same problem with period 12.
-> If not, something is wrong in the original query (you can proceed as below, if changes to original are permitted).
If so, then try removing the variable completely from the query and hardcode restriction to 12.
-> If problem still persists, I would have to do some thinking.
If problem is gone, then add the variable again. Check.
-> If problem is back, then the variable "is sick". Only quick thing to do, is to build an identical variable and use that one.
If problem also happens with the new variable, then it's time to share this experience with someone else and consider raising an OSS.
Good luck!
Jacob
P.S: what fisc year variant are you using?
Edited by: Jacob Jansen on Jan 25, 2010 8:36 PM -
Logical database in adhoc query
Hello All,
Can anyone tell me what is the logical database in adhoc query?Hi
When you create a query , you have to select an infoset. Infoset can be considered as a source from which data is populated in the Query Fields.
Infosets are created from Transaction SQ02.
There can be four methods through which an Infoset can become a source of data:
1. Table join ( By joining two or more tables from Data dictionary)
example: Joining tables PA0001 and PA0006 on Pernr to get a one resultant dataset
2. Direct read of Basis Table ( Like PA0001 as a source for data in Infoset )
3. Logical Database ( A Pre-written Program by SAP that extract data from clusters, tables taking care of authorizations and validity periods)
Example : Logical database PNP, PNPCE (Concurrent Employement),PCH ( LDB for Personnel Development Data)
Custom Logical DBs can be created in T_Code SE-36.
4. Data Retrieval by a Program ( Custom code written by ABAP developers which will collect and process data) . This program has a corresponding Structure in data dictionary and the fields of this structure will be used in query)
Reward Points, if helpful.
Regards
Waseem Imran -
Query help on Goods Receipt Query with AP Invoice
Looking for a little help on a query. I would like to list all the goods receipts for a given date range and then display the AP Invoice information (if its been copied to an AP Invoice). I think my problem is in my where clause, I plagerized an SAP query to show GR and AP from a PO as a start. SBO 2005 SP01. Any help would be great appreciated. Thanks
SELECT distinct 'GR',
D0.DocStatus,
D0.DocNum ,
D0.DocDate,
D0.DocDueDate,
D0.DocTotal,
'AP',
I0.DocStatus,
I0.DocNum ,
I0.DocDate,
I0.DocDueDate,
I0.DocTotal,
I0.PaidToDate
FROM
((OPDN D0 inner Join PDN1 D1 on D0.DocEntry = D1.DocEntry)
full outer join
(OPCH I0 inner join PCH1 I1 on I0.DocEntry = I1.DocEntry)
on (I1.BaseType=20 AND D1.DocEntry = I1.BaseEntry AND D1.LineNum=I1.BaseLine))
WHERE
(D1.BaseType=22 AND D1.DocDate>='[%0]' AND D1.DocDate<='[%1]')
OR (I1.BaseType=20 AND I1.BaseEntry IN
(SELECT Distinct DocEntry
FROM PDN1 WHERE BaseType=22 AND DocDate>='[%0]' AND DocDate<='[%1]'))Hi Dalen ,
I believe it is because of the condition
(D1.BaseType=22 AND D1.DocDate>='%0' AND D1.DocDate<='%1')
OR (I1.BaseType=20 AND I1.BaseEntry IN
(SELECT Distinct DocEntry FROM PDN1 WHERE PDN1.BaseType=22 AND DocDate>='%0' AND DocDate<='%1'))
Try changing
D1.BaseType=22 OR D1.DocDate>='%0' AND D1.DocDate<='%1
PDN1.BaseType=22 OR DocDate>='%0' AND DocDate<='%1'))
Lets see what would be the result . Lets have some fun with troubleshooting
See what would be the difference in the result .
Thank you
Bishal -
Can you check for data in one table or another but not both in one query?
I have a situation where I need to link two tables together but the data may be in another (archive) table or different records are in both but I want the latest record from either table:
ACCOUNT
AccountID Name
123 John Doe
124 Jane Donaldson
125 Harold Douglas
MARKETER_ACCOUNT
Key AccountID Marketer StartDate EndDate
1001 123 10526 8/3/2008 9/27/2009
1017 123 10987 9/28/2009 12/31/4712 (high date ~ which means currently with this marketer)
1023 124 10541 12/03/2010 12/31/4712
ARCHIVE
Key AccountID Marketer StartDate EndDate
1015 124 10526 8/3/2008 12/02/2010
1033 125 10987 01/01/2011 01/31/2012
So my query needs to return the following:
123 John Doe 10526 8/3/2008 9/27/2009
124 Jane Donaldson 10541 12/03/2010 12/31/4712 (this is the later of the two records for this account between archive and marketer_account tables)
125 Harold Douglas 10987 01/01/2011 01/31/2012 (he is only in archive, so get this record)
I'm unsure how to proceed in one query. Note that I am reading in possibly multiple accounts at a time and returning a collection back to .net
open CURSOR_ACCT
select AccountID
from
ACCOUNT A,
MARKETER_ACCOUNT M,
ARCHIVE R
where A.AccountID = nvl((select max(M.EndDate) from Marketer_account M2
where M2.AccountID = A.AccountID),
(select max(R.EndDate) from Archive R2
where R2.AccountID = A.AccountID)
and upper(A.Name) like parameter || '%'
<can you do a NVL like this? probably not... I want to be able to get the MAX record for that account off the MarketerACcount table OR the max record for that account off the Archive table, but not both>
(parameter could be "DO", so I return all names starting with DO...)if I understand your description I would assume that for John Dow we would expect the second row from marketer_account ("high date ~ which means currently with this marketer"). Here is a solution with analytic functions:
drop table account;
drop table marketer_account;
drop table marketer_account_archive;
create table account (
id number
, name varchar2(20)
insert into account values (123, 'John Doe');
insert into account values (124, 'Jane Donaldson');
insert into account values (125, 'Harold Douglas');
create table marketer_account (
key number
, AccountId number
, MktKey number
, FromDt date
, ToDate date
insert into marketer_account values (1001, 123, 10526, to_date('03.08.2008', 'dd.mm.yyyy'), to_date('27.09.2009', 'dd.mm.yyyy'));
insert into marketer_account values (1017, 123, 10987, to_date('28.09.2009', 'dd.mm.yyyy'), to_date('31.12.4712', 'dd.mm.yyyy'));
insert into marketer_account values (1023, 124, 10541, to_date('03.12.2010', 'dd.mm.yyyy'), to_date('31.12.4712', 'dd.mm.yyyy'));
create table marketer_account_archive (
key number
, AccountId number
, MktKey number
, FromDt date
, ToDate date
insert into marketer_account_archive values (1015, 124, 10526, to_date('03.08.2008', 'dd.mm.yyyy'), to_date('02.12.2010', 'dd.mm.yyyy'));
insert into marketer_account_archive values (1033, 125, 10987, to_date('01.01.2011', 'dd.mm.yyyy'), to_date('31.01.2012', 'dd.mm.yyyy'));
select key, AccountId, MktKey, FromDt, ToDate
, max(FromDt) over(partition by AccountId) max_FromDt
from marketer_account
union all
select key, AccountId, MktKey, FromDt, ToDate
, max(FromDt) over(partition by AccountId) max_FromDt
from marketer_account_archive;
with
basedata as (
select key, AccountId, MktKey, FromDt, ToDate
from marketer_account
union all
select key, AccountId, MktKey, FromDt, ToDate
from marketer_account_archive
basedata_with_max_intervals as (
select key, AccountId, MktKey, FromDt, ToDate
, row_number() over(partition by AccountId order by FromDt desc) FromDt_Rank
from basedata
filtered_basedata as (
select key, AccountId, MktKey, FromDt, ToDate from basedata_with_max_intervals where FromDt_Rank = 1
select a.id
, a.name
, b.MktKey
, b.FromDt
, b.ToDate
from account a
join filtered_basedata b
on (a.id = b.AccountId)
ID NAME MKTKEY FROMDT TODATE
123 John Doe 10987 28.09.2009 31.12.4712
124 Jane Donaldson 10541 03.12.2010 31.12.4712
125 Harold Douglas 10987 01.01.2011 31.01.2012
If your tables are big it could be necessary to do the filtering (according to your condition) in an early step (the first CTE).
Regards
Martin -
Query help : Query to get values SYSDATE-1 18:00 hrs to SYSDATE 08:00 hrs
Hi Team
I want the SQl query to get the data for the following comparison : -
Order Created is a Date Column , and i want to find out all the values from (SYSDATE-1) 18:00 hours to SYSDATE 08:00 hours
i.e.
(SYSDATE-1) 18:00:00 < Order.Created < SYSDATE 08:00:00.
RegardsHi, Rohit,
942281 wrote:
If i want the data in the below way i.e.
from (SYSDATE-1) 18:00 hours to SYSDATE 17:59 hours ---> (SYSDATE-1) 18:00:00 < Order.Created < SYSDATE 07:59:00.If you want to include rows from exactly 18:00:00 yesterday (but no earlier), and exclude rows from exatly 08:00:00 today (or later), then use:
WHERE ord_dtl.submit_dt >= TRUNC (SYSDATE) - (6 / 24)
AND ord_dtl.submit_dt < TRUNC (SYSDATE) + (8 / 24)
So can i use the below format : -
ord_dtl.submit_dt BETWEEN trunc(sysdate)-(6/24) and trunc(sysdate)+(7.59/24) . Please suggest . .59 hours is .59 * 60 * 60 = 2124 seconds (or .59 * 60 = 35.4 minutes), so the last time included in the range above is 07:35:24, not 07:59:59.
If you really, really want to use BETWEEN (which includes both end points), then you could do it with date arithmentic:
WHERE ord_dtl.submit_dt BETWEEN TRUNC (SYSDATE) - (6 / 24)
AND TRUNC (SYSDATE) + (8 / 24)
- (1 / (24 * 60 * 60))but it would be simpler and less error prone to use INTERVALs, as Karthick suggested earlier:
WHERE ord_dtl.submit_dt BETWEEN TRUNC (SYSDATE) - INTERVAL '6' HOUR
AND TRUNC (SYSDATE) + INTERVAL '8' HOUR
- INTERVAL '1' SECONDEdited by: Frank Kulash on Apr 17, 2013 9:36 AM
Edited by: Frank Kulash on Apr 17, 2013 11:56 AM
Changed "- (8 /24)" to "+ (8 /24)" in first code fragment (after Blushadown, below) -
Query help, subtract two query parts
Hi,
I am beginner of PL/SQL and have a problem I couldn’t solve:
Table (op_list):
Item - Amount - Status
Item1 - 10 - in
Item2 - 12 - in
Item3 - 7 - in
Item1 - 2 - out
Item2 - 3 - out
Item1 - 1 - dmg
Item3 - 3 - out
Item1 - 2 - out
Item2 - 5 - out
Item2 - 2 - in
Item3 - 1 - exp
Would like to get result of query (subtract amount of 'out/dmg/exp' from 'in' ):
Item - Amount left
Item1 - 5
Item2 - 6
Item3 - 3
I wrote code that returns sum of all incoming items and sum all out/dmg/exp items, but couldn’t solve how to subtract one part of querry from another. Or maybe there is a better way. Also worried what happens if there is no 'out/dmg/exp' only 'in'
select item.name, sum(op_list.item_amount)
from op_list
inner join item
on op_list.item = item.item_id
where op_list.status = 'in'
group by item.name
union
select item.name, sum(op_list.item_amount)
from op_list
inner join item
on op_list.item = item.item_id
where op_list.status = 'out'
or op_list.status = 'dmg'
or op_list.status = 'exp'
group by item.name
Return:
Item1 - 10 [10 in]
Item1 - 5 [2+1+2]
Item2 - 14 [12+2]
Item3 - 7
Item3 - 4 [3+1]
Thanks in advanceHi,
We can also use simple inline views to get what we need.
select a.item,a.amount-b.amount Balance from
(select item,sum(amount) Amount from op_list
where status = 'in'
group by item) a,
(select item,sum(amount) Amount from op_list
where status in ('out','dmg','exp')
group by item) b
where
a.item=b.item
order by item;
ITEM BALANCE
Item1 5
Item2 6
Item3 3Regards,
Prazy -
Query help: query to return column that represents multiple rows
I have a table with a name and location column. The same name can occur multiple times with any arbitrary location, i.e. duplicates are allowed.
I need a query to find all names that occur in both of two separate locations.
For example,
bob usa
bob mexico
dot mexico
dot europe
hal usa
hal europe
sal usa
sal mexico
The query in question, if given the locations usa and mexico, would return bob and sal.
Thanks for any help or advice,
-=beekyHow about this?
SELECT NAME
FROM <LOCATIONS_TABLE>
WHERE LOCATION IN ('usa','mexico')
GROUP BY NAME
HAVING COUNT(DISTINCT LOCATION) >= 2Results:
SQL> WITH person_locations AS
2 (
3 SELECT 'bob' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
4 SELECT 'bob' AS NAME, 'Mexico' AS LOCATION FROM DUAL UNION ALL
5 SELECT 'dot' AS NAME, 'Mexico' AS LOCATION FROM DUAL UNION ALL
6 SELECT 'dot' AS NAME, 'Europe' AS LOCATION FROM DUAL UNION ALL
7 SELECT 'hal' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
8 SELECT 'hal' AS NAME, 'Europe' AS LOCATION FROM DUAL UNION ALL
9 SELECT 'sal' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
10 SELECT 'sal' AS NAME, 'Mexico' AS LOCATION FROM DUAL
11 )
12 SELECT NAME
13 FROM person_locations
14 WHERE LOCATION IN ('USA','Mexico')
15 GROUP BY NAME
16 HAVING COUNT(DISTINCT LOCATION) >= 2
17 /
NAM
bob
salHTH!
Edited by: Centinul on Oct 15, 2009 2:25 PM
Added sample results. -
QUERY HELP!!! trying to create a query
i'm creating a summary report
i have a table with sale dates
for example i have a table tab_1 and column saleDate as
saleDat
1923
1936
1945
2003
2005
saleDate contains years and there are some missing years where no sale
was made
My report has to display years starting from earliest year
so i have to create a query that starts with 1923
but the problem is that I have to have years that are not in table.
for example i have to display years 1924 which is not in table
so the part of report has to look like
1923 blah blah summary.........
1924 "
1925
1926
2005
2006
upto current year (2006 may not be in the table, but i have to display)
i just need to know the query that can query all the years starting from
the ealiest saleDate to current year
thanks in advancePlease write the query in the following form:
SELECT a.year, --- place other columns from your table.
FROM (SELECT (:start_num + rownum) year
FROM all_tab_columns
WHERE :start_num + rownum <= :end_num) a,
tab_1 b
WHERE a.year = b.saleDat(+);
Note:
1) if your start year and end year are 1923 and 2006. Then input as below:
:start_num = 1922
:end_num = 2006
2) Since for some of the years (1924 etc) may not be there in your so you may need to use NVL to print proper indicators.
3) If you have more than one record in tab_1 for a particular year then group them based year and then use it.
Hope this helps.
- Saumen.
Maybe you are looking for
-
Lost my iphone 5 and want your help to get it. Have my apple id for 2 devices
Lost my iphone 5 and need your help please since i downloaded find my iphone and can only locate my ipad
-
How to test system down in XI? Kindly help!
Hi Experts, I have a JMS -> XI ->SAP R/3 scenario. If the remote SAP R/3 is down then I have to trigger an alert. In the runtime workbench, i have configured the alert in Alert Configuration. In this I have given the alert category, r
-
Hi All, As per my knowledge, Purchase requision is a internal document and hence printing option is not available in standard SAP. However due to some legal and complice requirement, my client want to print all the purchase requisition. I know, we ne
-
Standard Sampler Loop Points a la SoundForge
Hi, I work doing audio for video games, and the tools we have available at a company I've recently started working for allow the software to read standard sampler-compatable loop metadata from audio files to be used in game. I'm wondering if there is
-
I try now for hours to export an MXF op1a with 8 channel audio from Premiere CC2014.1 and with AME 2014.1 to copy the file on my XDCam drive u1 to a disc. The file is always asynchronous after 20 or 30 minutes. The project is synchronous and also ot