a single comparison string and get pure SQL strings,

Hi all

These are two strings

S1 = "HAS, B, C, D, F;
S2 ='C, F, H, B, A, K';

output should be like unique string values.

S3 = A, B, C, D, F, H, K;


How to get this in pure sql...

Thanks in advance,

Roots

Hello

In a relational database, each column of each row needs to store a value, not a repleating group of values, such as a delimited list. It is so basic to the design of database it is called "First Normal Form." You don't have to follow the rules like that, but if you do not, your code will be complicated, inefficient and prone to errors. It might be better to re-design your application so that each value was on a separate line.

If you can't do that, then you can start by dividing your lists of delimitd in separate lines. Then you can easily fond distinct values and use any technique of chain aggregation to combine the results into an output line.
Here's a way to do this:

WITH     got_params     AS
(
     SELECT     'A,B,C,D,F' AS str, 1 AS str_id     FROM dual     UNION ALL
     SELECT     'C,F,H,B,A,K',          2            FROM dual
)
,     got_part_cnt     AS
(
     SELECT     str
     ,     1 + LENGTH (str)
            - LENGTH (REPLACE (str, ','))     AS part_cnt
     FROM    got_params
)
,     cntr          AS
(
     SELECT     LEVEL     AS n
     FROM     (
              SELECT  MAX (part_cnt)     AS max_part_cnt
              FROM    got_part_cnt
          )
     CONNECT BY     LEVEL     <= max_part_cnt
)
,     got_substr     AS
(
     SELECT DISTINCT
            REGEXP_SUBSTR ( p.str
                           , '[^,]+'
                    , 1
                    , c.n
                    )          AS sub_str
     FROM    got_part_cnt p
     JOIN     cntr          c  ON     c.n     <= p.part_cnt
)
,     got_r_num     AS
(
     SELECT     sub_str
     ,     ROW_NUMBER () OVER (ORDER BY  sub_str)     AS r_num
     ,     ROWNUM                                        AS r
     FROM     got_substr
)
SELECT     MIN ( SUBSTR ( SYS_CONNECT_BY_PATH (sub_str, ',')
                      , 2
                      )
         )          AS unique_sub_strs
FROM    got_r_num
WHERE     CONNECT_BY_ISLEAF     = 1
-- START WITH     r_num     = 1
CONNECT BY     r_num     = 1 + PRIOR r_num
;

It works in 10.2.0.2.0 Oracle Express Edition, which is the only database, can I use it right now. For the main query, you should be able to say:

SELECT     SUBSTR ( SYS_CONNECT_BY_PATH (sub_str, ',')
            , 2
            )     AS unique_sub_strs
FROM    got_r_num
WHERE     CONNECT_BY_ISLEAF     = 1
START WITH     r_num     = 1
CONNECT BY     r_num     = 1 + PRIOR r_num
;

but, when I try it on my database, I get only "A, B" as output. CONNECT is very buggy in Oracle 10.2; If you have Oracle 10.1, simplest form might work.

The above query can be shortened, some, but I wrote it this way to make it easier to understand.
For example, you can combine got_sub_str and got_r_num subqueries. If you do so, substitute DENSE_RANK, ROW_NUMBER.

This does not imply that the sub-qtrings are all 1 characters long. If they are, the query can be simplified.

For more information on aggregation of chain, see
http://www.Oracle-base.com/articles/10G/StringAggregationTechniques.php

Tags: Database

