Result may contain the unique string or separated by commas must split into lines

Hi all... I searched through the forums and found a lot on separation with commas in lines; Although I'm fighting apply to my situation. I have data that looks at the below where I need to divide a value in several lines if she should be, but the same field in the table may also contain a string which should not be separated (indicated by the field 'Array' be 0 or 1)...
WITH t AS
(SELECT 1 as array, '"Banana", "Apple", "Pear"' as str FROM dual union all
SELECT 0, 'Fruit is delicious' FROM dual union all
SELECT 0, 'So are vegetables' FROM dual union all
SELECT 1, '"Bean", "Carrot", "Broccoli"' FROM dual union all
SELECT 1, '"Apple", "Banana"' FROM dual)
I looked through several of the connect_by on the forum posts, and I've not met one that divides a field if it should be, but not if it is not... maybe missed it because there are a lot of these requests on the forum!

If you are feeling more ambitious - the ultimate goal is to count the number of times where an answer appears in a table - view up to the last part of the data contain 'Apple', 'Banana'... the result are:
RESULT
----------
Banana             2
Apple              2
Pear               1
Bean               1
Carrot             1
Broccoli           1
Fruit is delicious
So are vegetables
I can always sort more later from the other fields in the table - but the result above would be my ultimate goal!

Any help is always appreciated. Thank you! 31%

Tags: Database

