String Aggregate Concatenation

Link on aggregate concatenation with variable:
CREATE FUNCTION CSVLanguage (@Title as varchar(50))
RETURNS varchar(1000)
AS
BEGIN
DECLARE @Sa varchar(1000)
SELECT @Sa=@Sa + language + ','
    FROM books
    WHERE title=@Title
RETURN (@Sa)
END
I have seen the above concatenation method zillion times, kind of thought it is a valid method. In fact I used it many times, and always worked.
Erland Sommarskog has pointed out in the following (unrelated) thread that the behaviour is undefined in such an aggregate concatenation:
http://social.msdn.microsoft.com/Forums/en/transactsql/thread/31804823-6e5e-4e2d-9729-330d12ccb880
Erland provided the following kb article for explanation:
http://support.microsoft.com/kb/287515
Since T-SQL does not (yet!) have a built-in function for aggregate concatenation, a T-SQL - XML hybrid method popped up with SQL Server 2005 ( I also used this many times to satisfaction):
SELECT DISTINCT id,
 SUBSTRING(
 (SELECT ','+name AS [text()]
   FROM t1
   WHERE id = T.id
   ORDER BY name
   FOR XML PATH( '' )
 ), 2,100) AS concat
 FROM t1 AS T;
As noted in the link above, this method has some issues as well.
-- DEMO: with "<" as part of the string, wrong concatenation result
SELECT ID=productID/100, Name='<'+Name
INTO t1
FROM AdventureWorks2008.Production.Product
go
SELECT DISTINCT id,
SUBSTRING(
(SELECT ','+name AS [text()]
FROM t1
WHERE id = T.id
ORDER BY name
FOR XML PATH( '' )
), 2,100) AS concat
FROM t1 AS T;
GO
id concat
0 &lt;Adjustable Race,&lt;BB Ball Bearing,&lt;Bearing Ball,&lt;Headset Ball Bearings
3 &lt;Blade,&lt;Chain Stays,&lt;Chainring,&lt;Chainring Bolts,&lt;Chainring Nut,&lt;Crown Race,&lt;Dec
DROP TABLE t1;
So what is the real solution to aggregate concatenate?
Kalman Toth SQL SERVER 2012 & BI TRAINING
New Book: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2012

an alternative query with hexBinary provides correct result
declare @sample table
id int,
data varchar(100)
insert @sample
values (1, 'Peso & Performance SQL>'),
(1, 'MVP'),
(2, 'Need help <' + CHAR(2) + '? /> + ' + CHAR(31) + ' f'),
(2, 'With XML string concatenation ?')
select i.id,
f.content
from (
select id
from @sample
group by id
) as i
outer apply (
select stuff(convert(varchar(max), convert(xml,'').value('xs:hexBinary(sql:column("w4.data"))', 'varbinary(max)')),1,2,'')
as Content
from (select convert(varchar(max),w3.data)
from (
select convert(xml,'').value('xs:hexBinary(sql:column("w2.data"))', 'varchar(max)')
from (select convert(varbinary(max), ', ' + w1.data)
from @Sample w1
where w1.ID = i.ID
) w2 (data)
for xml path(''),type
) w3 (data)
) w4 (data)
) f