Similar Questions

  • REST GET PL/SQL: Worked in 4.2.1 and 2.0.1 isn't in 4.2.5 and 2.0.6

    Hello

    I have asked this in the forum of the APEX, but I was wondering if this could be the best location.

    I have a REST to GET PL/SQL call that verifies an authorization header, performs a routine package which inserts data and then sets the location to a new URL where the customer collects the results of another call from PL/SQL GET REST:

    DECLARE
      l_ref        NUMBER;
      l_authorized BOOLEAN;
      l_body       BLOB := :body;
    BEGIN
    
      IF rest_util.authorized(:authorization) THEN
    
        rest_interface.handler(p_content_type => :contentType
                              ,p_body         => l_body
                              ,p_ref          => l_ref
                              ,p_status       => :status);
    
        :location := 'results/' || l_ref;
    
      ELSE
        :status := 401;
      END IF;
    
    END;
    
    
    
    
    

    This works very well in my 4.2.1 instance, but in a 4.2.5 instance it fails with the following text:

    Caused by: java.sql.SQLException: ORA-06550: line 1, column 8:
    PLS-00103: Encountered the symbol "" when expecting one of the following:
    
       begin function package pragma procedure subtype type use
       <an identifier> <a double-quoted delimited-identifier> form
       current cursor
    
    
    
    
    

    I also note that the ToolTip for the Type of Source says:

    
    PL/SQL - Executes an anonymous PL/SQL block and transforms any OUT or IN/OUT parameters into a JSON representation. Note that this option is only available when the HTTP method selected is one of the following: DELETE, PUT, POST.
    
    
    
    

    I was just lucky in 4.2.1 or is a documentation error and I should be looking at something else?

    Another thought... my work version uses 2.0.1 ADR and ADR 'broken' a 2.0.6. Is the java.sql.SQLException generated by the receiver or the APEX?

    Patched APEX and ADR on the system of 'work' to match that of "broken" and it still works! Now, the only difference I see is that work, we're on a database 11g and the other is 10 g?

    Post edited by: AndyH the same message of Type Source appears to 4.2.1 and 4.2.5

    Post edited by: working version AndyH corrected to match to broken - still works.

    It's a possible 10g known 'feature' - If you change a resource on a 10g database you will get the error the «» It seems that the routine that executes the PL/SQL cannot deal with carriage returns. The solution is to remove all your transport returns so the block is a single line. I'll find the bug number when I return to the office.

    On the plus side, you can import the restful service to another instance without problem.

    Bug 17695075 : RESTFUL SERVICES - CHANGE the error CAUSE CODE

  • JI downloaded cs6 design and web premium in a single folder, I always get the message missing archives... I use pc and ie10 none of the solutions proposed if you please

    I downloaded cs6 design and web premium in a single folder, I always get the message missing archives... I use pc and ie10 none of the solutions proposed if you please

    Hello

    Some Windows product downloads include two files: a file .exe and .7z file. To install the software, it is necessary that the two files are downloaded and located in the same folder. Otherwise, an error may occur when you start the Setup program. Errors are "Windows cannot open this file" and "file archive part Adobe [product name] is missing."

    You can check the link for more information below.

    Start the program installation after the download Acrobat X, CS5.5 and earlier versions

    Please try the link below to download the product again.

    https://helpx.Adobe.com/x-productkb/policy-pricing/CS6-product-downloads.html

    I hope this helps.

    Kind regards

    Vivet

  • the arduino comparison string

    I'm doing a project requiring labview + Mega1280 arduino + xbee. and I encountered a problem. I send you a string of arduino via xbee. LabVIEW Gets the string and try to compare it with a constant string that I chose. but each time the result of the comparison is fault. I tried to send the numbers: serial.println ("1"), I tried to send string: serial.println ("red of detection"), nothing works. I placed a prob on the wire of the input string and it shows me the right data, but the "equal?" is always fault. I would appreciate if you could help me.

    Thank you, Ben

    It is something quite common in the serial communication.  You probably unprintable characters in the string, such as a carriage return. Put an indicator (not a probe) on the returned string and set the display mode of the indicator of string for something as "------" codes. This will tell you if you have non-printable characters. If so, you have to strip before being compared, or include them as part of the comparison string.

  • Pure SQL Exception: Caused by java.lang.NullPointerException.

    Could not invoke the 'Query_XX_Flag' against the 'db' operation due to: []

    LIAISON. JCA-11633

    Pure SQL exception.

    Pure SQL select DECODE Execute (MSI. ATTRIBUTE5, 'Y', 'True', 'False') XX_flag of msi mtl_system_items_b where inventory_item_id =? and rownum = 1 failed.

    Caused by java.lang.NullPointerException.

    The pure SQL option is for only border use cases and provides simple but minimal functionality.  Maybe try the "Run an operation on a table" option instead.  This exception is considered non reproducible, probably due to an error of modeling.

    Version: Oracle soa suite 12.1.3 - jdk1.7 - (local) Windows 7 operating system

    I get the above exception in one of our Async BPEL of the process, and it happens like 1 in 5 cases.

    As you can see, the reason for the error is not really clear and I see nothing diagnosis either connects.

    And when I start this process from the console, it's getting completed successfully.

    We are not exceeding the number of DB connections either.

    Here's our design:

    BPEL Poller-> (several calls) Async BPEL process-> database adaptor with above query

    What could be wrong? What is the reason for this odd behavior?

    Thank you

    Prasanna

    This error could not be reproduced on the test environment, where the SOA server with oracle DB of the backend rather than javaDB on integrated server is installed...

    So if someone were unexpected exceptions on the local server and then try to test on the test/UAT/pre-production environments.

    Prasanna-

  • Any difference between the separate function and aggregation in sql query cost?

    Hello
    I've run many models sql stmts - such as:
    one) using a single table
    (b) using the two tables, using simple joins or outer joins

    but I didn't notice a difference in sql stmts in cost and implementation plan...
    In any case, my colleague insists on only using the aggregate function is less expensive compared to
    separate... (something I've not confirmed, that is why I believe that they are exactly the same...)

    For the situation described above under 1 sql... We could for example use
    select distinct deptno
    from emp
    select count(*), deptno
    from emp
    group by deptno
    select distinct owner, object_type from all_objects
    select count(*), owner, object_type from all_objects
    group by owner, object_type
    Have you ever found no difference between the two...?

    Note: I use Ora DB 10g v2.

    Thank you
    SIM

    Alexandre Gelin says:
    function separate and aggregation are for different uses and can give the same result, but if you use the aggregate function to get the separate records, it will be expensive...

    really? I find them almost identical to 11g. Actually GROUP BY is almost always more fast for me in the old days.

    article about this askTom Re: any difference between the separate function and aggregation in sql query cost?
    This applies mainly to the older oracle versions http://www.oracle.com/technology/products/rdb/pdf/distinct_derivedtables_groupby_sort_tech_article.pdf

  • Try to install Windows 8.1 and get error message: boot disk cannot be partitioned

    I am trying to reinstall Windows on my Mac 8.1 and get the message error "boot disk cannot be partitioned or restored to a single partition.  I ran across the 'bugs' usual suggested, that I found online with no luck.  Attached are the screenshots that can help.

    How have you managed to get two HDs of recovery on the same disc? You have two versions of OS X installed on this drive in the past?

  • error 80070643 came on my computer from 14/03/2012. He and get very frustrated. Please help me.

    I'm a gamer, I mainly use my computer to play games on the internet as though I buy games, etc.  I use my computer as an outlet the Dungeon, entertain me, like watch movies on Netflix, play games and connect with friends via Hotmail, Gmail and so on.

    From 14/03/2012, my computer has received an update from Microsoft for games or games, but my computer does not except her and instead, I got this error 80070643.  I want to know how to fix this error since then and get very frustrated.  Please someone who knows the Vista program could help me I am only a single old white lady who fights depression and my computer is my best friend.

    Hi AnneBest,

    Update failed?

    Try to install the update in a clean boot state. If a 3rd party program prevents this update of installation, this will remove the conflict.

    If you are unable to install the update and you said, the other troubleshooting steps did not resolve the issue, follow the steps in this document to perform an InPlace upgrade. Your current installation of Windows will be reset without affecting your personal information.

    Note that it is advisable to make sure you have a recent backup of your data and how to reinstall your software before all the major troubleshooting steps.

  • Try to install 4 ' important'updates on Windows Vista and get error codes: 80070641.

    Try to install 4 ' important'updates on Windows Vista and get error codes: 80070641, who has had a lot of answers posted but none does not seem to work and I tried to install this upgrade for the last 6 months! (I did one where you made sure something is running in the Control Panel, but it works just not - I HATE Vista!)

    Now just got a new error code: 6 to 8.

    The updates, I can't update (!) are:

    1. SQL Server 2005 Express Edition Service Pack 4
    2. Update of security for MSOffice 2007 System
    3. Update for MS 2007 Office system
    4. Update for MSOffice Outlook 2007 Junk email filter

    Unfortunately I'm not technically proficient at all and do not understand the jargon I've read on this site so if anyone has an answer, please could you write it as if you were talking to your grandma who only discovered what a mouse!  ;-)

    Thanks in advance

    Sharon

    original title: error codes: 6-8 and 80070641

    Hello

    see if that helps to fix:

    How to reset the Windows Update components?

    There is also an automatic 'fix - it' here

    http://support.Microsoft.com/kb/971058

    Also, try to put the KB numbers in the search on the link below and then manually download the

    http://www.Microsoft.com/downloads/en/default.aspx

     

    or please repost your question in the correct windows update forum

    http://answers.Microsoft.com/en-us/Windows/Forum/windows_vista-windows_update?page=1&tab=all

  • Complete used Windows 7 install and get a physical picture of the blue screen

    Monday my computer was play music on a hard disk when it entered into sleep and started screaming.

    It meets all of the keyboard controls, so I reset by holding down the power button.

    Since he refuses to load windows 7 but also put white dots on my screen at regular intervals when the system goes through its parameters.

    He enters the window of windows beginning it loads the logo entirely with three batches of 3 blue stripes run from top down in the background, but don't effect the logo or the words at all but then says that there is a windows error and can not load.

    Asked to do a system repair that may be defective and so I tried to reinstall the operating system instead. The screen has once again a lot of blue lines wavy background through the normal screen of windows 7, which is at the back of the repair of the system window.

    I wipe the partitions drive and begin the installation. It goes through the whole plant, until this happens at "Completing installation" then it blue screens says physical dump but blinks in and out and can not read. The rear crossbar start load windows logo, then opens pop-up box saying "installation could not complete due to an unexpected error, please click ok to reinstall windows" and then he turns around and does the same thing again and I'm going around and around.

    The graphics card can't be gone because on some screens (like the logo screen to motherboard to get into the Bios etc) there is no error at all, it seems to be nothing to do with black Bios windows or windows screens it puts these error lines. Also the motherboard doesn't mean that there is an error or a fault with it either.

    I checked and reformat the hard drive and it works without error.

    Tested my 4 GB of ram, who also spent and no mistake. There's nothing wrong with the power supply.

    I'm concerned, it's something with my card graph and map mother, or is - something in the BIOS?

    WD - 500 GB HDD

    Corsair XMS3 - 4 GB of ram (2x2gb 1600 mhz)

    Asus P7P55D-E motherboard

    Sapphire Pure 950w

    Processor i5

    I don't know what to do other than replace the motherboard?

    I CAN'T get to the office so no start menu stuff please as I can't do it. So I can not download the minidumps or update my system. Unless someone knows how can I update the Bios and drivers without current initialization?

    Thank you for your advice. Thanks to everyone for their advice. I got my system running a bit once the new parts increase.

    I did some experiments.

    I put my brothers old graphics card in my computer and loaded with the operating system without problem.

    Does not perform all the updates no bother. I tried my card on day of reclamation, but once again before you complete the download, it crashes and we're back in the loop.

    So I think that the map was officially.

    I ordered some new parts and make and upgrade with certainly a new graphics card.

    But it works now.

    So, if anyone has the same problem.

    Find another computer and write a check for the new bios for your motherboard and do a flash upload if your motherboard has this function as mine did.

    Get out of your hard drive and get the data off it by plugging in a new computer.

    Reformat and reinstall the operating system.

    If you have problems with your screen such as lines and points like I did then your operating system won't load and you will get "nvlddmkm.sys" your graphics card is totalled.

    If she does not do and update on your graphics card.

    That's all you can do.

  • compatibility of Windows 7 Home Premium with Visual Studio 2010, Visual Studio 2012, Sql Server 2008 and can be Sql Sever 2012.

    Hi, I'm going to buy a new laptop in which I get Windows 7 Home Premium. I'm going to use MS Visual Studio 2010, Visual Studio 2012, Sql Server 2008 and can be Sql Sever 2012. I'll use the other tools of development also. I just want to know fact these races of software in this operating system.

    It's the operating system have a compatibility issue with these software or other tools of development.

    Best place to look is the MS site for these products and consider the requirements specified

  • Get the SQL statement error programmatically

    Hello

    error SQL in the FORMS, you can display the erroneous SQL statement pressing (shift) (Ctrl) E on the screen. Is there a way to get the text of the SQL statement in a PL/SQL function for logging purposes?

    I get the error using SQLERRM, it's not a problem. But how can I get the SQL text of the statement?

    Thanks and regards,

    Sascha

    Sascha,

    You should be able to use the: SYSTEM. System LAST_QUERY variable forms.

    Craig...

  • Run ViewObject of bean and get the result.

    How can I run my bean ViewObject and get all the lines that jdev ViewObject Return.My Version is 11.1.1.5.0

    I tried to use this way but his return 0 rows, but when I check through Toad query returns data.

    DCIteratorBinding iter =

    getDCBindingContainer () .findIteratorBinding (name);

    iter.executeQuery ();

    Row [] rowArray = iter.getAllRowsInRange ();

    Thank you

    Raul

    Hello

    Its solved now thanks.

    DCIteratorBinding = voIterator

    ADFUtils.findIterator ("MyVObject");

    Object ViewObject = voIterator.getViewObject ();

    object.setNamedWhereClauseParam ("id", String.valueOf (id));

    voIterator.executeQuery ();

    Row [] rowArray = voIterator.getAllRowsInRange ();
    Thank you

    Raul

  • Can be combined in the same script Get - VM and Get - view?

    Hello

    I am trying to find a way to combine these two Get - VM and Get - view in the same script.

    Script # 1

    Get-Cluster Management | Get - VM | Select Name,@{Name="HardwareVersion; Expression = {$_.} ExtensionData.Config.Version}}

    Script # 2

    Get-Cluster Management | Get - vm | where {$_.powerstate - don't "PoweredOff"} | % {get-view $_.id} | Select Name, @{Name = "ToolsVersion"; {Expression = {$_.config.tools.toolsVersion}}, @{Name = "ToolStatus"; Expression = {$_.} Guest.ToolsVersionStatus}}

    I've always had problems try this out and now, I need to combine them into a single script in figure.

    If you can help me or point me in the right direction would be great.

    Thank you

    Mike

    Curiosity got the best of me so I came with this. You had more correct, but you need to make a custom object so that the properties you are looking for can all be used simultaneously.

    It does not use the pipeline and uses a foreach loop.

    ----------------------------------------------------------------------------------------------

    $vms = get-Cluster Management | Get - VM? {$_.powerstate - don't "PoweredOff"}

    {foreach ($vm to $vms)

    $VMID = get-View ($vm.id)

    New-object psobject-property @ {}

    VM = $vm

    HardwareVersion = $vm. ExtensionData.Config.Version

    ToolsVersion = $VMID.config.tools.toolsVersion

    ToolsStatus = $VMID. Guest.ToolsVersionStatus

    } | Select the virtual machine, ToolsVersion, HardwareVersion, ToolsStatus

    }

    ----------------------------------------------------------------------------------------------

    Or use this option if you like the pipeline with Foreach-Object approach.

    ----------------------------------------------------------------------------------------------

    Get-Cluster Management | Get - VM? {$_.powerstate - don't "PoweredOff"} | % {

    $VMID = get-View ($_.id)

    New-object psobject-property @ {}

    VM = $_

    HardwareVersion = $_. ExtensionData.Config.Version

    ToolsVersion = $VMID.config.tools.toolsVersion

    ToolsStatus = $VMID. Guest.ToolsVersionStatus

    } | Select the virtual machine, ToolsVersion, HardwareVersion, ToolsStatus

    }

    ----------------------------------------------------------------------------------------------

    Both methods are correct that I can see. I tried both and both work well. You can easily piple only out to Export-Csv at the end of the select line. I hope this helps.

    Andrew

    Post edited by: andrewsardinha
    condition of powerstate added to each block operator and foreach-object script to the last script block.

  • VM combining the Get - And Get-VMGuest CSV output

    Hello

    I am trying to generate a CSV file that combines different properties between the cmdlets Get - VM and Get-VMGuest but struggled.

    I am aware that the cmdlet Get - VM will give me an output like the number of processors, amount of memory per VM, vm name etc., but also want to retrieve properties such as its IP address, running OS, hostname, etc in the same CSV report.

    I tried to mix the taste.

    Get-vmguest - vm (get - vm). Select-object vmname, osfullname | Export-csv c:\vm_osreport.csv

    and a previous post by LucD-

    --------------

    Get - vm | %{
    $_ | Select name. Out-Default
    $_ | Get-VMGuest | Select the State, IPAddress, OSFullName | Out-Default
    }

    Now if you want the result in 1 object (or an array of objects) you could make

    Get - vm | %{
    $vm = "" | SELECT name, State, IPAddress, OSFullname
    $vm. Name = $_. Name
    $guest = $_. Get-VMGuest
    $vm. State = $guest. State
    $vm. IPAddress = $guest. IPAddress
    $vm. OSFullName = $guest. OSFullName
    $vm
    }

    --------------

    but can't seem to get what I want. Basically, I'm looking for is the output to a CSV file - next

    • vmhostname
    • IP address
    • numCPU
    • memoryMB
    • Allocated size of HD
    • GuestOS (as reported by VMTools)
    • Datacenter + file (if possible)

    Can anyone help please?

    Thank you!

    Given that the ownership of comments is present inside the VirtualMachine object returned by Get - VM, you can get these values without running the Get-VMGuest cmdlet.

    Something like that

    Get-VM  | Select Name, @{N="Hostname";E={$_.Host.Name}}, @{N="IP addr";E={[string]::Join(',',$_.Guest.IpAddress)}}, NumCPU,MemoryMB, @{N="HD size allocated (KB)";E={[string]::Join(',',($_.HardDisks | Select -ExpandProperty CapacityKB))}}, @{N="GuestOS";E={$_.Guest.OSFullName}}, @{N="Datacenter";E={Get-Datacenter -VM $_ | Select -ExpandProperty Name}}, @{N="Folder";E={$_.Folder.Name}} | Export-Csv C:\report.csv -NoTypeInformation -UseCulture
    

Maybe you are looking for