Similar Questions

  • Display data in the form of values separated by commas - need help

    Hi all

    I have some data formatted in the way below. The ID of the drug are the primary keys of the table and the first 9 digits in the drug ID are the same. They can be separated based on the last two digits.

    Type of drug drug ID
    00603107554 respiratory
    00603107556 cough and cold
    Antitussive-00603107558


    I want that data to be formatted as
    Type of drug drug ID
    006031075 respiratory, cough and colds, Antitussive

    I want to cut the last two characters, and format data. And the types must be displayed in the form of values separated by commas. Can someone help me?

    Thanks in advance

    Rambeau
    WITH t AS (SELECT '00603107554' Drug_ID, 'Respiratory' Drug_Type FROM DUAL
               UNION
               SELECT '00603107556', 'Cough and Cold' FROM DUAL
               UNION
               SELECT '00603107558', 'Antitussive' FROM DUAL)
        SELECT Drug_id, SUBSTR (SYS_CONNECT_BY_PATH (Drug_Type, ','), 2) Drug_Types
          FROM (SELECT SUBSTR (drug_id, 1, LENGTH (drug_id) - 2) drug_id,
                       Drug_Type,
                       ROW_NUMBER ()
                       OVER (PARTITION BY SUBSTR (drug_id, 1, LENGTH (drug_id) - 2)
                             ORDER BY Drug_Type)
                          rn
                  FROM t)
         WHERE CONNECT_BY_ISLEAF = 1
    START WITH rn = 1
    CONNECT BY PRIOR rn = rn - 1 AND PRIOR drug_id = drug_id
    
    DRUG_ID     DRUG_TYPES
    006031075     Antitussive,Cough and Cold,Respiratory
    

    just a note, I wonder if blushadow could consider adding techniques agg string to its very useful faq section because it seems a good
    request.

    Published by: pollywog on April 14, 2011 06:42

    Published by: pollywog on April 14, 2011 06:43

  • How can I get more results that contain the tag/bookmark appears in the awesome bar? Currently, it will show only 4.

    When I type a word in the address/url/awesome bar it's a word that I know that I used as a tag on several pages of a bookmark, only 4 results in the menu drop-down are marked pages of a bookmark. The rest of the pages in the menu drop-down are other pages available on the web. Because only 4 results are pages I tagged, the page I want to (and scoring) often does not appear. Is there a setting I can change to make it show more results? Or is there a way once I get the original results to add extra elements containing the tag / my favorites?

    This may be a problem with the Fastestfox extension.
    See Troubleshooting extensions and themes and problems of hardware acceleration to resolve common Firefox problems

    In the FastestFox Options, uncheck the 'Awesomebar improving '.

    See the 10 image in the image gallery: https://addons.mozilla.org/firefox/addon/9825

    https://addons.Mozilla.org/IMG/uploads/previews/thumbs/37/37975.PNG

  • With the help of a string of separated by commas as lines

    HT a column in which I store the name separated by commas, I have to show them that the lines in a report...
    Help, please

    Check out this link...

    http://nimishgarg.blogspot.com/2009/12/Oracle-SQL-use-comma-seprated-string-to.html

  • the list of columns separated by commas of a dictionary table table

    I use the following question.

    CONNECT_BY_ROOT SELECT table_name TopLevel, level,
    connect_by_isleaf IS_Node_leaf,
    substr (SYS_CONNECT_BY_PATH (column_name, ','), 2) column_name
    Of all_tab_cols
    where connect_by_isleaf = 1
    and column_id < (select max (column_id) + 1 all_tab_cols
    where table_name = 'Table_test')
    and column_id > (select min (column_id) - all_tab_cols 1
    where table_name = 'Table_test')
    START WITH table_name = "Table_test."
    CONNECT BY PRIOR column_id = nocycle (column_id - 1).
    AND table_name = "Table_test."

    The only problem with this query is that it goes into infinite loop. Can someone suggest a better solution?

    Why you ask all_tab_cols, I think will realize you that it will pull all tables in your database.

    If you want to retrieve the name of the table and the columns (separated by commas) your schema, you must query user_tab_cols.

    and here is the sql code

    select table_name,ltrim(sys_Connect_by_path(column_name,','),',') column_names
    from
    (select table_name,column_name,row_number() over (partition by table_name order by column_id) rn
    from user_tab_cols)
    where connect_by_isleaf = 1
    start with rn=1
    connect by prior rn=rn-1 and prior table_name = table_name
    /
    

    Or, you can use all_tab_cols to query a specific table by passing the name of the table and the name of the owner

    PRAZY@11gR1> desc test
     Name
     -------------------------------------------
     NUM
     NUM2
    
    PRAZY@11gR1>
    select table_name,ltrim(sys_Connect_by_path(column_name,','),',') column_names
    from
    (select table_name,column_name,row_number() over (partition by table_name order by column_id) rn
    from all_tab_cols
    where owner='PRAZY' and
    table_name = 'TEST')
    where connect_by_isleaf = 1
    start with rn=1
    connect by prior rn=rn-1 and prior table_name = table_name
    /
    PRAZY@11gR1> /
    
    TABLE_NAME                     COLUMN_NAMES
    ------------------------------ ----------------------------------------
    TEST                           NUM,NUM2
    
    Elapsed: 00:00:00.01
    

    HTH,
    Prazy

    Published by: Prazy on April 28, 2010 10:23

  • Enter several values in the text box, separated by commas and spaces

    Hello

    I have the following syntax as my request to report to the opening of user_names in the area of text separated by commas, but the user sometimes come with a space between commas, could someone please let me know
    How this can be controlled, both when the user uses the space or not use space as well as the comma recording several user names in the text box?
    select 
    *
    from   DW_RFA_JOBDATA
    where  FINISH_TIME >= :P1_START_DATE 
    and FINISH_TIME < :P1_END_DATE
         AND  instr(',' || :P1_USER || ',', ',' || USER_NAME || ',') > 0
     OR (USER_NAME = USER_NAME AND :P1_USER is null)
    Thank you

    Select
    *
    of DW_RFA_JOBDATA
    where FINISH_TIME > =: P1_START_DATE
    and FINISH_TIME<>
    AND instr ("," |) REPLACE (translate (: P1_USER, '! @# $% ^ & * () _-+= {[]}] |------:; ~ ',' '),' ', "). ',', ',' || USER_NAME | ',') > 0
    OR (USER_NAME = USER_NAME AND: P1_USER is null)

  • list separated by commas - extraction of each element in an array?

    Is there a quick way to make a field that contains a list of items separated by commas and put them in a table or perhaps separate variables?

    for example.

    a single line in the database contains the field [matches_with] and would generally contain the following elements:

    rings, bracelets, necklaces

    I need to be put in a variable

    < cfset item1 = 'rings' >

    < cfset item2 = 'bracelets' >

    < cfset item3 = necklaces >

    or if its more simple, put them in a table

    agenda [1] = 'rings '.

    point [2] = "bracelets".

    point [3] = "necklaces."

    There is a built-in ListToArray function to CF.

  • Columns separated by commas

    Oracle 10.2.0.1
    Windows XP

    I have a table that stores the data of our customers. When I said:

    Select city, city_code as CS, count (*) as the early group of customers by city, city_code:
    It returns:
    CITY                                     CS        TOT
    ---------------------------------------- -- ----------
    Delhi                                    01         23
    Bangalore                                02         36
    Mumbai                                   03         33
    Hyderabad                                04          8
    Jaipur                                   00          2
    Patna                                    00          1
    Chennai                                  05        114
    Power required:
    CITY                                     CS        TOT                        IDS
    ---------------------------------------- -- ----------     ----------------------
    Jaipur                                   01          2                    393,405
    Patna                                    02          1                        200
    Means that if Tot for a city is between 1,5; I want to get these IDS to customer (from the customer table itself)
    separated by commas as above, so that I can know who are the customers, because all the
    cities whose number is < = 5, there are errors in the name of the city.

    Thank you.

    NOT TESTED! not having do not have database access

    select city,city_code,tot,substr(sys_connect_by_path(to_char(customer_id),','),2) ids
      from (select c.customer_id,c.city,c.city_code,e.tot,
                   row_number() over (partition by c.city,c.city_code order by customer_id) the_row
              from customers c,
                   (select city,city_code,count(*) tot
                      from customers
                     group by city,city_code
                     having count(*) <= 5
                   ) e
             where e.city = c.city
               and e.city_code = c.city_code
           )
     where connect_by_isleaf = 1
     start with the_row = 1
     connect by prior the_row + 1 = the_row
            and prior city = city
            and prior city_code = city_code
            and prior tot = tot
    

    Concerning

    Etbin

  • Is there a way to differentiate the string containing the characters and numbers?

    Hello, I created an application to read data from a serial port device. The problem is that the device, at startup, displays a block of text that contain characters describing the device. Shortly after, he displays a command prompt "command:" it's when I want my VI to enter the command to start to take action.

    I was looking at the VISA waiting on the event and looks that could be used to wait for the output device, only a "Serial character", but there is no distinction between the letters and numbers that I can tell.

    If the device is out of numbers in the reading string, of course, no need to enter the command to start to take action once again, which will probably only confuse the device. In this case, I want my VI to continue taking measures with VISA Read.

    The reason is that when I run the application, the device may have already been turned on. Send this command to the device using VISA Write is not necessary at this time.

    Any advice would be appreciated. Thank you.

    This makes it much easier.  In this case, this will do the trick.  You will notice that the bottom of the case does not match even if it has valid values inside.  The only thing that will match if the entire string is of the form XX. XXXX. Incidentally, since we are only matching numbers now, you can remove the "ignore case" Boolean as there is more important.

  • SimpleDateFormat giving different results for the same string in the form

    I use http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/i18n/SimpleDateFormat.html for formatting my date and time fields.

    I got a bug report that a device on English (UK) has a problem where the time turns off the screen, and I was able to reproduce this on device and Simulator.

    It's the pattern string that I use: hh:mma

    (hour 2 digits, colon, minute 2-digit and one letter for 'a' or 'p')

    English or r I get the result you want, for example 12: 12 p '

    "On English (UK), I get two letters for one / p marker, for example ' 12:12.

    (as if I had used 'hh:mmaa').

    What is the desired behavior? My client doesn't like it and wants a look and feel unique, with only one letter for 'a' or 'p', and I'm a little hesitatant to use aubstring...

    I usually do so, but our customer asked specifically localized to the date and time formatting.
    I have the model in my resource files, as the requested values are not easy to manage with the dateformat standard.

    Well, I have submitted comments on the entry of doc API, the doc is fake or the OS has a bug.
    I use substring if the string endsWith (am or pm) now...

  • Why the function of integrated separator string is missing in Oracle?

    Hi all

    It's maybe a generic/discussion question. And it's purely for learning about how Oracle prioritizes its development on the functions in construction.

    Well, we have very userful built-in functions (http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions001.htm) is transformed during the versions of Oracle from simple to very complex (syntactic xml and data mining functions)

    But why is this important function to split a string has been neglected (may not be the right word) by Oracle.

    Be a learner curious and admirer of such a wonderful technology database called Oracle, I always thought that it must have a dedicated channel, divide the function.

    My question is: is this something that can be generalized in a built-in function?

    or

    Is he coming releases?

    At least a simple function first (I guessed right his name would be splitstr and the very basic features to do our job of splitting, maybe I'm wrong in thinking this way, please correct me if...) Thank you in advance!)

    splitstr('A,B,c',',','col')-> (separator ',' and the fractionating column mode)

    Output: A B C (three separate columns)

    splitstr('A,B,c',',','row')-> (separator ',' and the mode line split)

    Output:

    A

    B

    C

    ----------

    If oracle has this, there will be a lot of code reduced and we can be saved by connect or recursive with clause or as a matter of fact even xmltable (with or without tokenizer ) for the separation of the channels.

    What you have to say about this? You can ignore this naïve question if is not a value you answer.

    And thanks for everyone who reads this discussion!

    See you soon,.

    Manik.

    Can you please help me understand why Oracle has its participation in develping and DBMS_UTILITY.COMMA_TO_TABLE now then?

    http://docs.Oracle.com/CD/B19306_01/AppDev.102/b14258/d_util.htm

    Oracle can only tell you why they have developed this particular function. But the fact that Oracle included in a package of "utility" tells me that they do not consider that there was a generic number of use cases. These functions often begin as internal functions that Oracle decides to publish.

    But if you read this API spec you'll see that he does that to a VERY PARTICULAR use case and has several restrictions.

    The list must be a list separated by commas of non-vide: another thing that a comma-separated list is rejected. Do not count the commas inside double quotes.

    Entries in the list separated by commas may not include multibyte and dashes (-) character.

    Also, returns a collection which would normally be used only for a very limited number of items.

    It is not yet near a general-purpose function.

    A major complication with such a function in SQL is sql is generally used with more than one, or even millions, of lines.

    How you specify to Oracle where to put the collection on each of these lines?

    New - Oracle is a relational database. With the help of sql to manipulate collections is NOT a relational paradigm.

    Just my opinion. Others can and will disagree. But you may have to wait for the weekend for these answers.

  • How to split string separated by commas and pass to the clause of the select statement

    Referring to article How to divide string separated by commas, then pass to clause of a select statement, tquery that there the following plan:

    Query1:

    select * from emp where ename in (
        select regexp_substr('SMITH,ALLEN,WARD,JONES','[^,]+', 1, level) from dual
        connect by regexp_substr('SMITH,ALLEN,WARD,JONES', '[^,]+', 1, level) is not null );
    

    Base1:

    Plan hash value: 4242290184
    
    
    --------------------------------------------------------------------------------------------
    | Id  | Operation                       | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                |          |     1 |   133 |     7  (29)| 00:00:01 |
    |*  1 |  HASH JOIN                      |          |     1 |   133 |     7  (29)| 00:00:01 |
    |   2 |   VIEW                          | VW_NSO_1 |     1 |    46 |     3  (34)| 00:00:01 |
    |   3 |    HASH UNIQUE                  |          |     1 |       |     3  (34)| 00:00:01 |
    |*  4 |     CONNECT BY WITHOUT FILTERING|          |       |       |            |          |
    |   5 |      FAST DUAL                  |          |     1 |       |     2   (0)| 00:00:01 |
    |   6 |   TABLE ACCESS FULL             | EMP      |    14 |  1218 |     3   (0)| 00:00:01 |
    --------------------------------------------------------------------------------------------
    
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
    
       1 - access("ENAME"="$nso_col_1")
       4 - filter( REGEXP_SUBSTR ('SMITH,ALLEN,WARD,JONES','[^,]+',1,LEVEL) IS NOT NULL)
    

    However, the following query generates the plan I want:

    Query2:

    select * from emp where ename in ('SMITH','ALLEN','WARD','JONES');
    

    Plan2:

    Plan hash value: 3956160932
    
    
    --------------------------------------------------------------------------
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------
    |   0 | SELECT STATEMENT  |      |     4 |   348 |     3   (0)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL| EMP  |     4 |   348 |     3   (0)| 00:00:01 |
    --------------------------------------------------------------------------
    
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
    
       1 - filter("ENAME"='ALLEN' OR "ENAME"='JONES' OR "ENAME"='SMITH' OR
                  "ENAME"='WARD')
    

    Can I change the query1 query for plan2?

    As Juliet was mentioned in the first SQL that you generate from the ENAME list that you must pass in the IN clause when executing. But in the second SQL, it passed as a static value. So first SQL must do more work. So you see a different execution plan.

    But this is a work around to get what you are looking for. But I can't say it's a foolproof method. But anyway here you go.

    SQL > var ename_list varchar2 (100)
    SQL > exec: ename_list: = 'SMITH, ALLEN, WARD, JONES ';

    PL/SQL procedure successfully completed.

    SQL > select *.
    2 of PEM
    where the 3 «,» | : ename_list | ',' like '%', | Ename | ',%';

    EMPNO, ENAME, JOB HIREDATE DEPTNO ID COM SAL MGR
    ---------- ------ --------- ---------- --------- ---------- ---------- ---------- ----------
    7369 SMITH COMMITTED 7902 2975 2 APRIL 81 0 20
    7499 ALLEN 7698 1600 20 FEBRUARY SALESMAN 81 300 30
    7521 WARD 7698 1250 22 FEBRUARY SALESMAN 81 500 30
    7566 JONES MANAGER 7839 2975 2 APRIL 81 0 20

    SQL > select * from table (dbms_xplan.display_cursor);

    PLAN_TABLE_OUTPUT
    -------------------------------------------------------------------------------------------------------
    SQL_ID, 848zhvbvgf7d6, number of children 0
    -------------------------------------
    Select * from emp where «,» | : ename_list | ',' like '%', | Ename
    || ',%'

    Hash value of plan: 2872589290

    --------------------------------------------------------------------------
    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
    --------------------------------------------------------------------------
    |   0 | SELECT STATEMENT |      |       |       |     2 (100) |          |
    |*  1 |  TABLE ACCESS FULL | EMP |     1.    38.     2 (0) | 00:00:01 |
    --------------------------------------------------------------------------

    Information of predicates (identified by the operation identity card):
    ---------------------------------------------------

    1 - filter(','||:ENAME_LIST||',' LIKE '%,'||") ENAME "|", %')

    19 selected lines.

    SQL >

  • Build the string separated by commas in query with Expression box sub

    Oracle 10g on Windows XP

    Consider the following query:

    Select batch_id, tr state_tag_seq where request_type in (select case WHEN PX = 'RETURN' AND 'TRANSFER' |) «, » || "PUBLIC TRANSIT"
    WHEN PX = "RFT" THEN "TRANSIT".
    ELSE 'Invalid '.
    END
    OF THE DOUBLE
    ) ;


    In this case, PX is accepted to execution of the user interface.

    I'm having no rows returned (all valid lines matching in DB) for the following case assessment

    WHEN PX = 'RETURN' THEN 'TRANSFER '. «, » ||' Transit "(PX when is evaluated to 'RETURN')

    The application works well when it px IS estimated to be "PCR" (as the evaluated expression is just a string ('TRANSIT') single, not separated by commas, as in the other case)

    Hiow do rewrite this query, if it gives a correct result? In other words, I actually build the query string slot, which is assessed by the external when query clause.

    I think it might be a specific way to use quotes in my case expression, but I'm reaching an impasse. Any help is appreciated.

    Thank you
    SR

    You can try

    select batch_id, state_tag_seq
      from tr
     where request_type member of case
                             when px = 'RETURN'
                             then
                              sys.dbms_debug_vc2coll (
                               'TRANSFER',
                               'TRANSIT'
                              )
                             when px = 'RFT'
                             then
                              sys.dbms_debug_vc2coll ('TRANSIT')
                             else
                              sys.dbms_debug_vc2coll ('Invalid')
                             end
    
  • On the OWN website of mozilla, I get the message "Your Firefox is out of date and may contain a security risk!' but I just download and install the latest version?

    I have the latest version of firefox to date (15/10/2014 v32) and I still get messages while on various sites Internet (Youtube, Google, Gmail), telling me that your Firefox is out of date and may contain a security risk.

    I have not even this message on the support pages of mozilla.org?

    I tried the subject: config reset the useragent (s) fix, but it does not work.
    I tried browsing in safe mode and still get the error.

    Why this false/positive happening?

    Thank you

    Hello your useragent (information, the browser sends to websites to identify its version) - apparently by mistake - shows this:

    Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20140923 Firefox/4.0.0; xs-A30GTmfXR3o;CkHZPf;
    

    probably some kind of unwanted software has crashed it. Please refer to this article in order to reset the user agent settings in firefox:
    Sites Internet says that Firefox is obsolete or incompatible, even if it's the latest version

    in case this is not enough, please try to reset the whole browser:
    Firefox - modules to reset and refresh settings

  • Bug: Find/replace does not work if the statement contains the string is too long

    Hello

    in my sequence, I press Ctrl + F to open the Find dialog box and enter a string. All the checkboxes are checked 'Elements for search' and ' limit the search to "is not enabled.

    Now comes the finding it is only announcing the discovery in the main sequence.

    Other places in a sous-suite that are part of a labview vi action setting is not in the list. Also if I open the sequence and I'm looking at this place.

    If I create a comment in the subsequence containing the searchstring, then it is.

    When I open the properties of the action of labview and open the parameter that contains the string and click on check for errors, and then close all and supplementary search then the value lies.

    Is it possible that the variable is too long setting? It's about 200 characters and one thing very nested SationGlobals and the table and the TestSockets. Search string Dees is finally an arrayindex in this grand statement.

    It seems that this is the problem.

    Is this a known bug?

    Solved.

    There was an empty character at the end of the search string...

Maybe you are looking for

  • Satellite Pro L300 will not connect to Wifi after hibernation

    Hello can someone there help me please?I have a Satellite Pro L300 and it does not connect to Wifi after hibernation. The only way to do it is to restart the pc. Any suggestions?

  • Satellite 4090xcdt / question about CPU upgading & batteries

    Hello I just joined the forum. Looks really good. I inherited a satellite 4090xcdt (PAS409EYX-ENX). He had 4 gig ' ish HDD, Celeron CPU (300 or 400 MHZ?), 64 MB of RAM and win 98. me and my boyfriend has replaced the HARD drive with 80 GB model (the

  • Build-Fehler. Fehler 1 (im accordingly mit einkommendem path?)

    Hallo! ALS ich ein .exe von meinem VI machen wanted ich auf ein bad sharp Fehlermeldung kriegte: --------------------------------------------Fehler 1 ist bei Methodenknoten in AB_EXE.lvclass:Build.vi-> AB_Engine_Build.vi-> AB_Build_Invoke.vi-> AB_Bui

  • F1 key

    I need the key f1 for the games, but when I press it it opens the Help window. I can not turn all my keys action off because that I need for the volume, keyboard light etc. is there a way to just disable the f1 key, but leave other assets?

  • New installation of Secure ACS 4.1 on 2003, very slow

    Hi all We just did a new installation of Server 2003, ACS 4.1 Standard and it appears whenever we try to apply a change (add user, add a network device, etc.) it takes forever. Sometimes, it just hangs and if we close the browser and set up another s