How do to concatenate the strings having single quote and ampersand

Hi all

I have a task to concatenate two columns under SID - SNAME.

Input parameter is: sid. We can pass multiple parameters: sid

CREATE TABLE TABLE1 (NUMBER SID, SNAME VARCHAR2 (100));

Insert into TABLE1 (SID, SNAME) values (1, 'SURF UP');

Insert into TABLE1 (SID, SNAME) values (2, 'GNLV STYLE & KEY');

Insert into TABLE1 (SID, SNAME) values (3, 'ESSENTIALS NORTH & SOUTH');

Insert into TABLE1 (SID, SNAME) values (4, "Of Ora");

Select * from TABLE1;

SID SNAME
1Of THE SURF's UP
2KEY & GNLV STYLE
3ESSENTIALS NORTH & SOUTH
4ORA

Expected results

1. with the setting entry: sid in (1,2)

Output: 1 - SURF to the TOP, 2 - GNLV STYLE & KEY

2. with the setting entry: sid in (1,2,3,4)

Output: 1 - SURF to the TOP, 2 - GNLV STYLE & KEY, 3 - ESSENTIALS NORTH & SOUTH, 4 - ora

I tried to use the below query,

Select (select RTRIM (xmlagg (xmlelement (c, sid |')))) -' || SNAME | (",")) .extract ('/ / text()'), ',')

AS concatenated FROM table1 where «,» | : para. ',' like '%', | SID | %') as double concat;

What I get for output is as below:

1 SURF & apos; S upwards, 2 - GNLV STYLE & amp; TREND

I'm not handling apstrophe and ampersand correctly.

Can you please help me.

Thank you

What I get for output is as below:

1 - SURF to the TOP, 2 - GNLV STYLE & TREND

I'm not handling apstrophe and ampersand correctly.

Yes. This is what happens when you use a method that is not understood.

The answer to your question is dependent on the version and already well covered in the FAQ.

See 'Channel aggregation' in Re: 4. How can I convert rows to columns?

If you are on 11.2 and beyond, use LISTAGG function.

Regarding your present attempt, since you are extracting text() nodes on an aggregate of XMLType, the result is still a valid XMLType and therefore shows the XML characters reserved in their forms with escape sequence.

If you want to stick with the XML approach, from 11.1, is the right way to handle this situation:

SQL> select rtrim(
  2           xmlcast(
  3             xmlagg(
  4               xmlelement(e, sid ||' - '||sname||',')
  5             )
  6             as varchar2(4000)
  7           )
  8         , ','
  9         ) as concatenated
10  from table1
11  where ',' || '1,2,3' || ',' like '%,'|| sid || ',%' ;

CONCATENATED
--------------------------------------------------------------------------------
1 - SURF'S UP,2 - GNLV STYLE & KEY,3 - ESSENTIALS NORTH & SOUTH

In earlier versions, use either:

select rtrim(
         dbms_xmlgen.convert(
           extract(
             xmlagg(
               xmlelement(e, sid ||' - '||sname||',')
             )
           , '//text()'
           ).getstringval()
         , 1
         )
       , ','
       ) as concatenated
from table1
where ',' || :para || ',' like '%,'|| sid || ',%' ;

Mun

select rtrim(
         utl_i18n.unescape_reference(
           extract(
             xmlagg(
               xmlelement(e, sid ||' - '||sname||',')
             )
           , '//text()'
           ).getstringval()
         )
       , ','
       ) as concatenated
from table1
where ',' || :para || ',' like '%,'|| sid || ',%' ;

Tags: Database

Similar Questions

  • Display the string with single quote

    Hello..

    I have a doubt.

    Below the statement works very well to get the result in single quotes as 'Hello world'
       SELECT '''Hello World'''
       FROM dual;
    Now my question is why we get error when we try to do the same.

       SELECT ''Hello World''
       FROM dual;
    Please let me know the reason, if an organization is to have an idea.

    Thank you
    Suri

    To print a single quotation mark, use two single quotes (IE he "s to print from) and to print a string to write the string inside the single quotation mark as"Hello Word ".
    You want to print "Hello World" your sql will be

    SELECT '''Hello World'''
       FROM dual;
    

    You get the following error as search oracle of KEYWORD Analyzer after "that a chain is closed using the" quote

    SELECT ''Hello World''
       FROM dual;
    ORA-00923: FROM keyword not found where expected
    
  • How to concatenate the string with a digital command?

    Hello

    How to concatenate the string with a digital command?

    Thank you.

    I think I forgot to add the semicolon, what you can do is, drag the CONCATENATE function and add semicolon.

  • concatenate the strings comand...

    sHello,

    I must repeat that channels below a large part of the time (ON SQL MORE);

    Now I do with comand of copying and pasting each string, but it is very unconfortable.

    How to concatenate the string in a string only, or max 2 strings?

    .. .so I need that I copy/past comand to do all operations of this...

    COMNAD STRING:

    create user Patrick identified by loan;

    Grant connect, create session, imp_full_database to Patrick;

    GRANT to CREATE ANY WORK to Patrick;

    modify user quota unlimited Patrick on the SYSTEM;

    grant unlimited tablespace to mx;

    THANKS FOR HELP

    sqlplus command line allows you to paste together multiple orders (lines) and it then executes sequentially.

    Hemant K Collette

  • How to get the string (specified by row and column) of txt file with labview

    Hello world

    How to get the string (specified by row and column) of txt file with labview

    THX

    As far as I know, a text file has no column.  Be more specific.  Do you mean something like the 5th word on line 4, where the words are separated by a space, and lines are separated by a newline character?  You can read from the spreadsheet String function and set the delimiter to a space.  This will produce a 2D channels table.  Then use the table to index and give the line number and column number.

  • First HP: how to enter a number complex, using single quotes

    Hello

    This is probably a stupid question, but how do you enter a charager apostrophe on the first HP RPN mode?

    I read the section in the guide of the user on enteringer a complex numbers in RPN mode.    Using (3.4) works fine, but I'm curious to know how to enter using the method indicated in the doc:

    "In RPN mode, complex numbers must be in single quotes and require an explicit multiplication.
    For example, 3-2 * i'. "

    For the life of me, I can't find the character of simple-qoute.     Maj 9' does not work.

    It's late and without a doubt, it is right in front of me, but I can't.   I feel a "time da come...» »

    Thanks in advance,

    OK, found it...      (Maj)

    (I cheated and google it)

  • I have a mac pro 3.1. How can I transfer the system to a new and bigger drive?

    I have a mac pro 3.1. How can I transfer the system to a new and bigger drive? The old drive is much too small.

    I'm not familiar with your model computer, but there are several ways to do so.  If the computer can accommodate multiple disks, you can install the new drive next to the former.  If she does not accept another disk, you can in these external adapters for about $30, which allow you to attach a bare drive to a computer with USB.  Then, you clone the internal drive to the new. Cloning is a special form of the copy.  It copies all files including startup system files so that your new drive is essentially identical to the first.

    Double clone - http://www.bombich.com/software/ccc.html

    SuperDuper - http://www.shirt-pocket.com/SuperDuper/SuperDuperDescription.html (shareware)

    IBackup - http://www.grapefruit.ch/iBackup/index.html (free)

    The restore function of disk utility included in directions of OS X. alarm - http://discussions.apple.com/message/8799711#8799711 (a former post but can still work).

    Clone the old drive to the new, then install a new one.

  • How can I reinstall the my working folder icon and the icon of internet explorer in my desktop

    How can I reinstall the my working folder icon and the icon of internet explore on my desk that had been removed in some sort tried to watch in recycle bin bit is not there also tried to restore to an earlier date, but it will not reinstall

    Assuming you are using Windows XP (you asked this question in a forum of Windows XP), download TweakUI for XP http://windows.microsoft.com/en-US/windows/downloads/windows-xp (left column, third item down).

    Install and run TweakUI.  Click "Desktop", and then select the items you want to have appear on the desktop.  Click OK.

  • AS100 how to ride in the middle of my chest, and then point to the front?

    AS100 how to ride in the middle of my chest and the point forward, not on the side?

    Hello positivguy,

    See the following link which may answer your question. Chest mount harness.

    If my post answered your question, please mark it as "accept as a Solution.

  • How I can scan the registry valuHi, how I can scan the Windows 7 registry value and how do I come to know if the registry value is same as it has been installed previously?

    Hello

    How can I scan the Windows 7 registry value and how do I come to know if the registry value is same as it has been installed previously?

    Hello
     
    The Windows registry is a vast and vital part of the computer, which continues to evolve being modified or deleted or new entries are created all the time.
     
    Case where the registry keys of change.
     
    At startup
     
    So that updates
     
    While making customization or custom settings in windows
     
    While to install the software
    Virus... etc.
     
     
    Each click Open and save is related to the registry.
     
    This is something very tedous to verify the integrity of a registry of windows with all of the above modifications being carried out.
     
    You can back up the registry of the computer after you install Windows new and update with all Windows updates and the custom software, into a registry backup or create a system image / restore point.
     
    Please visit these links for more information.

    Windows registry Description of the audit of the Windows Registry tool (Scanreg.exe) How do I add, edit or delete subkeys in registry and values by using a registration entries (.reg) file Hope this information helps

     
     
     
  • How can I make the popup with empty fields and create new record?

    I would use a popup create new record.
    I created an af:popup drag and drop a data control VO in jsff. Then, I created a button and place an af:showPopupBehavior. I was able to pop-up window by clicking on the button.
    However, the window filled with information from the record 1. and when I select a record in the table and click on the popup, the popup is filled with this record.
    How can I make the popup with empty fields and create a new record by recording the popup?
    Thank you

    Hello

    You must call the CreateInsert for the underlying ViewObject operation when opening the popup because it does not allow to clear the input field, you must have a new record created

    Frank

  • How can I get the string value displayed on a digital control defined for the relative time.

    I have a digital potentiometer to display relative time in increments of 30 minutes.

    I want to record the value displayed on the control string.  Unfortunately, when I use the "convert to decimal string.vi" number, the resulting string is just the value in seconds.

    How can I get the value as a string? (for example 01:30 for an hour and thirty minutes)

    Thank you

    Sean

    Hi Sean.C!

    M_Peeker's suggestion is a good thing.  A stage that could clarify things is that you must set the % t <%H:%M> format string entry.

    < br / > Kristen:.

  • How do I get the content from another file and paste it into the active document instead of certain string?

    I am newbie in indesign scripting of animals. So I apologize because I couldn't post my essays.

    Objective:
    I have a .indd document which will be a figure of legend, label etc. I need to copy the content (a figure that is editable) else file indd of this document where the tag figure exists.

    For example:
    Sample.indd

    Some text Fig.1.1 caption some text 

    I need to copy the contents of figure1.indd and paste in the document sample.indd where Fig.1.1 string exist and so forth. Now I do it manually. But am supposed to automate this process.

    So, I need some hint how to do it using extendscript?

    I found something like below, to do so, but I have no idea to develop it further and also do not know if this approach is correct my results. Please help me

    myDocument=app.open(File("file.indd"),false); //opening a file to get the content without showing.

    myDocument.pages.item(0).textFrames.item(0).contents="some text"; //here I could set the content but I don't knw how to get the content

    // ?????? Then I have to paste the content into active document.

    Try this test nicely to your and end, hope this will help you.

    var myDoc = File("/D/Sample.indd");//Figure File
    var myFigDoc = File("/D/Figure.indd");//Destination File
    app.open(File(myFigDoc));
    app.activeDocument.pageItems.everyItem().select();
    myObj = app.selection;
    var myGroup = app.activeWindow.activePage.groups.add(myObj);//Grouping the objects
    myGroup.select();
    app.copy();
    app.open(File(myDoc));
    app.findGrepPreferences = app.changeGrepPreferences = null;
    app.findGrepPreferences.findWhat = "Fig 1.1";//Figure caption text
    app.findGrepPreferences.appliedParagraphStyle = "FigureCaption";//Figure Caption Style
    myFinds = app.activeDocument.findGrep();
    for(var i=0;i		   
  • How do to convert the string (with the Hex data) in number?

    Hello

    I use TestStand 3.5 to automate a few test cases associated with boot loader.

    The requirement is that I need to read the value in some places for specific address. The values of these addresses are stored in a hexadecimal format.

    We have a step customized in TestStand through which we can read these values by address, but she returns as the type "String".

    For example, the value to 0 x 0000008 is 000001 B 2, and he returned in Locals.Value_Read as "000001 B 2" in the string.

    Is it possible, I can convert the string "000001 B 2" to a number?

    I tried to use the function-> val (locals. Value_Read), but it is return 0 as TestStand figures that the input string is not representing the valid number.

    Please help me with this.

    Thank you and best regards,

    Niraj.

    Try: Val ("0 x" + Locals.Value_Read)

  • How to merge multiple images into a single document and place them on the bottom

    I am trying to merge multiple images in a single document and arrange them on this document and save it.  Is it still possible?  There are five black and white drawings that I've resized at all have the same size.  Tutorials that I looked at, but it seems that everyone has another way to do this and all are very confusing.  Thanks for your help.

    It is not surprising that "everyone has a different way to do this." In Photoshop that is common. Try this:

    1. open a new file large enough to accommodate five drawings.

    2. open each design, click on it in the layers panel and drag and drop it in the layers panel to the new file.

    3. Repeat until all are in the new file

    4. use the move tool to reposition. (They are on separate layers)

    5 flatten the file if you wish (but save a version not flattened for future editing)

Maybe you are looking for