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.
Similar Messages
-
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 -
Search for string and replace with frame break
Hello there,
We're using an InDesign CS6 Server for creating print data. The problem relates to our documents that consist of several connected text frames.
Situation:
The texts are exported from our database into InDesign via xml and so some automated editing in javascript. These texts contaion several paragraphs with headlines. Sometimes after the import the layout just looks bad, because the first textfield contains the fist paragraph and the headline of the second paragraph including some lines of text. Sometimes this behaviour is desired and sometimes not.
Workaroud:
We definde the string #*# to be our placeholder for line breaks. During the creation of the xml this string gets replaced by unicode for the hard line break (
).
Desired Solution:
This workaround has some disadvantages and we want our placeholder string to be translated to a frame break.
Until now I have neither found any definition for the unicode translation of the frame break nor a script based solution that just replaces this string with a frame break. any help is appreciated.
RegardsInstend of define string add attribute in xml or DB
e.g attribute name frame break="frame break"
after that through find the attribute get the insertion ponint and apply "SpecialCharacters.FRAME_BREAK" -
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 -
Concat strings for use with ternay operator
Hi,
depending on a boolean i want to output an welcome message for a user logged in or "login failed".
problem: ternary operator only acceps one expression for each argument.
so, this is ok:
<t:outputText value="#{login.loggedIn ? bundle.loginWelcome : bundle.loginFailed}" />but i want to output the username also, like:
<t:outputText value="#{login.loggedIn ? bundle.loginWelcome login.user : bundle.loginFailed}" />but this throws this:
ERROR - Servlet.service() for servlet jsp threw exception
javax.faces.el.ReferenceSyntaxException: Invalid expression: '${login.loggedIn ? (bundle.loginWelcome login.username) : bundle.loginFailed}'
Caused by: org.apache.commons.el.parser.ParseException: Encountered "? ( bundle . loginWelcome login" at line 1, column 18.
Was expecting one of:
...is there a way to concat strings in EL?
thxWhy don't you create a method on the managed bean that do that for you?
-
Hi,
I've table TAB_COD
COD_ID.................NOTE
001....................OK
001....................NOT OK
001....................YES
002....................TOP
005....................X
005....................Y
005....................Z
007....................MY
007....................YOUR
008....................STOP
I'd like to get this output:
COD_ID.................NOTE
001....................OK - NOT OK - YES
002....................TOP
005....................X - Y - Z
007....................MY - YOUR
008....................STOP
How can I concat string group by COD_ID?
Thanks in advance!!Works for me:
SQL> select banner from v$version
2 /
BANNER
Oracle9i Enterprise Edition Release 9.2.0.7.0 - 64bit Production
PL/SQL Release 9.2.0.7.0 - Production
CORE 9.2.0.7.0 Production
TNS for IBM/AIX RISC System/6000: Version 9.2.0.7.0 - Production
NLSRTL Version 9.2.0.7.0 - Production
SQL> select location_id
2 , concat_all(concat_expr(department_id,',')) x
3 from departments
4 group by location_id
5 /
LOCATION_ID X
1400 60
1500 50
1700 10,110,130,150,170,260,250,240,230,220,210,200,190,180,270,1
60,140,120,100,30,90
1800 20
2400 40
2500 80
2700 70
7 rows selected.
SQL> -
Concat Strings to create a Resource Bundle KEY
Hello, I`m having a little problem. I need, at the same point o a JSF page to show 2 different messages depending on a String variable value inside a Bean.
Then I was thinking if a could have the 2 different keys for the 2 different messages written in the bundle file, but the first part of the key would be the same, then the second would be equal to the String variable in the bean, so I would need to do a concatenation to get the correct KEY and then retrieve the correct message. Is that possible? If so, how could I do that?
So far, I have tried: But none worked
#{messages[''+'']}
#{messages[''] + messages['']}The + is an arithmetic operator, not string-concatenation -- if you apply it to strings, the EL will attempt to coerce them to numeric values in order to apply the '+'.
There are some string manipulation functions in the JSTL standard function library. "str-concat" is not one of them, but there is a "replace" function.
Assuming your resource bundle is called 'messages' and the key suffix is in a bean called 'keysuffix', you could try something like this:
#{message[fn:replace('blah.blah.SUFFIX', 'SUFFIX', keysuffix)]} -
Concat String Values in an Update Statement
Hi,
i am having trouble with this SQL Statement. I do not understand why this is happening:
Table1 (id int, text nvarchar(max))
Data:
1 , "xxx"
1, "www"
2, "yyy"
2, "uuu"
Table2 (id int, text nvarchar(max))
1, "aaa"
2, "bbb"
The id field of table1 is not unique.
UPDATE TABLE Table2
SET text = text + Table1.text
FROM Table2 INNER JOIN Table1 ON Table2.id = Table1.id
Expected Result from Table2:
1, "aaaxxxwww"
2, "bbbyyyuuu"
But the actual result is:
1, "aaaxxx"
2, "bbbyyy"
What am I doing wrong or what am I missing?
thanx.
regards
StefanThe problem is that there is no intermediate result propagation. You simply get "aaa" + "..." where "..." is the last column value by the internal order of your statement.
You need to explicitliy concat your input strings from T1 before doing the update, e.g.
DECLARE @T1 TABLE
id INT ,
[text] NVARCHAR(MAX)
INSERT INTO @T1
VALUES ( 1, 'xxx' ),
( 1, 'www' ),
( 2, 'yyy' ),
( 2, 'uuu' );
DECLARE @T2 TABLE
id INT ,
[text] NVARCHAR(MAX)
INSERT INTO @T2
VALUES ( 1, 'aaa' ),
( 2, 'bbb' );
UPDATE T2
SET [text] = T2.[text] + ( SELECT '' + T1.[text]
FROM @T1 T1
WHERE T1.id = T2.id
FOR XML PATH('')
FROM @T2 T2;
SELECT T.id ,
T.[text]
FROM @T2 T; -
APEX application or page url - How to use enum string to replace ID number
URL to a APEX page is format as ***/f?p=APPLICATION_ID:PAGE_ID:... . Here the APPLIACTION_ID and PAGE_ID are numbers.
My Question is: Is there a way to replace the numbers by using strings? For example: can I have a URL like /f?p=MY_APPLICATION:MY_PAGE1: ... ? Juts like ENUM in other languages, MY_APPLICATION actually just represent the application id but much more readable since it is a string with a name the user may familar.
Please help.
Thank you.You can assign an alphanumeric alias to applications and pages using their respective attribute edit forms in the Application Builder. Then you can construct links that use those aliases instead of the IDs. These aliases will generally be preserved in the URL visible in the browser, but not in all cases. You have to deliberately use the aliases in any branch definitions, list item targets, etc. Note that application aliases must be unique within a workspace. Please see the User's Guide for more info.
Scott -
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. -
Search and Replace String Function replaces line feeds when I only want spaces replaced?
I need to replace every instance of a space or series of spaces in a multi line string with commas (or tabs) so I can dump it into a spreadsheet.
I am using the regular expresion [\s]+ and it works but it is also replacing the end of lines (\r\n) too.
How can I make it replace the spaces but leave teh end of lines intact?
Solved!
Go to Solution.
Attachments:
replace.vi 6 KBRight click on the search string and change it to '\' Code Display. Enter the space character (\s) correctly - you've got \\s right now.
-
How to concate string variable?
hi,
anyone help me out in this case.
i have a prg. like this.
data: var1(20) type c.
data: var2(2) type c.
data: var3(2) type c.
data: var type string.
var1 = 'abcd'.
var2 = 'bp'.
var3 = 'bp'.
i want the output like..... abcd bpbp.
it means i want to leave 16 spaces after abcd in this case. if var1 is having content like ,
abcde than i want to leave 15 space after abcde because total length of var1 is 20.
if i simply concate output would be abcdbpbp.
so if i count the no. of spaces i need to leave after abcd and create one date object of type c at runtime , it would work out.
but how should i create.....?
plz let me know ASAP.
saurin shah.Hi Saurin...
there are 2 main keywords used with concatenate
(1) ...."SEPARATED BY"
(2) ...."RESPECTING BLANKS"
in this case if you do the code
copy the code into a test program......................
data: var1(20) type c.
data: var2(2) type c.
data: var3(2) type c.
data : var4(4) type c.
data: var type string.
var1 = 'abcd'.
var2 = 'bp'.
var3 = 'bp'.
concatenate var2 var3 into var4.
to get bpbp
concatenate var1 var4 into var separated by SPACE.
write var.
clear var.
concatenate var1 var4 into var respecting blanks.
write var.
keep changing the value of var1 in the code to see how you can use the 2 options to your advantage...and which one suits your requirement best
Output1: " using separated by space"
abcd bpbp
here there will be 1 spacce after abcd
so it is abcde
it will be
abcde bpbp
Output2: " using respecting blanks"
abcd bpbp
ie,after abcd there will be 16 more blank spaces since its total length is 16...
using this keyword the number of space is not condensed but kept intact
but if there are 20 characters in the var1 then there will be no space eg: abcdefghijklmnopqrsbpbp...for 19 characters it will be abcdefghijklmnopqr bpbp
so you can decide which layout you need once you write the code and see th output for yourself
Pls check,revert and reward if helpful
Regards
Byju -
C# Script Task string variable replace wont replace
The code below ought to replace "A" with "B" but it doesnt.
Please tell me how to make this work. Thanks!Doug,
it returns a new string (does not assign to the same)
So you need fn = fn.Replace("A", "B");
Arthur
MyBlog
Twitter -
when i have the following program, the system print out at last is just "good" instead of "goodhello", do I make any mistake?
thx~
import java.io.*;
import java.lang.Object;
import java.lang.String;
public class Test{
public static void main(String[] args) throws IOException {
String c = "good";
String d ="hello";
c.concat(d);
System.out.println(c);In Java, Strings are immutable. All String manipulation functions return new Strings and leave the originals unchanged.
c.concat(d);This creates and ignores a new, separate, String object. c is left unchanged.
You could have done as the previous poster recommended and used c = c.concat(d);or c += d; c then points (yes, Java does have pointers!) to the newly-created String object.
You could also use the mutable class StringBuffer:
c = new StringBuffer(c).append(d).toString();For a simple concatenation, this offers no readability or efficiency benefits over +, but it's useful in other circumstances. -
I have the following xml in String format. I'm only showing one XMLWorkFlowTask node, but there are potentially many in my application. I would like to replace all occurrences of the <sch:Title> node (located in the <sch:XMLWorkflowNode> node) with <sch:Title2>. Does anyone know of a way to do this?
<XMLWorkFlowTask>
<sch:TaskID>jbpm$17011</sch:TaskID>
<sch:Desc>daiswf:genericFundingRequestTask</sch:Desc>
<sch:Title>daiswf:genericFundingRequestTask</sch:Title>
<sch:PooledGroup>FINA_ADMIN</sch:PooledGroup>
<sch:DateCreated>2008-12-10T10:30:44.000-06:00</sch:DateCreated>
<sch:DateDue>2008-12-12T10:30:00.000-06:00</sch:DateDue>
<sch:Status>Not Yet Started</sch:Status>
<sch:WorkflowInstanceID>jbpm$2472</sch:WorkflowInstanceID>
<sch:Outcome/>
<sch:Action>initDefaultTask</sch:Action>
<sch:AgencyName>Jane Addams Hull House Association</sch:AgencyName>
<sch:Project>Mid Southwest and Southeast and Northeast</sch:Project>
<sch:GrantApplicationID/>
<sch:GrantAwardID/>
<sch:GrantCloseOutID/>
<sch:FundingRequestID>800</sch:FundingRequestID>
<sch:OrganizationName>Jane Addams Hull House Association / Mid Southwest and Southeast and Northeast</sch:OrganizationName>
<sch:FundNum>0893</sch:FundNum>
<sch:XMLWorkflowTaskDefinition>
<sch:TaskDefinitionID>daiswf:genericFundingRequestTask</sch:TaskDefinitionID>
<sch:XMLWorkflowNode>
<sch:Name>coverSheet</sch:Name>
<sch:Title>Create Contract/Amendment Cover Sheet for Scan</sch:Title>
<sch:Desc>N/A</sch:Desc>
<sch:XMLWorkflowTransition>
<sch:TransitionID>Task Done</sch:TransitionID>
<sch:Title>Task Done</sch:Title>
<sch:Desc>Task Done</sch:Desc>
<sch:Default>true</sch:Default>
</sch:XMLWorkflowTransition>
</sch:XMLWorkflowNode>
</sch:XMLWorkflowTaskDefinition>
<sch:WorkflowActive>true</sch:WorkflowActive>
<sch:Department>CONTRACTS</sch:Department>
<sch:OriginatedBy>hs00577</sch:OriginatedBy>
</XMLWorkFlowTask>if you are using jdom API then
SAXBuilder builder = new SAXBuilder(false);
Document objDoc = builder.build(strXmlDoc);
Element objRootElement = objDoc.getRootElement();
Namespace objNameSpace = Namespace.getNamespace("sch",
"http://url");
Element objParentOfWorkTask = objRootElement.getChild("ParentOfWorkFlowTask");
List objLstXmlTasl = objParentOfWorkTask.getChildren("XMLWorkFlowTask");
for(int numCnt = 0; numCnt < objLstXmlTasl.size(); numCnt++) {
List objLstTitle = ((Element) objLstXmlTasl.get(numCnt)).getChildren("Title", objNameSpace);
for(int numAntCnt = 0; numAntCnt < objLstTitle.size(); numAntCnt++) {
((Element) objLstTitle.get(numCnt)).setName("Title2");
}
Maybe you are looking for
-
Lost the power cord for time capsule!
So I've lost the power cord for my time capsule. I went to an Apple store and they don't sell them but the employee said that it is a standard cord and I should be able to pick one up at a Radio Shack or the like? Has anybody else had to do this? I c
-
How to pass int array as an IN parameter to PLSQL Procedure
Hi, How to pass int array in java to a stored procedure througn jdbc and what type of data type I should declare to this IN parameter in PLSQL Procedure. Thanks, Simi
-
TRANSITIONS AND EFFECTS???
Hey guys i am so new to imovie. I got a mac 3 yrs ago but just now using imovie. anyway i have both imovies 6 and 8 and i see that imovie 6 has more transitions and effects. Imovie 8 doesn't. So either i am looking at the wrong place or they don't ha
-
HT201401 i have no edit button in my contacts
i noticed a while ago i no longer have an edit button in my contacts so i cannot edit any contacts i already have but i am also unable to too any new contacts without having to dial the number first and then adding it that way. Any help would be grea
-
How to transport the validations, assignments, named searches, and workflow
Hi Experts How to transport the validations, assignments, named searches, and workflow between two repositories. Thanks Vickey.