Xmltable fn:string-join
create table emp (doc XMLtype);
insert into emp values(
xmltype('<dept bldg="114">
<employee id="903">
<name>
<first>Mary</first>
<last>Jones</last>
</name>
<office>415</office>
<phone>905-403-6112</phone>
<phone>647-504-4546</phone>
<salary currency="USD">64000</salary>
</employee>
</dept>'));
I need the output to be
Mary Jones 905-403-6112,647-504-4546
I tried
SELECT X.* FROM emp ,
XMLTABLE ('$d/dept/employee' passing doc as "d"
COLUMNS
first VARCHAR2(25) PATH 'name/first',
last VARCHAR2(25) PATH 'name/last',
phone VARCHAR2(100) PATH 'fn:string-join(phone/text(),",")'
) AS X
and received error
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00601: Invalid token in: '/*/fn:string-join(phone/text(),",")'
please advise. thanks.
SCOTT@soti_10> with emp as(
2 select xmltype(
3 '
4 <dept>
5 <employee id="901">
6 <name>
7 <first>John</first>
8 <last>Doe</last>
9 </name>
10 </employee>
11 <employee id="902">
12 <name>
13 <first>Peter</first>
14 <last>Pan</last>
15 </name>
16 <phone>905-416-5004</phone>
17 </employee>
18 <employee id="903">
19 <name>
20 <first>Mary</first>
21 <last>Jones</last>
22 </name>
23 <phone>905-403-6112</phone>
24 <phone>647-504-4546</phone>
25 </employee>
26 </dept>
27 '
28 ) as doc
29 from dual
30 )
31 SELECT X.*
32 FROM emp ,
33 XMLTABLE (
34 'for $e in $d/dept/employee,
35 (: $pi - index of the current phone element.
36 If there is no phone elements at all then $pi = 0, otherwise $pi > 0 :)
37 $pi in (0 to fn:count($e/phone))[. > 0 or fn:last() = 1]
38 return <e>
39 {$e/name}
40 {$e/phone[$pi]}
41 </e>'
42 passing doc as "d"
43 COLUMNS first VARCHAR2(25) PATH 'name/first',
44 last VARCHAR2(25) PATH 'name/last',
45 phone VARCHAR2(100) PATH 'phone'
46 ) AS X
47 ;
FIRST LAST PHONE
John Doe
Peter Pan 905-416-5004
Mary Jones 905-403-6112
Mary Jones 647-504-4546Regards,
Dima
Similar Messages
-
Xquery concat / string-join / replace
Hi, I am a newbie on Xquery.
And I need some help on a problem I been having.
My in data is three digit numbers (ex. "123" "321" "213" etc). And I need to separate this with a comma ",". The problem is how do I do this if the input is only one item?, and second how do I not
put a "," on the last item?
I have tried a for-loop where a concat my string with with "," but the result is "123, 321, 213,". I do not want the last comma. And the spaces is not real whitespaces. I don't know where this comes from, the can not be removed or be used to
replace them with a comma (which would be the simplest way to solve my problem) but doesn't work.
for $Something in $Something/ns0:Something
return
fn:concat(data($Something)," ",",").
This returns "123, 321, 213,".I have solved it.
string-join(( data($Something/SomethingElse)),",")
Thanks. -
HI,
I tested the following query in 10gr2 and 11gr2
SELECT XMLQuery('string-join("a","b")'
returning content) as output
FROM DUAL;
Result => a and NOT ab.
Any idea why this result?
Thanks,
HenkSome doc reading might help : fn:string-join()
The function concatenates a sequence of strings (first arg) into a single string using the second arg as separator.
In your example, the sequence consists in a single item so the result is the item itself.
Are you looking for fn:concat() ?
SQL> select xmlquery('concat("a","b")' returning content)
2 from dual;
XMLQUERY('CONCAT("A","B")'RETU
ab -
String m="Hello"
Is there any difference between
m=m+" Java";
and
m=m.concat(" Java");There must be some difference I guess, but not sure where.
Can anyone explain please?Another interview question?
Adding strings with + gets compiled into instantiations and invocations of StringBuffer or StringBuilder, invoking append() on it, and then calling toString on it. That is, unless the stuff you're adding is all immutable at compile time, in which case the concatenation happens at compile time and the class just has a big string.
.concat(), I presume, creates a new String object right there and doesn't get transmogrified into anything else at compile time.
As such, if you're doing a lot of string concatenations, or if the concatenations are built with immutable values, it's more efficient to use +. On the other hand if you're doing a single concatenation using a variable, .concat() is probably more efficient.
But these are just educated guesses. Try experimenting with both, disassembling the class files with javap to see what happened, looking at the source code, etc. -
Hi,
I am looking at an XML file/feed, and within it there are paragraphs and page breaks (<para>,
). When I'm extracting the data into a varchar2 field, i want to preserve the paragraph/break structure...
e.g.
SELECT text_col
FROM XMLTABLE('/'
PASSING (xmltype('<para>This is paragraph 1.<br/>This is p1, line 1.<br/>This is p1, line 2.</para>'))
COLUMNS text_col VARCHAR2(1000) PATH '/'
);gives
This is paragraph 1.This is p1, line 1.This is p1, line 2.What I'm after is:
This is paragraph 1.
This is p1, line 1.
This is p1, line 2.Is this achievable?
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit
Thanks.Hi,
On 11g, I would use this :
SQL> select text
2 from xmltable(
3 'string-join(
4 for $i in /para/node()
5 return
6 typeswitch ($i)
7 case text() return string($i)
8 case element(br) return "&#xA;"
9 default return ""
10 , "")'
11 passing xmlparse(content '<para>Line1<br/>Line2<br/>Line3</para>')
12 columns text varchar2(2000) path '.'
13 )
14 ;
TEXT
Line1
Line2
Line3
but I'm not sure it works on your version. You can try though.
Another solution would be :
SQL> select utl_i18n.unescape_reference(replace(x.text.getstringval(), '<br/>', '&#xA;')) as text
2 from xmltable('/para'
3 passing xmltype('<para>Line1&Line1.1<br/>Line2<br/>Line3</para>')
4 columns text xmltype path 'node()'
5 ) x
6 ;
TEXT
Line1&Line1.1
Line2
Line3 -
XML info: D:\XMLDATA\mytable.xml
create directory XML_dir as 'D:\XMLDATA';
<INFO>
<Column_Name>Col1</Column_Name>
<Data_Type>Char(1)</Data_Type>
</INFO>
<INFO>
<Column_Name>Col2</Column_Name>
<Data_Type>VARCHAR2(50)</Data_Type>
</INFO>
I need to create a table based on the XML data.
Create Table mytable
Col1 Char(1),
Col2 Varchar2(50)
How to read and execute the xml data to create a table.
Thanks!Something like this :
SQL> declare
2
3 v_xmlinfo clob;
4 v_ddl varchar2(32767) := 'CREATE TABLE mytable ( #COLUMN_LIST# )';
5 v_column_list varchar2(4000);
6
7 begin
8
9 v_xmlinfo := dbms_xslprocessor.read2clob('TEST_DIR', 'info.xml');
10
11 select column_list
12 into v_column_list
13 from xmltable(
14 'string-join(
15 for $i in /INFO
16 return concat($i/Column_Name, " ", $i/Data_Type)
17 , ", "
18 )'
19 passing xmlparse(content v_xmlinfo)
20 columns column_list varchar2(4000) path '.'
21 ) ;
22
23
24 v_ddl := replace(v_ddl, '#COLUMN_LIST#', v_column_list);
25 --dbms_output.put_line(v_ddl);
26
27 execute immediate v_ddl;
28
29 end;
30 /
PL/SQL procedure successfully completed
SQL> select * from mytable;
COL1 COL2 -
Looping through a refcursor to get list of dates as a string
hi,
i have a simple procedure which gives me list of from dates and to dates
i need to get the dates a comma separated dates
i am not sure if this can be done directly by doing a for loop on the refcursor or i have to fetch it into a record/array and then concatenate with comma or is there anything else that can be done.
i tried out some stuff like below
ps help me out
the procedure that retruns the list of dates is
CREATE OR REPLACE procedure SALUSER.prm_sp_rpt_payslip_lop_dates(p_empid in int,p_tran_year in int,p_tran_month in integer,o_dates out sys_refcursor)
as
begin
open o_dates for select to_char(PHL_LOP_FROM,'DD-Mon-YYYY'),to_char(PHL_LOP_TO,'DD-Mon-yyyy')
from prm_h_lop
where phl_emp_id=p_empid
and phl_tran_year=p_tran_year
and phl_Tran_month=p_tran_month;
end;
/i need my o/p as
dates :<date1>,<date2>...etcregards,Maybe sth. like
SQL> var cur refcursor
SQL> declare
cr sys_refcursor;
procedure prm_sp_rpt_payslip_lop_dates (cr in out sys_refcursor)
as
begin
open cr for select hiredate from emp;
end prm_sp_rpt_payslip_lop_dates;
begin
prm_sp_rpt_payslip_lop_dates(cr);
open :cur for select 'Dates: ' || column_value dates from xmltable('string-join(//text(), ", ")' passing xmltype(cr));
end;
PL/SQL procedure successfully completed.
SQL> print cur
DATES
Dates: 17-Dec-1980, 20-Feb-1981, 22-Feb-1981, 02-Apr-1981, 28-Sep-1981, 01-May-1
981, 09-Jun-1981, 19-Apr-1987, 17-Nov-1981, 08-Sep-1981, 23-May-1987, 03-Dec-198
1, 03-Dec-1981, 23-Jan-1982
1 row selected. -
LabView String StartsWith functionality like in C#?
Hello all,
in C# (.NET) there is a good class: String
There it is possible e.g. to get information, if the string startswith a special substring.
Is there such possibility in LabView? Is there such LabView vi, which offers this functionality? (Some snippet?)
Why I am asking:
I want to create a switch/case-block (case-structure) in labview for this code:
if(string.startswith("XYZ")) step into case1
else if(string.startswith("DEF")) step into case2
BTW:
It would be so nice if anybody could create polymorphic VI with these functions:
(from C# string class)
public object Clone();
public static int Compare(string strA, string strB);
public static int Compare(string strA, string strB, bool ignoreCase);
public static int Compare(string strA, string strB, StringComparison comparisonType);
public static int Compare(string strA, string strB, bool ignoreCase, CultureInfo culture);
public static int Compare(string strA, string strB, CultureInfo culture, CompareOptions options);
public static int Compare(string strA, int indexA, string strB, int indexB, int length);
public static int Compare(string strA, int indexA, string strB, int indexB, int length, bool ignoreCase);
public static int Compare(string strA, int indexA, string strB, int indexB, int length, StringComparison comparisonType);
public static int Compare(string strA, int indexA, string strB, int indexB, int length, bool ignoreCase, CultureInfo culture);
public static int Compare(string strA, int indexA, string strB, int indexB, int length, CultureInfo culture, CompareOptions options);
public static int CompareOrdinal(string strA, string strB);
public static int CompareOrdinal(string strA, int indexA, string strB, int indexB, int length);
public int CompareTo(object value);
public int CompareTo(string strB);
public static string Concat(IEnumerable<string> values);
public static string Concat<T>(IEnumerable<T> values);
public static string Concat(object arg0);
public static string Concat(params object[] args);
public static string Concat(params string[] values);
public static string Concat(object arg0, object arg1);
public static string Concat(string str0, string str1);
public static string Concat(object arg0, object arg1, object arg2);
public static string Concat(string str0, string str1, string str2);
public static string Concat(object arg0, object arg1, object arg2, object arg3);
public static string Concat(string str0, string str1, string str2, string str3);
public bool Contains(string value);
public static string Copy(string str);
public void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count);
public bool EndsWith(string value);
public bool EndsWith(string value, StringComparison comparisonType);
public bool EndsWith(string value, bool ignoreCase, CultureInfo culture);
public override bool Equals(object obj);
public bool Equals(string value);
public static bool Equals(string a, string b);
public bool Equals(string value, StringComparison comparisonType);
public static bool Equals(string a, string b, StringComparison comparisonType);
public static string Format(string format, object arg0);
public static string Format(string format, params object[] args);
public static string Format(IFormatProvider provider, string format, params object[] args);
public static string Format(string format, object arg0, object arg1);
public static string Format(string format, object arg0, object arg1, object arg2);
public CharEnumerator GetEnumerator();
public override int GetHashCode();
public TypeCode GetTypeCode();
public int IndexOf(char value);
public int IndexOf(string value);
public int IndexOf(char value, int startIndex);
public int IndexOf(string value, int startIndex);
public int IndexOf(string value, StringComparison comparisonType);
public int IndexOf(char value, int startIndex, int count);
public int IndexOf(string value, int startIndex, int count);
public int IndexOf(string value, int startIndex, StringComparison comparisonType);
public int IndexOf(string value, int startIndex, int count, StringComparison comparisonType);
public int IndexOfAny(char[] anyOf);
public int IndexOfAny(char[] anyOf, int startIndex);
public int IndexOfAny(char[] anyOf, int startIndex, int count);
public string Insert(int startIndex, string value);
public static string Intern(string str);
public static string IsInterned(string str);
public bool IsNormalized();
public bool IsNormalized(NormalizationForm normalizationForm);
public static bool IsNullOrEmpty(string value);
public static bool IsNullOrWhiteSpace(string value);
public static string Join(string separator, IEnumerable<string> values);
public static string Join<T>(string separator, IEnumerable<T> values);
public static string Join(string separator, params object[] values);
public static string Join(string separator, params string[] value);
public static string Join(string separator, string[] value, int startIndex, int count);
public int LastIndexOf(char value);
public int LastIndexOf(string value);
public int LastIndexOf(char value, int startIndex);
public int LastIndexOf(string value, int startIndex);
public int LastIndexOf(string value, StringComparison comparisonType);
public int LastIndexOf(char value, int startIndex, int count);
public int LastIndexOf(string value, int startIndex, int count);
public int LastIndexOf(string value, int startIndex, StringComparison comparisonType);
public int LastIndexOf(string value, int startIndex, int count, StringComparison comparisonType);
public int LastIndexOfAny(char[] anyOf);
public int LastIndexOfAny(char[] anyOf, int startIndex);
public int LastIndexOfAny(char[] anyOf, int startIndex, int count);
public string Normalize();
public string Normalize(NormalizationForm normalizationForm);
public string PadLeft(int totalWidth);
public string PadLeft(int totalWidth, char paddingChar);
public string PadRight(int totalWidth);
public string PadRight(int totalWidth, char paddingChar);
public string Remove(int startIndex);
public string Remove(int startIndex, int count);
public string Replace(char oldChar, char newChar);
public string Replace(string oldValue, string newValue);
public string[] Split(params char[] separator);
public string[] Split(char[] separator, int count);
public string[] Split(char[] separator, StringSplitOptions options);
public string[] Split(string[] separator, StringSplitOptions options);
public string[] Split(char[] separator, int count, StringSplitOptions options);
public string[] Split(string[] separator, int count, StringSplitOptions options);
public bool StartsWith(string value);
public bool StartsWith(string value, StringComparison comparisonType);
public bool StartsWith(string value, bool ignoreCase, CultureInfo culture);
public string Substring(int startIndex);
public string Substring(int startIndex, int length);
public char[] ToCharArray();
public char[] ToCharArray(int startIndex, int length);
public string ToLower();
public string ToLower(CultureInfo culture);
public string ToLowerInvariant();
public override string ToString();
public string ToString(IFormatProvider provider);
public string ToUpper();
public string ToUpper(CultureInfo culture);
public string ToUpperInvariant();
public string Trim();
public string Trim(params char[] trimChars);
public string TrimEnd(params char[] trimChars);
public string TrimStart(params char[] trimChars);
Eugen Wiebe
Bernstein AG
CLAD - Certified LabView Associate Developer
Solved!
Go to Solution.Why I am asking:
I want to create a switch/case-block (case-structure) in labview for this code:
This can be done already with the case structure, you can do simple parsing in the case selector, which takes a string as an input.
Type into the case for first case "XYZ....XYZ~"
Type into next case "DEF...DEF~"
Next case is empty string, default.
How does this work:
The "XYZ...XYZ~" matches all strings that start with XYZ and have any ascii value after the ~ is the highest printable 7bit ascii value so this catches all other characters.
Option 2 is parse (there are very good reg expression vi in the string palette) the string and create interger value if a matched then habdle the unique integers in the case structure.
There are so many ways to do it without making a wrapper for the .net string class, I provided a few quick methods
Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA -
Get Artists and show Artist Name as string
Hi
I'm using VS2013, EF6, WPF
I have tables Media, MediaArtists, Artists
MediaArtist is a bridge table that use MediaId and ArtistId. it's mean that every Media has more Artists.
dbContext db = new dbContext();
mediumDataGrid.ItemsSource = db.Media.Select(m => new{
m.MediaId,
m.Title,
m.LastPlayedDate,
????m.MediaArtists.Select(a => Artist)????
}).ToList();
I want to get the Artists "Name" and show in gridview as Artist1, Artist2, Artist3
can you please let me know how do that?
thanksHello Zorig,
It seems that you are trying to perform a group by comma list in linq, if you data is not larger, you could use the LINQ2Object as below:
var result = db.X.ToList().Select(x => new { XID = x.XID, XName = x.XName, YNames = string.Join(",", x.Y.Select(y => y.XName)) }).ToList();
If data is large, you could check the workaround from Emran Hussain:
http://stackoverflow.com/a/25676673
Or to use store produce for a complex query instead.
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Hello,
I need help in removing duplicates from a string that contains years and "-". Example: 1988-1997-2000-2013-1998-1965-1997-1899
I know this can be done in regular expressions but have no experience in this subject.
select REGEXP_REPLACE(.....) from dual;
Thank youodie_63 wrote:
For "large" strings, XQuery evaluation happens to be faster
But model solution beats them both and also preserves the order:
set timing on
set serveroutput on
declare
v_result varchar2(4000);
v_list varchar2(4000) := '1988-1997-2000-2013-1998-1965-1997-1899-1997-2000-2013-1998-1965-1997-1899-1997-2000-2013-1998-1965-1997-1899';
begin
for i in 1 .. 50000 loop
select /*+ no_xmlquery_rewrite */
xmlcast(
xmlquery(
'string-join(distinct-values(ora:tokenize($list, "-")[.]), "-")'
passing v_list || '-' as "list"
returning content
as varchar2(4000)
into v_result
from dual;
end loop;
dbms_output.put_line(v_result);
end;
1899-1965-1988-1997-1998-2000-2013
PL/SQL procedure successfully completed.
Elapsed: 00:00:15.31
declare
v_result varchar2(4000);
v_list varchar2(4000) := '1988-1997-2000-2013-1998-1965-1997-1899-1997-2000-2013-1998-1965-1997-1899-1997-2000-2013-1998-1965-1997-1899';
begin
for i in 1 .. 50000 loop
select listagg(str, '-') within group (order by null)
into v_result
from (
select distinct regexp_substr(v_list, '[^-]+', 1, level) str
from dual
connect by level <= regexp_count(v_list, '-') + 1
end loop;
dbms_output.put_line(v_result);
end;
1899-1965-1988-1997-1998-2000-2013
PL/SQL procedure successfully completed.
Elapsed: 00:00:26.06
declare
v_result varchar2(4000);
v_list varchar2(4000) := '1988-1997-2000-2013-1998-1965-1997-1899-1997-2000-2013-1998-1965-1997-1899-1997-2000-2013-1998-1965-1997-1899';
begin
for i in 1 .. 50000 loop
select ltrim(newstr,'-')
into v_result
from dual
model
dimension by(0 d)
measures(
'-' || replace(v_list,'-','--') || '-' workarea,
cast(null as varchar2(4000)) element,
cast(null as varchar2(4000)) newstr
rules iterate(1e6) until(workarea[0] is null)
element[0] = substr(workarea[0],1,instr(workarea[0],'-',2)),
newstr[0] = newstr[0] || rtrim(element[0],'-'),
workarea[0] = replace(workarea[0],element[0])
end loop;
dbms_output.put_line(v_result);
end;
1988-1997-2000-2013-1998-1965-1899
PL/SQL procedure successfully completed.
Elapsed: 00:00:11.94
SQL>
SY. -
Calculate number in string?
Hi Devleoper,
string result = "Add={1,1},{2,4},{5,5}";
how to add two integers value in a string result as above if possible ? e.g
1 + 1 = 2
2 + 4 = 6
5 + 5 = 10
Any Idea?
ThanksHere is another sample solution for your problem. Be aware that it does not contain error handling.
I assume that you are expecting input like "operation={arg1,arg2...},{arg1,arg2,...}":
string result = "Add={1,1},{2,4},{5,5}";
string[] sp1 = result.Split('=');
switch(sp1[0])
case "Add":
MatchCollection mc = Regex.Matches(sp1[1], @"\{.*?\}"); // split string for - {..} {..} {..} ...
foreach(Match m in mc)
List<int> argumetnts = m.Value.Trim('{', '}').Split(',').Select(a => int.Parse(a)).ToList();
Console.WriteLine("{0} = {1}", string.Join(" + ", argumetnts.Select(a => a.ToString())), argumetnts.Sum());
break;
//case ...
//other operations
default:
//Error handling
break; -
String[] args fights String... args
Hi,
I thought this error message was a joke at first, but it's for real:
Arrayz.java:15: cannot declare both in(java.lang.String,java.lang.String[]) and in(java.lang.String,java.lang.String...) in krc.utilz.ArrayzPlease, would anyone care to offer an opinion as to WHY the compiler does not differentiate between String[] args and String... args. Obviously String... args is implemented internally as String[] args, but that really shouldn't effect the interface... and if they are internally equivalent then wny not allow a syntax that effectively declares both in one... It's just that I would have thought it was possible (and desirable) for the compiler & JVM to do the required parameter matching for both definitions... in my mind the calling parameter list of (String, String, String) is distinct from (String, String[]) ... Or does java (like C/C++) internally not differentiate between the types reference-to-String and reference-to-array-of-Strings and reference-to-array-of-array-of-Strings ????
I'm just a tad miffed about this... I mean, it's easy to work around in at least a dozen simple ways, it's just that the compiler didn't do what I expected it to do, so it should just pull it's socks up, and, well, you know, Work!
Here's the code... complete with compiler error.
package krc.utilz.stringz;
public class Arrayz
* returns true if the given value is in the args list, else false.
* @param value - the value to seek
* @param args... - variable number of String arguments to look in
public static boolean in(String value, String... args) {
for(String a : args) if(value.equals(a)) return true;
return false;
//Arrayz.java:15: cannot declare both in(java.lang.String,java.lang.String[]) and in(java.lang.String,java.lang.String...) in krc.utilz.Arrayz
public static boolean in(String value, String[] array) {
for(String s : array) if(value.equals(s)) return true;
return false;
}Thanx all. Keith.I didn't know that. Cool!
package forums;
class VarArgsTester
public static String join(String FS, String... args) {
if (args==null) return null;
if (args.length==0) return "";
StringBuffer sb = new StringBuffer(args[0]);
for (int i=1; i<args.length; i++) {
sb.append(FS+args);
return sb.toString();
public static void main(String[] args) {
System.out.println(join(" ", "Your", "momma", "wears", "army", "boots"));
String[] words = {"But", "she", "looks", "very", "nice", "in", "them"};
System.out.println(join(" ", words));
I was expecting a compiler error from the line[
pre]System.out.println(join(" ", words));
Thanks ~Puce. -
Hi all,
I have a simple query which concatenates three columns together, separated by a comma. Something like...
SELECT FK_COMMUNITY||', '||FK_BUILDING_ID ||', '|| FK_ROOM_TYPE AS preference
FROM preferences;
The issue is that not all these columns are populated, in some cases they all have data and in some cases the data is missing (NULL).
The problem is the output leaves the formatting off example:
PREFERENCE
Avery Hill, ,
, TUD,
, DEV,
, DEV,
, CUT,
, CUT,
, BIN, BINSTA
, MMA, MMASTE
, BIN,
, MMS, MMSSTU
Any help would be appreciated. Many thanksSo in general you need to:I'd prefer to use XMLCAST (where it is supported) - or maybe sometimes EXTRACTVALUE :
SQL> set define off
SQL> with prefences as (
select 0 as row_id, 'Avery & Hill' as fk_community, null as fk_building_id , null as fk_room_type from dual
union select 1, null, 'TUD', null from dual
union select 2, null, 'DEV', null from dual
union select 3, null, 'DEV', null from dual
union select 4, null, 'CUT', null from dual
union select 5, null, 'CUT', null from dual
union select 6, null, 'BIN', 'BINSTA' from dual
union select 7, null, '<MMA>', 'MMASTE' from dual
union select 8, null, 'BIN', null from dual
union select 9, null, 'MMS', 'MMSSTU' from dual
select xmlcast(xmlquery('string-join(./*,",")' passing xmlforest(fk_community, fk_building_id, fk_room_type) returning content) as varchar2(100)) str
from prefences
STR
Avery & Hill
TUD
DEV
DEV
CUT
CUT
BIN,BINSTA
<MMA>,MMASTE
BIN
MMS,MMSSTU
10 rows selected. -
I would like to convert XML in to a simple table structure, with:
- 1 row per tag
- a tag_id for each tag
- a parent tag_id for each tag
- the attribute for each tag
E.g. for the following
DROP TABLE test_xml;
CREATE TABLE test_xml OF XMLType;
INSERT INTO test_xml
VALUES
(XMLType
('<tag1>
<tag2_1>
<tag2_1_1 Value1="A">
<tag2_1_1_1 Value2="B" Value3="C"/>
</tag2_1_1>
<tag2_1_2 Value1="D">
<tag2_1_2_1 Value2="E" Value3="F"/>
</tag2_1_2>
<tag2_1_3 Value1="G">
<tag2_1_3_1 Value2="H" Value3="I"/>
</tag2_1_3>
<tag2_1_4 Value1="J">
<tag2_1_4_1 Value2="K" Value3="L"/>
</tag2_1_4>
</tag2_1>
<tag2_2>
<tag2_2_1 Value4="M"/>
</tag2_2>
<tag2_3>
<tag2_3_1 Value5="N">
<tag2_3_1_1>
<tag2_3_1_1_1>
<tag2_3_1_1_1_1 Value6="O" Value7="P">
<tag2_3_1_1_1_1_1 Value2="Q" Value3="R"/>
</tag2_3_1_1_1_1>
</tag2_3_1_1_1>
</tag2_3_1_1>
<tag2_3_1_2>
<tag2_3_1_2_1 Value8="S" Value9="T"/>
</tag2_3_1_2>
</tag2_3_1>
</tag2_3>
</tag1>'
set long 1000
select * from test_xml;
SYS_NC_ROWINFO$
<tag1>
<tag2_1>
<tag2_1_1 Value1="A">
<tag2_1_1_1 Value2="B" Value3="C"/>
</tag2_1_1>
<tag2_1_2 Value1="D">
<tag2_1_2_1 Value2="E" Value3="F"/>
</tag2_1_2>
<tag2_1_3 Value1="G">
<tag2_1_3_1 Value2="H" Value3="I"/>
</tag2_1_3>
<tag2_1_4 Value1="J">
<tag2_1_4_1 Value2="K" Value3="L"/>
</tag2_1_4>
</tag2_1>
<tag2_2>
<tag2_2_1 Value4="M"/>
</tag2_2>
<tag2_3>
<tag2_3_1 Value5="N">
<tag2_3_1_1>
<tag2_3_1_1_1>
<tag2_3_1_1_1_1 Value6="O" Value7="P">
<tag2_3_1_1_1_1_1 Value2="Q" Value3="R"/>
</tag2_3_1_1_1_1>
</tag2_3_1_1_1>
</tag2_3_1_1>
<tag2_3_1_2>
<tag2_3_1_2_1 Value8="S" Value9="T"/>
</tag2_3_1_2>
</tag2_3_1>
</tag2_3>
</tag1>I want to generate the following output
tag_id parent_tag_id tag_name attribute
1 tag1
2 1 tag2_1
3 2 tag2_1_1 Value1="A"
4 3 tag2_1_1_1 Value2="B" Value3="C"
5 2 tag2_1_2 Value1="D"
6 5 tag2_1_2_1 Value2="E" Value3="F"
7 2 tag2_1_3 Value1="G"
8 7 tag2_1_3_1 Value2="H" Value3="I"
9 2 tag2_1_4 Value1="J"
10 9 tag2_1_4_1 Value2="K" Value3="L"
11 1 tag2_2
12 11 tag2_2_1 Value4="M"
13 1 tag2_3
14 13 tag2_3_1 Value5="N"
15 14 tag2_3_1_1
16 15 tag2_3_1_1_1
17 16 tag2_3_1_1_1_1 Value6="O" Value7="P"
18 17 tag2_3_1_1_1_1_1 Value2="Q" Value3="R"
19 14 tag2_3_1_2
20 19 tag2_3_1_2_1 Value8="S" Value9="T"I can find lots of ways of converting data to XML but not much this other way round
In the actual code, the XML will be in a file - not sure how much of a difference to the solution..
Thanks,
BenHi Ben,
Here's a first "working" solution, but certainly not the optimum considering the way I compute node IDs :
SQL> select * from v$version
2 ;
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 64-bit Windows: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
SQL>
SQL> SELECT x.*
2 FROM test_xml t,
3 XMLTable(
4 'declare function local:getID($e as node()) as xs:integer
5 {
6 for $i at $j in $d/descendant::*
7 where $i is $e
8 return $j
9 }
10 ; declare function local:getChildren($e as node()) as element()*
11 {
12 for $i in $e/*
13 return element r
14 {
15 element tag_id {local:getID($i)},
16 element parent_tag_id {if (not($e is $d)) then local:getID($e) else()},
17 element tag_name {local-name($i)},
18 element attr_list {string-join(for $j in $i/@* return concat(local-name($j),''="'',$j,''"'')," ")}
19 }
20 | local:getChildren($i)
21 }; local:getChildren($d)'
22 passing t.object_value as "d"
23 columns tag_id number path 'tag_id',
24 parent_tag_id number path 'parent_tag_id',
25 tag_name varchar2(30) path 'tag_name',
26 attr_list varchar2(100) path 'attr_list'
27 ) x
28 ;
TAG_ID PARENT_TAG_ID TAG_NAME ATTR_LIST
1 tag1
2 1 tag2_1
3 2 tag2_1_1 Value1="A"
4 3 tag2_1_1_1 Value2="B" Value3="C"
5 2 tag2_1_2 Value1="D"
6 5 tag2_1_2_1 Value2="E" Value3="F"
7 2 tag2_1_3 Value1="G"
8 7 tag2_1_3_1 Value2="H" Value3="I"
9 2 tag2_1_4 Value1="J"
10 9 tag2_1_4_1 Value2="K" Value3="L"
11 1 tag2_2
12 11 tag2_2_1 Value4="M"
13 1 tag2_3
14 13 tag2_3_1 Value5="N"
15 14 tag2_3_1_1
16 15 tag2_3_1_1_1
17 16 tag2_3_1_1_1_1 Value6="O" Value7="P"
18 17 tag2_3_1_1_1_1_1 Value2="Q" Value3="R"
19 14 tag2_3_1_2
20 19 tag2_3_1_2_1 Value8="S" Value9="T"
20 rows selected
Do you really want attributes displayed that way?
Edited by: odie_63 on 23 mars 2011 13:04 -
Webdav and xdb, xml-files are automatically deleted (or hidden)
Hi All.
In our project we have mounted webdav from a Linux box against an IBM database server running AIX and Oracle 11g.
The file system on the Linux box is mounted to the xdb-schema on the dbserver.
When placing xml-files into the database through the webdav-catalogue on the Linux-box the files are copied over, but almost immediatly removed (or hidden) from the target directory in the database.
I´m thinking there might be a trigger that tries to validate the xml-file against an xsd that isn´t registered in XDB. The reason for this is that when suffixing these files with something other than .xml the files are kept visible to all users.
What I´d like to know is how to disable this check/trigger, and which trigger does this.
Can anybody tell me if my assumtion is correct, and if yes, how to disable this checking?
Our users in the project will also be given access to folders through this webdav mount, and they will use this as a storage space for other xml-files as well. Files we do not have xsd´s for. Another function for this webdav directory is to serve as a source directory for ODI, and ODI validates the files against the xsd when transferring data to the database, so we don´t need this extra validation in the database.
Thanks,
BobHi,
What's the database version? (select * from v$version)
When placing xml-files into the database through the webdav-catalogue on the Linux-box the files are copied over, but almost immediatly removed (or hidden) Does that mean you see them for a short period of time, and then they disappear, or you never see them at all?
Are you using XML DB events?
You can check if there's any resource configuration defined, and that may explain this behaviour :
select x.*
from xdb.xdb$resconfig rc
, xmltable(
xmlnamespaces(default 'http://xmlns.oracle.com/xdb/XDBResConfig.xsd')
, '/ResConfig/event-listeners/listener'
passing rc.object_value
columns description varchar2(300) path 'description'
, schema varchar2(30) path 'schema'
, source varchar2(30) path 'source'
, events varchar2(300) path '(#ora:xq_proc#){string-join(for $i in events/child::* return name($i), ", ")}'
, condition varchar2(300) path 'pre-condition/existsNode/XPath'
) x
DESCRIPTION SCHEMA SOURCE EVENTS CONDITION
Register event handlers for users. SYS DBMS_XS_PRINCIPAL_EVENTS_INT Pre-Create, Post-Create, Pre-Update, Pre-Delete /r:Resource[r:SchemaElement="http://xmlns.oracle.com/xs/principal.xsd#user"]
Register event handlers for role sets. SYS DBMS_XS_ROLESET_EVENTS_INT Pre-Create, Post-Create, Pre-Update, Pre-Delete /r:Resource[r:SchemaElement="http://xmlns.oracle.com/xs/roleset.xsd#roleSet"]
Register event handlers for roles. SYS DBMS_XS_PRINCIPAL_EVENTS_INT Pre-Create, Post-Create, Pre-Update, Pre-Delete /r:Resource[r:SchemaElement="http://xmlns.oracle.com/xs/principal.xsd#dynamicRol
Register event handlers for dynamic roles. SYS DBMS_XS_PRINCIPAL_EVENTS_INT Pre-Create, Post-Create, Pre-Update, Pre-Delete /r:Resource[r:SchemaElement="http://xmlns.oracle.com/xs/principal.xsd#role"]
Register event handlers for function roles. SYS DBMS_XS_PRINCIPAL_EVENTS_INT Pre-Create, Post-Create, Pre-Update, Pre-Delete /r:Resource[r:SchemaElement="http://xmlns.oracle.com/xs/principal.xsd#functionRo
Register event handlers for Data Security. SYS DBMS_XS_DATA_SECURITY_EVENTS Post-Update, Post-Delete /r:Resource[r:SchemaElement="http://xmlns.oracle.com/xs/dataSecurity.xsd#DataSec
Register event handlers for Security Classes. SYS DBMS_XS_SECCLASS_EVENTS Pre-Update, Pre-Delete /r:Resource[r:SchemaElement="http://xmlns.oracle.com/xs/securityclass.xsd#securi
SYS DBMS_NETWORK_ACL_ADMIN Pre-Delete
PL/SQL Network ACL Resource Configuration
Handling of Office Open XML spreadsheets OOX OOX_SML_STORE Pre-Create, Pre-Delete /Resource[ContentType="application/vnd.openxmlformats-officedocument.spreadsheet
9 rows selected
{code}
And if your target folder has any config file associated, for example :
{code}
SQL> select *
2 from table(dbms_resconfig.getResConfigPaths('/office/excel/docs'));
COLUMN_VALUE
/office/excel/conf/sml_rescfg.xml
{code}
Maybe you are looking for
-
ERROR MESSAGE: The IPOD cannot be updated.
Please help!! Have tried everything can think of including, resetting, retrying, restarting, reinstalling and restoring. ITunes automatically starts downloading when you connect but then only transfers the first 50 or so songs in the library, and the
-
When I start up the NFS shares I get an error: "SC[SUNW.nfs:3.1,nfs-rg,nfs-res,nfs_probe]: stat of share path /global/qfsnfs1 failed: Value too large for defined data type. Terminated" The qfs file system /global/qfsnfs1is 5.4Terabytes and if I turn
-
Integrated help in Visual Studio
I installed ODP.Net into Visual Studio .Net 2003. Is there any way to integrate the help from ODP into Visual Studios help? I would to get the same type of response when I press F1 for a OPD member as I get for the normal .Net classes. For instance:
-
1. I have created a Sales Order 15009231 on 02.11.2010 for Material 391115 Quantity Two. Requested delivery date is 08.11.2010. Availability check is working fine and schedule lines confirmed for 08.11.2010. 2. Created delivery 80106315 on 04.11.2010
-
From Final Cut into Soundtrack
Is there a way to edit the audio from a video clip in FCP in Soundtrack while FCP is running? - Anthony