Similar Messages

  • Adding white spaces between strings during concatenation in JSTL

    Please provide a way to add white space between strings during concatenation in JSTL.
    I tried the following.
    eg:
    <c:set var="even_odd" value="odd">
    <c:out value="first ${even_odd}"/>
    I want the output string as "first odd ".
    Moreover i am using the above value for generating the class attribute of a row of a table like
    <tr class=<c:out value="first ${even_odd}"/>>
    while printing the value of <c:out value="first ${even_odd}"/> in the page,i am getting correctly as i needed as "first odd".
    But while taking the code of the page while rendering by the browser, it is showing like
    <tr class="first" odd="">
    I think the white space is the problem.
    Please provide any solution or hint.

    <tr class=<c:out value="first ${even_odd}"/>><tr class="first ${even_odd}">

  • How to string aggregate in OBIEE reports?

    Hi ,
    I have a requirement to string aggregate the data for a particular column in OBIEE 11g.
    When Iam using the in built functions *(wmconcat)*_ it is throwing the error as ,
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 17001] Oracle Error code: 934, message: ORA-00934: group function is not allowed here at OCI call OCIStmtExecute. [nQSError: 17010] SQL statement preparation failed. (HY000)
    How to get this requiremnet in OBIEE analytics report page while displaying?
    emp_name Dept_no
    Ex: Kalyan 1162 26164,26169,26183,26249,26285
    Help is highly appreciated.
    Regards,
    Kalyan

    Hi Deepak,
    Thanks for your responce.
    My requirement was not that.
    Ex: If a employe belongs to multiple departments
    employe X belongs to department 10,20,30,40 then report should disply as comma separated values.
    sol: X 10,20,30,40
    As the output when we use wm_concat in built function.
    Kindly waiting for the people responce.
    Regards,
    Kalyan

  • Concatinating numbers with a string...sort of

    Well I've got an assignment that says this "Write a method called multiConcat that takes a string and an interger as parameters. Return a string that consists of the string parameter concatenated with itself count time, where count is the integer parameter. For example, if the parameter vales are 'hi" and 4, the return value is "hihihihi". Return the original string if the interger parameter is less than two.
    So I've tried a couple of things that I thought would work with my small amount of CS courses, but I have not been able to come up with a resolution for this assignment yet. I do not want anyone to post any time of code yet. All I ask for is for someone to point me in the correct direction with some kind of a learning document etc.

    for that the answer is
    class MyClass{
         StringBuffer string1=null;
    public      StringBuffer myMethod(String string , int number){
    string1=new StringBuffer(string);
              if (number<2){
                   return string1;
              }else{
                   while(number!=1){
                        string1.append(string);//here string is String and string1 is StringBuffer tehn only we can get coorect data.then u will get output hihihihi for input hi,4
                        //try it by keeping both of type stringBuffer, u will get out put hihihihihihihihi for input hi,4
                        --number;
                   return string1;
    class FirstProgram {
         public static void main(String[] args) {
              String string=args[0];
              int number=Integer.parseInt(args[1]);
              System.out.println("string ="+string+" "+"number ="+number);
              StringBuffer result=(new MyClass()).myMethod(string,number);
              System.out.println("final output is"+result);
    }

  • Simple string optimization question

    ABAPpers,
    Here is the problem description:
    In a SELECT query loop, I need to build a string by concatenating all the column values for the current row. Each column is represented as a length-value pair. For example, let's say the current values are:
    Column1 (type string)  : 'abc          '
    Column2 (type integer) : 7792
    Column3 (type string)  : 'def                    '
    The resulting string must be of the form:
    0003abc000477920003def...
    The length is always represented by a four character value, followed by the actual value.
    Note that the input columns may be of mixed types - numeric, string, date-time, etc.
    Given that data is of mixed type and that the length of each string-type value is not known in advance, can someone suggest a good algorithm to build such a result? Or, is there any built-in function that already does something similar?
    Thank you in advance for your help.
    Pradeep

    Hi,
    At the bottom of this message, I have posted a program that I currently wrote. Essentially, as I know the size of each "string" type column, I use a specific function to built the string. For any non-string type column, I assume that the length can never exceed 25 characters. As I fill 255 characters in the output buffer, I have to write the output buffer to screen.
    The reason I have so many functions for each string type is that I wanted to optimize concatenate operation. Had I used just one function with the large buffer, then "concatenate" statement takes additional time to fill the remaining part of the buffer with spaces.
    As my experience in ABAP programming is limited to just a couple of days, I'd appreciate it if someone can suggest me a better way to deal with my problem.
    Thank you in advanced for all your help. Sorry about posting such a large piece of code. I just wanted to show you the complexity that I have created for myself :-(.
    Pradeep
    REPORT ZMYREPORTTEST no standard page heading line-size 255.
    TABLES: GLPCA.
    data: GLPCAGL_SIRID like GLPCA-GL_SIRID.
    data: GLPCARLDNR like GLPCA-RLDNR.
    data: GLPCARRCTY like GLPCA-RRCTY.
    data: GLPCARVERS like GLPCA-RVERS.
    data: GLPCARYEAR like GLPCA-RYEAR.
    data: GLPCAPOPER like GLPCA-POPER.
    data: GLPCARBUKRS like GLPCA-RBUKRS.
    data: GLPCARPRCTR like GLPCA-RPRCTR.
    data: GLPCAKOKRS like GLPCA-KOKRS.
    data: GLPCARACCT like GLPCA-RACCT.
    data: GLPCAKSL like GLPCA-KSL.
    data: GLPCACPUDT like GLPCA-CPUDT.
    data: GLPCACPUTM like GLPCA-CPUTM.
    data: GLPCAUSNAM like GLPCA-USNAM.
    data: GLPCABUDAT like GLPCA-BUDAT.
    data: GLPCAREFDOCNR like GLPCA-REFDOCNR.
    data: GLPCAAWORG like GLPCA-AWORG.
    data: GLPCAKOSTL like GLPCA-KOSTL.
    data: GLPCAMATNR like GLPCA-MATNR.
    data: GLPCALIFNR like GLPCA-LIFNR.
    data: GLPCASGTXT like GLPCA-SGTXT.
    data: GLPCAAUFNR like GLPCA-AUFNR.
    data: data(255).
    data: currentPos type i.
    data: lineLen type i value 255.
    data len(4).
    data startIndex type i.
    data charsToBeWritten type i.
    data remainingRow type i.
    SELECT GL_SIRID
    RLDNR
    RRCTY
    RVERS
    RYEAR
    POPER
    RBUKRS
    RPRCTR
    KOKRS
    RACCT
    KSL
    CPUDT
    CPUTM
    USNAM
    BUDAT
    REFDOCNR
    AWORG
    KOSTL
    MATNR
    LIFNR
    SGTXT
    AUFNR into (GLPCAGL_SIRID,
    GLPCARLDNR,
    GLPCARRCTY,
    GLPCARVERS,
    GLPCARYEAR,
    GLPCAPOPER,
    GLPCARBUKRS,
    GLPCARPRCTR,
    GLPCAKOKRS,
    GLPCARACCT,
    GLPCAKSL,
    GLPCACPUDT,
    GLPCACPUTM,
    GLPCAUSNAM,
    GLPCABUDAT,
    GLPCAREFDOCNR,
    GLPCAAWORG,
    GLPCAKOSTL,
    GLPCAMATNR,
    GLPCALIFNR,
    GLPCASGTXT,
    GLPCAAUFNR) FROM GLPCA
    perform BuildFullColumnString18 using GLPCAGL_SIRID.
    perform BuildFullColumnString2 using GLPCARLDNR.
    perform BuildFullColumnString1 using GLPCARRCTY.
    perform BuildFullColumnString3 using GLPCARVERS.
    perform BuildFullColumnString4 using GLPCARYEAR.
    perform BuildFullColumnString3 using GLPCAPOPER.
    perform BuildFullColumnString4 using GLPCARBUKRS.
    perform BuildFullColumnString10 using GLPCARPRCTR.
    perform BuildFullColumnString4 using GLPCAKOKRS.
    perform BuildFullColumnString10 using GLPCARACCT.
    perform BuildFullColumnNonString using GLPCAKSL.
    perform BuildFullColumnNonString using GLPCACPUDT.
    perform BuildFullColumnNonString using GLPCACPUTM.
    perform BuildFullColumnString12 using GLPCAUSNAM.
    perform BuildFullColumnNonString using GLPCABUDAT.
    perform BuildFullColumnString10 using GLPCAREFDOCNR.
    perform BuildFullColumnString10 using GLPCAAWORG.
    perform BuildFullColumnString10 using GLPCAKOSTL.
    perform BuildFullColumnString18 using GLPCAMATNR.
    perform BuildFullColumnString10 using GLPCALIFNR.
    perform BuildFullColumnString50 using GLPCASGTXT.
    perform BuildFullColumnString12 using GLPCAAUFNR.
    ENDSELECT.
    if currentPos > 0.
      move '' to datacurrentPos.
      write: / data.
    else.
      write: / '+'.
    endif.
    data fullColumn25(29).
    data fullColumn1(5).
    Form BuildFullColumnString1 using value(currentCol). 
      len = STRLEN( currentCol ).
      concatenate len currentCol into fullColumn1.
      data startIndex type i.
      data charsToBeWritten type i.
      charsToBeWritten = STRLEN( fullColumn1 ).
      data remainingRow type i.
      do.
        remainingRow = lineLen - currentPos.
        if remainingRow > charsToBeWritten.
          move fullColumn1+startIndex(charsToBeWritten) to
            data+currentPos(charsToBeWritten).
          currentPos = currentPos + charsToBeWritten.
          exit.
        endif.
        if remainingRow EQ charsToBeWritten.
          move fullColumn1+startIndex(charsToBeWritten) to
            data+currentPos(charsToBeWritten).
          write: / data.
          currentPos = 0.
          exit.
        endif.
        move fullColumn1+startIndex(remainingRow) to
            data+currentPos(remainingRow).
        write: / data.
        startIndex = startIndex + remainingRow.
        charsToBeWritten = charsToBeWritten - remainingRow.
        currentPos = 0.
      enddo.
    EndForm.
    data fullColumn2(6).
    Form BuildFullColumnString2 using value(currentCol). 
      len = STRLEN( currentCol ).
      concatenate len currentCol into fullColumn2.
      data startIndex type i.
      data charsToBeWritten type i.
      charsToBeWritten = STRLEN( fullColumn2 ).
      data remainingRow type i.
      do.
        remainingRow = lineLen - currentPos.
        if remainingRow > charsToBeWritten.
          move fullColumn2+startIndex(charsToBeWritten) to
            data+currentPos(charsToBeWritten).
          currentPos = currentPos + charsToBeWritten.
          exit.
        endif.
        if remainingRow EQ charsToBeWritten.
          move fullColumn2+startIndex(charsToBeWritten) to
            data+currentPos(charsToBeWritten).
          write: / data.
          currentPos = 0.
          exit.
        endif.
        move fullColumn2+startIndex(remainingRow) to
            data+currentPos(remainingRow).
        write: / data.
        startIndex = startIndex + remainingRow.
        charsToBeWritten = charsToBeWritten - remainingRow.
        currentPos = 0.
      enddo.
    EndForm.
    data fullColumn3(7).
    Form BuildFullColumnString3 using value(currentCol). 
    EndForm.
    data fullColumn4(8).
    Form BuildFullColumnString4 using value(currentCol). 
    EndForm.
    data fullColumn50(54).
    Form BuildFullColumnString50 using value(currentCol). 
    EndForm.
    Form BuildFullColumnNonString using value(currentCol). 
      move currentCol to fullColumn25.
      condense fullColumn25.     
      len = STRLEN( fullColumn25 ).
      concatenate len fullColumn25 into fullColumn25.
      data startIndex type i.
      data charsToBeWritten type i.
      charsToBeWritten = STRLEN( fullColumn25 ).
      data remainingRow type i.
      do.
        remainingRow = lineLen - currentPos.
        if remainingRow > charsToBeWritten.
          move fullColumn25+startIndex(charsToBeWritten) to
            data+currentPos(charsToBeWritten).
          currentPos = currentPos + charsToBeWritten.
          exit.
        endif.
        if remainingRow EQ charsToBeWritten.
          move fullColumn25+startIndex(charsToBeWritten) to
            data+currentPos(charsToBeWritten).
          write: / data.
          currentPos = 0.
          exit.
        endif.
        move fullColumn25+startIndex(remainingRow) to
            data+currentPos(remainingRow).
        write: / data.
        startIndex = startIndex + remainingRow.
        charsToBeWritten = charsToBeWritten - remainingRow.
        currentPos = 0.
      enddo.
    EndForm.

  • How can I write this string to a file as the ASCII representation in Hex format?

    I need to convert a number ( say 16000 ) to Hex string ( say 803E = 16,000) and send it using Visa Serial with the string control in Hex Mode. I have no problem with the conversion (see attached). My full command in the hex display must read AA00 2380 3E...
    I can easily get the string together when in Normal mode to read AA0023803E... but how can I get this to hex mode without converting? (i.e. 4141 3030 3233 3830 3345 3030 3030 3031 )
    Attachments:
    volt to HEX.vi ‏32 KB

    Sorry, The little endian option was probably introduced in 8.0 (?).
    In this special case it's simple, just reverse the string before concatenating with the rest.
    It should be in the string palette, probably under "additional string functions".
    (note that this only works in this special case flattening a single number as we do here. If the stat structure is more complex (array, cluster, etc.) you would need to do a bit more work.
    Actually, you might just use typecast as follows. Same difference.
    I only used the flatten operation because of the little endian option in my version.
    Message Edited by altenbach on 11-16-2007 11:53 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    littleendian71.png ‏4 KB
    littleEndiancast71.png ‏4 KB

  • Set "url" in HTTPService using String variable

    Hi,
    How can I set "url" in HTTPService using String variable (see below). I've tried different formats of string & variable concatenations.
    privtate var myurl:String = "http://localhost/";
        <mx:HTTPService id="post_submit_service"
            url="{myurl+'test.php'}"
            method="POST"
            resultFormat="text"
          result="result_handler(event)"
          fault="fault_handler(event)">
            <mx:request xmlns="">
          </mx:request>
        </mx:HTTPService>
    Thanks,
    ASM

    try following:
    url="{myurl}test.php"

  • Add 2 strings together

    Hello,
    i have a really weird error message here:
    say I define 2 dta type c objects:
    data: tot_str(50) type c,
          sub_str(20) type c.
    then I do
        tot_str = 'ABCDEF' & substr
    assuming both tot_str and sub_str are already initialized.
    However, the error message I got is:
    Incorrect arithmetic or bit expression: Instead of "&", an operator (+,     -, *, /, ... or BIT-AND, BIT-XOR, BIT-OR) was expected.)
    Why is it so? I thought & is the standard concatenation character for ABAP. And BTW, when I changed to +, it will give me a run-time error saying that the 2 strings can not be added....
    Thanks a lot!
    Regards,
    Anyi

    Hi Anyi,
    yes you are right. I found it in SAP help hidden somewhere in the data objects section:
    "If you want to enter a character literal in the ABAP Editor that is longer than a single editor line, ABAP syntax allows you to enter several character literals and link them using the & character. "
    So this was just a crutch to bypass the (meanwhile obsolete) editor line length limit.
    I the section "Processing Character Strings", chapter "Concatenating Character Strings", they say:
    "The CONCATENATE statement combines two or more separate strings into one.
    CONCATENATE <c1> ... <cn> INTO <c> [SEPARATED BY <s>].
    This statement concatenates the character fields <c1> to <cn> and assigns the result to <c>. The system ignores spaces at the end of the individual source strings.
    The addition SEPARATED BY <s> allows you to specify a character field <s> which is placed in its defined length between the individual fields."
    That means that all leading and trailing spaces will disappear except the ones in the separator string <sep>.
    So it depends on the result you want as how to do the concatenation. if you want a fixed position regardless of blanks, then you must work with offset and length addition.
    Kind regards,
    Clemens

  • Sql group by query and concatenation

    Hi folks,
    I have question.I need to concatenate the columns like this.
    i/p
    i_txt txt
    1000 abc
    1000 def
    1001 things
    1001 to
    1001 do
    1002 is
    1002 it
    1002 possible
    O/P should be like this
    i_txt txt
    1000 abcdef
    1001 things to do
    1002 is it possible
    Thanks in advance
    Raj

    Tubby's provided the useful search term: String Aggregation.
    Assuming you've studied Tim's article, you now know that the approach and techniques you can use are database-version dependant.
    So, please: always mention your database-version when posting a question.
    Now, when looking at your desired output, it looks like a simple string aggregation question, however:
    You don't seem to want 'abcdef' connected by a space?
    Without knowing why, you can use case and replace the space for that specific i_txt.
    But, that requires some hard-coding:
    SQL> select * from t;
         I_TXT TXT
          1000 abc
          1000 def
          1001 things
          1001 to
          1001 do
          1002 is
          1002 it
          1002 possible
    8 rows selected.
    SQL> select i_txt
      2  ,      ltrim(sys_connect_by_path(txt, ' '), ' ') txt
      3  from ( select i_txt
      4         ,      txt
      5         ,      row_number() over (partition by i_txt order by i_txt ) rn
      6         from t
      7       )
      8  where connect_by_isleaf=1    
      9  start with rn=1
    10  connect by i_txt = prior i_txt
    11         and rn = prior rn+1;
         I_TXT TXT
          1000 abc def
          1001 things to do
          1002 is it possible
    3 rows selected.
    SQL> select i_txt
      2  ,      case i_txt
      3           when 1000
      4           then  replace(sys_connect_by_path(txt, ' '), ' ')
      5           else  ltrim(sys_connect_by_path(txt, ' '), ' ')
      6         end txt
      7  from ( select i_txt
      8         ,      txt
      9         ,      row_number() over (partition by i_txt order by i_txt ) rn
    10         from t
    11       )
    12  where connect_by_isleaf=1    
    13  start with rn=1
    14  connect by i_txt = prior i_txt
    15         and rn = prior rn+1;
         I_TXT TXT
          1000 abcdef
          1001 things to do
          1002 is it possible
    3 rows selected. This example works when you're on database version 10G and onwards.
    Perhaps we could find other ways, if you can explain when you do and do not want your strings aggregated/concatenated by a space

  • Pad string with leading blanks

    Im having trouble with padding leading blanks...
    String PRpty_no = "10";
    String qsPRpty_no = null;
    qsPRpty_no = "PRpty_no=\""+pad(PRpty_no, 5, true)+"\" AND ";
    protected String pad(String origString, int requiredSize, boolean justRight){
    String theString=origString;
    if(justRight){
    while(theString.length()<requiredSize){ theString=" "+theString; }
    } else {
    while(theString.length()<requiredSize){ theString=theString+" "; }
    return theString;
    Returns:
    theString = " 10"
    theString = " 10"
    theString = " 10"
    It only adds 1 blank. The loop is obviously finishing when theString.length=5.
    If I replace " " with "0" the desired result comes back:
    theString = "010"
    theString = "0010"
    theString = "00010"
    What is the difference using " " to "0"?

    Unfortunately not GreyMan, copyright and all that. In the end the strings get concatenated into an sql query then run:
    String sql="SELECT PRupi FROM PRprop WHERE ("+qsPRpty_no+qsPRpty_suffix+qsPRroad_id+")";
    Where PRpty gets pulled out from an earlier sql as "10" and qsPRpty needs to be " 10" not " 10".

  • Problem with my aggregate function

    Hello there,
    I tried to build my own string aggregate function but I've a troubles when I'm using it into my query. When I'm using it, it writes ORA904, whereas this idenfifier exists. Do you know what's wrong ?
    here my aggregate function :
    create or replace FUNCTION aggme (query_in in VARCHAR2) RETURN VARCHAR2 IS
        incoming    varchar2(4000);
        hold_result varchar2(4000);
        c sys_refcursor;
    Begin
        open c for query_in;
        loop
            fetch c into incoming;
            exit when c%notfound;
            hold_result := hold_result||','||incoming;
        end loop;
        return ltrim(hold_result,',');
    END;and here my query by using my aggregate function aggme:
    select
      RES.LASTNAME as "LASTNAME",
      RES.FIRSTNAME as "FIRSTNAME",
      aggme('select NAME from PATHOLOGY where ID= RES.PATHOLOGY_ID') as "PATHOLOGY"
    from
      TBK_RESOURCE RES

    Mustafa KALAYCI wrote:
    I think you wanted to do this:
    select
    RES.LASTNAME as "LASTNAME",
    RES.FIRSTNAME as "FIRSTNAME",
    aggme('select NAME from PATHOLOGY where ID=' || RES.PATHOLOGY_ID) as "PATHOLOGY"
    from
    TBK_RESOURCE RESby the way this is a very very bad idea doing like that. you should look for WM_CONCAT (for db version 11.1 or lower)No. Nobody should use WM_CONCAT. It's an undocumented function that is not supported by Oracle and may be changed in future versions without notice.
    All Oracle experts say not to use it, including Tom Kyte... Re: DISTINCT not working with  wmsys.wm_concat
    Below 11gR2, you should use SYS_CONNECT_BY_PATH, or a user defined function, including user defined aggregate functions such as the following example, which aggregates strings into a clob as a result...
    create or replace type clobagg_type as object
      text clob,
      static function ODCIAggregateInitialize(sctx in out clobagg_type) return number,
      member function ODCIAggregateIterate(self in out clobagg_type, value in clob) return number,
      member function ODCIAggregateTerminate(self in clobagg_type, returnvalue out clob, flags in number) return number,
      member function ODCIAggregateMerge(self in out clobagg_type, ctx2 in clobagg_type) return number
    create or replace type body clobagg_type is
      static function ODCIAggregateInitialize(sctx in out clobagg_type) return number is
      begin
        sctx := clobagg_type(null) ;
        return ODCIConst.Success ;
      end;
      member function ODCIAggregateIterate(self in out clobagg_type, value in clob) return number is
      begin
        self.text := self.text || value ;
        return ODCIConst.Success;
      end;
      member function ODCIAggregateTerminate(self in clobagg_type, returnvalue out clob, flags in number) return number is
      begin
        returnValue := self.text;
        return ODCIConst.Success;
      end;
      member function ODCIAggregateMerge(self in out clobagg_type, ctx2 in clobagg_type) return number is
      begin
        self.text := self.text || ctx2.text;
        return ODCIConst.Success;
      end;
    end;
    create or replace function clobagg(input clob) return clob
      deterministic
      parallel_enable
      aggregate using clobagg_type;
    SQL> select trim(',' from clobagg(ename||',')) as enames from emp;
    ENAMES
    SMITH,ALLEN,WARD,JONES,MARTIN,BLAKE,CLARK,SCOTT,KING,TURNER,ADAMS,JAMES,FORD,MILLER
    SQL> ed
    Wrote file afiedt.buf
      1  with t as
      2    (select 'PFL' c1, 0 c2,110 c3 from dual union all
      3     select 'LHL', 0 ,111 from dual union all
      4     select 'PHL', 1, 111 from dual union all
      5     select 'CHL', 2, 111 from dual union all
      6     select 'DHL', 0, 112 from dual union all
      7     select 'VHL', 1, 112 from dual union all
      8     select 'CPHL', 0, 114 from dual union all
      9     select 'WDCL', 1, 114 from dual union all
    10     select 'AHL' ,2 ,114 from dual union all
    11     select 'NFDL', 3, 114 from dual)
    12  --
    13  -- end of test data
    14  --
    15  select trim(clobagg(c1||' ')) as c1, c3
    16  from (select * from t order by c3, c2)
    17  group by c3
    18* order by c3
    SQL> /
    C1                                     C3
    PFL                                   110
    LHL CHL PHL                           111
    DHL VHL                               112
    CPHL AHL NFDL WDCL                    114

  • Null reference converted to a String

    I read somewhere that when a null reference is converted to a string, the result is the String "null", hence a null reference can be used freely within any string concatenation expression.
    for example:
    String str1 = null;
    String str2 = null;
    System.out.println(str1+=str2);//outputs "nullnull"
    Before I read about this, I would have thought that a NullPointerException would have been thrown.
    Can anyone explain the rationale behind this?

    This is not a property of String, its the property of
    the println method in the PrintStream class.No, that's not correct.
    Whenever Strings are concatenated, non-Strings are converted to Strings and null Strings are converted to the String "null". This is a property of the Java language itself.
    The expression a + b, where either a or b is a String, is converted into the expression:
    new StringBuffer().append(a).append(b).toString();
    It is the append method of StringBuffer that calls the toString method of non-String objects, calls String.valueOf on primitives, and converts null String references into the String "null". Even though it's an API call that technically produces this behavior, it is actually a feature of the Java language itself as is therefore explained in the JLS. See http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#39990 for details.

  • Construct a string containing a command

    Hi experts
    please help me
    Is there a way to dynamically construct code, such as:
    I'd like to write a method that receives as input a string identifying a node name, and use it as follows:
    wdcontext.current<InputNodeName>Element.get<AttributeName><do whatever I want>
    OR
    Is there a way to construct a string containing a command, and then execute it?
    Such as: If I construct the following in a string by concatenating different parts of the string: wdcontext.current<InputNodeName>Element.get<AtributeName>.<do whatever I want>
    Can I then pass the resulting string to some function that actually executes it?

    Hi,
    Unfortunately - there is no way to construct the command dynamically so that the command will execute.  The parameters that are part of teh command may be dynamic (using Super classes and method overloading).
    However, in case you want to write a single method that does all the function calling then what you need to do is:
    1.) Make a context attribute that will hold some code (1,2,3 or A,B,C etc)
    2.) Create the method that will read this attribute.
    3.) After reading the attribute write a switch case or an if statement that will run your command.
    Of course for this you will need to know all the required commands at design time.
    Thanks.
    p256960

  • Strings are immutable

    I want to know what exactly it means when u say that Strings r immutable.I need to understand with ex.please.There r StringBuffers to handle it we say.
    We can concatenate a string with another too. SO what is immutable means?
    CAn anyone help?Thanks in advance.

    Immutable means that the object can not be modified after it is constructed. For Strings, there are no methods that allow the value of the String to be changed. Thus, for a every new value, a new String object must be created. StringBuffers on the other hand, have methods like append and setCharAt that allows the value stored to be changed. You can create one StringBuffer object and keep altering it.
    Concatenation does not actually modify a String. It creates a new one. Notice how you have to assign the concatenated value to something.
    String str1;
    str1 = "test ";
    str1 + "string";
    System.out.println(str1);  // concatenation didn't modify str1
    str1 = str1 + "string";  // assign a new string which is the concatenation of str1 and "string" to str1
    System.out.println(str1);  // str1 refers to a completely new String, the concatenation
    StringBuffer sb1;
    sb1 = new StringBuffer("test ");
    sb1.append("string");
    System.out.println(sb1);  // sb1 was modified
    [\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Coercing string to MovieClip class

    I've been learning coercion between String and Number and
    simple stuff, but now I have a class that the books don't cover.
    This is best explained by example (this isn't the end goal, just a
    learning example).
    On the stage in frame 1, I have a MovieClip instance named
    shape_mc.

    In your first post you create a variable fubar with no
    particular type and then make it a String by concatenating two
    other variables. Next you attempt to cast String to MovieClip -
    this is what is wrong with the code. Casting works only if an
    object somehow is related to other object - in this instance if
    fubar data type was related somehow to MovieClip (by extension for
    example).
    In order to use a string to point to an object - you need to
    use an associative array syntax:
    parentObject["string"] - given that an object "string" is in
    the scope of parentObject.
    The following syntax will work (if the movieclip is in the
    scope of "this"):
    var pre:String="shape";
    var suf:String="_mc";
    var fubar:* = MovieClip(this[pre + suf]);
    Again, the key is to use a correct scope.
    As for the flv files, there is no need to cast at all. FLVs
    are not MovieClips. It is not clear how you want to play FLVs. Are
    they on the server? If so - you need the url to them only (which
    are strings). If they are progressive (downloaded via http) your
    code may look something like:
    var flvURL:String;
    function clickListener(e:MouseEvent):void{
    flvURL = e.target.name.toString().split("_")[0] + "_flv";
    //some time later:
    netStream.play(flvURL);
    Of course this is just a concept - real code should be
    different.

Maybe you are looking for

  • Visual Voicemail gone after upgrade to 2.0 (and porting number)

    Anyone else experience this? I upgraded to 2.0 and at the same time I ported the old iPhone to another cell phone number on my account with ATT. The upgrade to 2.0 and porting appeared to go OK as everything else is working EXCEPT when on the phone a

  • TS3540 Iphone 4S won't sync with iTunes after update to 11.1.3

    I have updated all softwares on my Macbook Air 10.7.5, included the iTunes 11.1.3. Once i plugged my Iphone 4S IOS 7.0.3, iTunes wouldn't see it, recognize it or sync. Other iphones show up. What is up? HELP! It's driving me crazy! Thank you! Melanie

  • MRP stoage location -  create reservation and external demand

    Hi Our company using  MRP for sloc - ROP - type VB plant 1000 with sloc 1 (Distribution Center) sloc 2 (branch) - planning at storage location sloc 3 (branch)  -planning at storage location currently if I run MRP, a reservation is created from sloc 2

  • Special fonts to the long text

    Hi all, I want to apply special fonts to the long text which I am saving using save text. I have a container in which I am wrintin the text,Now I want to provide the functionality such that I can make few lines bold,few undelined etc. same as we have

  • Same XMP for PDF and MS WORD

    I have made a XMP for al the Pdfs that we have .. and I was wondering if I can use the XMP in MS WORD .. :-/ Am using for now Office XP soon it will Office 2003 thnx Helda