String to column

Hi experts,
The data is as follows
sno
1,2,3,4,5,6,7,8,9,10
I want to display it as
SNO
1
2
3
4
5
6
7
8
9
10
Please provide me the SQL query.
Thanks in advance.

Hi,
Here's one way:
SELECT  REGEXP_SUBSTR ( sno
                , ''[^,]+'
                , 1
                , LEVEL
                )          AS sub_sno
FROM    table_x
WHERE     str     = ...     -- If table has more than 1 row
CONNECT BY  LEVEL <= 1 + LENGTH (sno)
                     - LENGTH (REPLACE (sno, ','))
;If sno is not in a table, then you can use dual in the FROM clause.
Starting in Oracle 11.1, you can use REGEXP_COUNT instead of LENGTH to see how many commas are in sno.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using.
See the forum FAQ {message:id=9360002}

Similar Messages

  • Find out varchar2 string NULL columns and Empty columns

    Hi dev's ,
    my requiremnt is to find out the string columns Names of whose storing NULL values and EMPTY strings. for that i had written below code. it's getting some error.
    SET ECHO OFF;
    SET FEEDBACK OFF;
    SET SERVEROUTPUT ON;
    SET VERIFY OFF;
    SET PAGES 0;
    SET HEAD OFF;
    spool D:\stringnull.csv
    DECLARE
      v_tab_indent NUMBER(5);
      v_col_indent NUMBER(5);
      v_val1       VARCHAR2(20);
      v_val2       VARCHAR2(20);
      v_query1     VARCHAR(500);
      v_query2     VARCHAR(500);
    BEGIN
      --DBMS_OUTPUT.ENABLE(100000);
      SELECT MAX(LENGTH(table_name))+1,MAX(LENGTH(column_name))    +1
      INTO v_tab_indent,v_col_indent
      FROM user_tab_columns
      WHERE data_type='VARCHAR2';
    FOR i IN
      (SELECT table_name,
        column_name
      FROM user_tab_columns
      WHERE data_type IN ('NVARCHAR2', 'CHAR', 'NCHAR', 'VARCHAR2')
      ORDER BY table_name,
        column_name
      LOOP
        v_query1:='SELECT NVL('||i.column_name||',0) AS VAL    
                  FROM '||i.table_name||' where '||i.column_name||' IS NULL';
        v_query2:='SELECT '||i.column_name||' AS VAL    
                  FROM '||i.table_name||' where '||i.column_name||'=''''';
        --dbms_output.put_line(v_query1);
       -- dbms_output.put_line(v_query2);
        EXECUTE immediate v_query1 INTO v_val1;
        EXECUTE immediate v_query2 INTO v_val2;
        dbms_output.put_line (rpad(i.table_name,v_tab_indent,' ')||','||rpad(i.column_name,v_col_indent,' ')||' ,'||v_val1||','||v_val2);
      END LOOP;
    END;
    Spool OFF
    Set echo on
    Set feedback onERROR:
    Error report:
    ORA-01403: no data found
    ORA-06512: at line 31
    01403. 00000 -  "no data found"
    *Cause:   
    *Action:
    set feedback onpls help me on this issue..
    Thanks,

    Example:
    SQL> DECLARE
      2    v_val       VARCHAR2(20);
      3    v_query1     VARCHAR(32767);
      4  BEGIN
      5   FOR i IN (SELECT table_name, column_name FROM user_tab_columns
      6             WHERE data_type IN ('NVARCHAR2', 'CHAR', 'NCHAR', 'VARCHAR2')
      7             ORDER BY table_name, column_name
      8            )
      9   LOOP
    10     v_query1 := 'SELECT count(*) FROM '||i.table_name||' where '||i.column_name||' IS NULL';
    11     EXECUTE immediate v_query1 INTO v_val;
    12     dbms_output.put_line(rpad(i.table_name,30,' ')||' : '||rpad(i.column_name,30,' ')||' : '||v_val);
    13   END LOOP;
    14  END;
    15  /
    CHILD_TAB                      : DESCRIPTION                    : 0
    DEPT                           : DNAME                          : 0
    DEPT                           : LOC                            : 0
    EMP                            : ENAME                          : 0
    EMP                            : JOB                            : 0
    MYEMP_OLD                      : ENAME                          : 0
    MYEMP_OLD                      : JOB                            : 0
    MYNULLS                        : ENAME                          : 0
    MYNULLS                        : JOB                            : 4
    PARENT_TAB                     : DESCRIPTION                    : 0
    T                              : CHAR_VALUE                     : 0
    TABLE1                         : COL1_DESC                      : 0
    PL/SQL procedure successfully completed.

  • Join String to Column in Query

    Hi
    I have a column in a query I would like to join a string so that the value from the column always has a descriptor at the end like this:
    1.5 "Yards"
    2.5 "Yards"
    I don't mean:
    column AS "Yards"
    The value in the column changes length so I want to try and have this descriptor so that when I put it in a report the changing value length does not overwrite a seperate text field in the report.
    the column is a float value and I want to join the string to it.
    Thanks for any input on how to do this

    Hi
    Sorry I think we have wires crossed
    so say I have this:
    select columnA
    from table A
    and It returns this:
    columnA
    ======
    123
    456
    789
    .What I want is for it to show this:
    columnA
    ======
    123 Yards
    456 Yards
    789 Yards
    . Yards
    . Yards
    . Yards
    . Yards
    . YardsSo for ever value returned I want to have the string value "Yards" on the end; column A is a float.
    Thanks

  • Add one column of string to columns of integer

    Hi there,
    Could someone help please. 
    I would like to add one column of strings to a few columns of integer. 
                                                           --------- Added elements ------ 
    20C=           100     101    102           20C=100     20C=101    20C=102
    15C=           200     201    202          15C=200     15C=201    15C=202
    10C=           300     301    302          10C=300     10C=301    10C=302
    Thanks for help. 

    Hoverman wrote:
    I had a look at the tutorial link you sent. They are not particularly relevant to my question. 
    Why do you think I am posting a question? I have already spent a few hours searching forum and looking at examples. It would be more helpful to have a relevant example or a solution.
    Thanks for your time.  
    What is your problem here? RavensFan gave you information quite relevant to your task, but you had not (and still have not) answered his questions, so he could not (nor anyone else) tell where in your task you are having trouble. Do you know how for loops work, with respect to outputs? Your questions imply that you need to spend some real time learning LabVIEW, not just "having a look at the tutorials."
    Hmm, it looks like you had a similar problem with your last question, and you still have not indicated that you understood how to solve it.
    Cameron
    To err is human, but to really foul it up requires a computer.
    The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
    Profanity is the one language all programmers know best.
    An expert is someone who has made all the possible mistakes.
    To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):
    LabVIEW Unit 1 - Getting Started
    Learn to Use LabVIEW with MyDAQ

  • Archiving a ztable with string/lob column

    Hello,
    We have a ZTable that is quite big.
    Our functionals would like to preserve this information,
    even if they rarely access it.
    The table is independent of other tables.
    This table contains a zone with the abap data type string.
    This is stored as a lobs column in the Oracle database.
    1. Is it possible to "sara" archive that kind of tables?
    2. Where could I found examples of ADK abap delete/write/read/reload programs
    for ztables?
    Thanks in advance for your answers.

    Give help.sap.com a chance:
    http://help.sap.com/saphelp_sm40/helpdata/EN/2a/fa042d493111d182b70000e829fbfe/frameset.htm
    it is pretty well explained there and even mentiones example programs:  SBOOKA and SFLIGHTA

  • How to split a string into columns

    Hello to all ,
    Having a strings like this, where pipe(|) is his delimiter
    10:00 | x1 | 2 | RO | P | Con ausilio  | y1
    10:10 | x2 | 1 | RO |  |  | y2
    10:20 |x3 | 3 |  |  |  | y3
    10:30 |x4 | 3 | RO | N | Con aiuto  | y4
    10:40 |x5 | 1 | RO |  |  | y5
    how can I break it up into columns, for example, the first char(before first pipe) insert in first variable,
    then, after first pipe,  second characters in a other column ans so on
    col1 := '10:00';
    col2 := 'x1';
    col3 := '2';
    col4:= 'RO';
    col5 := 'P';
    col6 := ' Con ausilio ';
    col7 := 'y1';
    col1 := '10:10';
    col2 := 'x2';
    .. and so on
    thanks in advance

    Hi,
    check this:
    WITH mydata(txt) AS
       SELECT '10:00 | x1 | 2 | RO | P | Con ausilio  | y1' FROM DUAL UNION ALL
       SELECT '10:10 | x2 | 1 | RO |  |  | y2'              FROM DUAL UNION ALL
       SELECT '10:20 |x3 | 3 |  |  |  | y3'                 FROM DUAL UNION ALL
       SELECT '10:30 |x4 | 3 | RO | N | Con aiuto  | y4'    FROM DUAL UNION ALL
       SELECT '10:40 |x5 | 1 | RO |  |  | y5'               FROM DUAL
    SELECT TRIM(REGEXP_SUBSTR(txt,'[^|]+',1,1)) col1
         , TRIM(REGEXP_SUBSTR(txt,'[^|]+',1,2)) col2
         , TRIM(REGEXP_SUBSTR(txt,'[^|]+',1,3)) col3
         , TRIM(REGEXP_SUBSTR(txt,'[^|]+',1,4)) col4
         , TRIM(REGEXP_SUBSTR(txt,'[^|]+',1,5)) col5
         , TRIM(REGEXP_SUBSTR(txt,'[^|]+',1,6)) col6
         , TRIM(REGEXP_SUBSTR(txt,'[^|]+',1,7)) col7
      FROM mydata;
    COL1   COL2   COL3   COL4   COL5   COL6            COL7 
    10:00  x1     2      RO     P      Con ausilio     y1   
    10:10  x2     1      RO                            y2   
    10:20  x3     3                                    y3   
    10:30  x4     3      RO     N      Con aiuto       y4   
    10:40  x5     1      RO                            y5    Regards.
    Al

  • String to column conversion

    i have searched the forum before posting
    i want to convert single string value to multiple column
    445 1945551 1595560 1594591
    444 1945553 1595560 1594593 1594544
    to col1 --- col5
    please give me adv
    i am using the following version
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE     10.2.0.4.0     Production
    TNS for Linux: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production

    You can use Regular Expression :
    SQL> with t_data as
    select '445 1945551 1595560 1594591' as txt from dual union all
    select '444 1945553 1595560 1594593 1594544' from dual
    select
      txt,
      regexp_substr(txt,'[^ ]+',1,1) col1,
      regexp_substr(txt,'[^ ]+',1,2) col2,
      regexp_substr(txt,'[^ ]+',1,3) col3,
      regexp_substr(txt,'[^ ]+',1,4) col4,
      regexp_substr(txt,'[^ ]+',1,5) col5
    From t_data;
    TXT                                                COL1            COL2            COL3            COL4            COL5
    445 1945551 1595560 1594591                        445             1945551         1595560         1594591
    444 1945553 1595560 1594593 1594544                444             1945553         1595560         1594593         1594544
    SQL>

  • How to compare array of String with column of a table

    Hi,
    i have a array of string(say array is of length 1000). I want to
    compare those string in array with one table column
            - whether that table column has a string
                            if yes
                                            do nothing.
                            if no
                                            then insert that string into table.
            - whether table has obsolete row i.e, the one present in table and
    not in array
                            then delete that row.
    How do i go about this, because i see, it is not feasible to loop
    through array and search table to find new string OR loop through each
    row from table to find some obsolete row
    How can i accomplish this task more feasibly(without running query for
    each string, for comparission)? Is there any way to find this kind of
    problem. I would have been easy if i had to compare two tables(with
    UNION and INTERSECT), but it is not the case.
    thanks,
    kath.

    I'm not sure, whether I understand your problem correctly. Only two comments:
    - if both arrays are sorted, all can be done running exactly once simultaneously through both arrays.
    - if the column is marked as UNIQUE, all column strings will be different. I.e. you cannot insert the same string a second time.
    Regards  Thomas

  • I can't pass empty string as column of Table Valued Parameter.

    Hello.
    I have stored procedure which accept TVP with columns of 'sql_variant' type. And I have C++ application which call this stored procedure.
    When i pass some non-empty string as sql_variant from my application - all works fine.
    But when I need to pass empty string ("") as sql_variant - I get following error:
    "OLEDB hr = 0x80040e14
     #0:  OLEDB provider error 3621  "The statement has been terminated."
     #1:  OLEDB provider error 8062  "The data for the table-valued parameter 1 doesn't conform to the table type of the parameter."
     #2:  OLEDB provider error 8046  "The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Table-valued parameter 0 (""), row 1, column 1: The supplied length is not valid for data type sql_variant.
    Check the source data for invalid lengths. An example of an invalid length is data of nchar type with an odd length in bytes."  
    Could you please help me deal with that issue?
    Thanks,
    Vitaliy

    Dear Vitaliy,
    Thank you for your question.
    Based on my understanding of your question, the issue is related with passing SQL_VARIANT data type in C++ application using Microsoft OLE DB Provider.
    As we can see from http://msdn.microsoft.com/en-us/library/ms173829(v=sql.100).aspx:
    ODBC does not fully support sql_variant. Therefore, queries of sql_variant columns are returned as binary data when you use Microsoft OLE DB Provider for ODBC (MSDASQL). For example, a sql_variant column that contains the character string data 'PS2091'
    is returned as 0x505332303931.
    According to above statement, as you are using OLEDB provider for ODBC with sql_variant in your application, it is not fully support. Seems there are some conversion failure within the Stored Procedure calling. You may consider to adjust your application
    slightly to use other commonly supported data types which also fits your application requirements.
    I listed some more information regarding sql_variant below for your reference:
    A column of type sql_variant may contain rows of different data types such as int, binary and char values.
    A sql_variant data type must first be cast to its base data type value
    before participating in operations such as addition and subtraction. You can find the conversion details in "Comparings sql_variant Values" part.
    Below types of values cannot be stored by using sql_variant:
    varchar(max)
    varbinary(max)
    nvarchar(max)
    xml
    text
    ntext
    image
    timestamp
    sql_variant
    geography
    hierarchyid
    geometry
    User-defined types
    Hope it will be helpful.
    Thank you!
    Best Regards,
    SQL Team - MSFT

  • How to split strings into columns

    Hi guys,
    I have a select like this:
    select 'testing1'||'.'||'testing2'||'.'||'testing3' from dualwhich gives me an output like this:
    testing1.testing2.testing3How can I split this into 3 columns in SQL PLUS?
    Thank you in advance

    user643734 wrote:
    Thank you guys for all your help.
    Hi,
    I tried to resolve your problem using somme functions...
    I know is a long, long story but it works.
    Regards,
    Ion--create table_pivot
    CREATE TABLE pivot_table(id VARCHAR2(1) primary key, all_concat VARCHAR2(1810));
    --add data
    insert into pivot_table (id, all_concat) values('x','12345.2829303132.234234.234234.234234');
    insert into pivot_table (id, all_concat) values('y','67890.2324252627.234234.234234.234234.332545');
    insert into pivot_table (id, all_concat) values('z','11121314.12345.234234.234234.234234.23432.32453245.345435.345435');
    insert into pivot_table (id, all_concat) values('a','151617.67890.234234.234234');
    insert into pivot_table (id, all_concat) values('b','1819202122.1112131415.234234.234234.234234.345435');
    insert into pivot_table (id, all_concat) values('c','2324252627');
    insert into pivot_table (id, all_concat) values('h','2829303132.234234.234234.234234.23432.32453245.345435.345435.4325435.345');
    insert into pivot_table (id, all_concat) values('r','');
    set termout off
    --procedures and functions to compile
    --1. Main function to format strings
    create or replace function fgetformatstring
    (v_max_rows numeric, v_crt_row varchar2, v_table_source varchar2, v_save_to_table varchar2, v_option numeric)
    return varchar2
    is
    v_crt_char      numeric:=0;
    v_pos_char      numeric:=1;
    v_count      numeric:=0;
    v_string_out varchar2(500);
    v_str_paded     varchar2(10):=',null';
    v_length_pad     numeric;
    v_diff_pad numeric;
    l_crt_row varchar2(1800);
    v_char char:=',';
    v_delimiter char:='.';
    l_save_to_table varchar2(1000);
    l_max_rows     numeric;
    begin
    l_crt_row:=replace(v_crt_row,'.' ,',');
    l_save_to_table:=v_save_to_table;
    l_max_rows:=v_max_rows;
    if v_option=0 then     --get the ',null' to paded in pivot_table     
    loop
              v_pos_char:=v_crt_char;
              v_crt_char:=instr(v_crt_row,v_char, v_crt_char+1);
              v_count:=v_count+1;
    exit when v_crt_char=0 or v_count=1000;
         end loop;
         v_string_out:=' ';
         v_count:=v_count-1;
         v_diff_pad :=l_max_rows-1-v_count;
    if v_diff_pad >0 then                    --nothing to add
         v_length_pad:=length(v_str_paded);-- (+v_char)
         v_length_pad:=v_diff_pad*v_length_pad;
         v_length_pad:=v_length_pad+1;
         v_string_out:=rpad(v_string_out,v_length_pad,v_str_paded);
    end if;
    end if;
    if v_option=1 then     --get definition of v_save_to_table
         v_count:=1;
         v_string_out:=' ';
         loop
    exit when v_count=l_max_rows+1 or v_count>=1000;
    v_length_pad:=length(v_string_out||'col'||to_char(v_count)||',');
              v_string_out:=rpad(v_string_out,v_length_pad,'col'||to_char(v_count)||',');
              v_count:=v_count+1;
         end loop;
    v_string_out:=trim(v_char from v_string_out);
              --v_string_out:='id,'||v_string_out;
              v_string_out:=v_string_out;
    end if;
    if v_option=2 then     --get position of last comma  
    loop
              v_pos_char:=v_crt_char;
              v_crt_char:=instr(v_crt_row,v_char, v_crt_char+1);
              v_count:=v_count+1;
    exit when v_crt_char=0 or v_count=1000;
         end loop;
         v_string_out:=substr(v_crt_row,1,v_pos_char-1);
    end if;
    if v_option=3 then     --get numbers of delimiters(.)
    loop
              v_pos_char:=v_crt_char;
              v_crt_char:=instr(v_crt_row,v_delimiter, v_crt_char+1);
    --dbms_output.put_line( 'Rows: ' ||v_crt_row|| ' iteration: '||v_count);
              v_count:=v_count+1;
    exit when v_crt_char=0 or v_count=1000;
         end loop;
         v_count:=v_count;
         v_string_out:=to_char(v_count);
    end if;
    if v_option=4 then     --get sql command to create v_save_to_table
         v_count:=1;
         v_string_out:=' ';
         loop
    exit when v_count=l_max_rows+1 or v_count>=1000;
    v_length_pad:=length(v_string_out||'col'||to_char(v_count)||' varchar2(40), ');
              v_string_out:=rpad(v_string_out,v_length_pad,'col'||to_char(v_count)||' varchar2(40), ');
              v_count:=v_count+1;
         end loop;
    v_string_out:=trim(' ' from v_string_out);
              v_string_out:=trim(v_char from v_string_out);
              v_string_out:='create table '|| l_save_to_table ||'('||v_string_out||')';
    end if;
    if v_option=5 then     --get numbers of delimiters(,) 
    loop
              v_pos_char:=v_crt_char;
              v_crt_char:=instr(v_crt_row,',', v_crt_char+1);
              v_count:=v_count+1;
    exit when v_crt_char=0 or v_count=1000;
         end loop;
         v_count:=v_count-1;
         v_string_out:=to_char(v_count);
    end if;
    dbms_output.put_line( 'string: ' ||v_string_out|| ' option: '||v_option);
    return v_string_out;
    end;
    --2.get max items
    create or replace function fgetmaxitems
    --get the max number of items founded in the pivot_table.all_concat
    --before change the points with comma
    return numeric
    is
    v_max                numeric:=0;
    v_field               pivot_table.all_concat%type;
    v_crt_max numeric:=0;
    v_crt_row     varchar(1000);
    cursor c1 is
    select all_concat from pivot_table;
    begin
    v_crt_max:=0;
    v_max:=0;
    open c1;
    loop
    fetch c1 into v_field;
    exit when c1%notfound;
    v_crt_row:=v_field;
    v_crt_max:=fgetformatstring(0,v_crt_row,'pivot_table','',3);
    if v_crt_max>v_max then
         v_max:=v_crt_max;
    end if;
    end loop;
    close c1;
    return v_max;
    end;
    --3. insert the rows in table_dest
    create or replace procedure pinsertrow
    v_max_rows numeric,
    v_all_concat varchar2,
    v_source_table_name varchar2,
    v_save_to_tablename varchar2
    is
    v_sql_string      varchar2(1000);
    l_all_concat     varchar2(1500);
    begin
    l_all_concat:=replace(v_all_concat,'.' ,',');
    v_sql_string:='('||l_all_concat||')';
    v_sql_string:=' insert into ' ||v_save_to_tablename
    ||' (' ||fgetformatstring(v_max_rows,l_all_concat,v_source_table_name,v_save_to_tablename,1)||')'||
    ' values'||v_sql_string ;
    execute immediate v_sql_string;
    end;
    --4.procedure to create dinamically <table_dest>
    create or replace procedure pcreatesavetable
    (v_table_source varchar2, v_save_to_table varchar2)
    is
    v_sql_string      varchar2(1000);
    already_exists exception;
    pragma exception_init(already_exists,-955);
    v_max numeric;
    begin
    --clear empty values;
    v_sql_string:='delete from ' ||v_table_source|| ' where length(all_concat)=0 or (all_concat) is null';
    execute immediate v_sql_string;
    v_sql_string:='';
    v_max:=fgetmaxitems;
         --create new table
         v_sql_string:=fgetformatstring(v_max,'all_concat', v_table_source,v_save_to_table,4);
    dbms_output.put_line( 'sql create : '|| v_sql_string);
    execute immediate v_sql_string;
    exception
         when already_exists then
    --delete old table
         v_sql_string:='drop table ' ||v_save_to_table;
         execute immediate v_sql_string;
         --create new table
         v_sql_string:=fgetformatstring(v_max,'all_concat', v_table_source,v_save_to_table,4);
    dbms_output.put_line( 'sql recreate final_table : '|| v_sql_string);
    execute immediate v_sql_string;
    end;
    --5.main procedure
    create or replace procedure pmainproc(v_save_to_table varchar2)
    is
    v_key_pivot      pivot_table.id%type;
    v_column_pivot     pivot_table.all_concat%type;
    v_max numeric;
    v_crt_row          varchar2(1600);
    cursor c2 is select y.id , y.all_concat
         from pivot_table y
    ;     --cursor upon pivot_table 
    begin
    v_max:=fgetmaxitems;
    if v_max <> 0 then
    --clear empty values;
    delete from pivot_table where length(all_concat)=0 or (all_concat) is null;
    --change all points with comma
    update
    (select x.id, x.all_concat from pivot_table x, pivot_table y where x.id=y.id) b
    set b.all_concat=replace(b.all_concat,'.', ',');
    -- padd the all_concat with ',null'
    update
    (select x.id, x.all_concat from pivot_table x, pivot_table y where x.id=y.id and
    fgetformatstring(v_max,x.all_concat,'pivot_table',v_save_to_table,5) <> v_max
    ) b
    set b.all_concat=b.all_concat || fgetformatstring(v_max,b.all_concat,'pivot_table',v_save_to_table,0);
    --remove last
    update pivot_table
    set all_concat= fgetformatstring(v_max,all_concat,'pivot_table',v_save_to_table,2)
    where fgetformatstring(v_max,all_concat,'pivot_table',v_save_to_table,5) = v_max;
    open c2;
    loop
    fetch c2 into      v_key_pivot, v_column_pivot;
    exit when c2%notfound;
    v_crt_row:=v_column_pivot;
    -- insert data in to final_table
    pinsertrow(v_max,v_crt_row,'pivot_table',v_save_to_table);
    end loop;
    close c2;
    end if;
    end;
    --create table_dest
    --the table_dest will be created automatically, so you need admin privilege to run that before compile pcreatesavetable :
    connect / as sysdba or connect system/password
    --grant create table to hr;
    --conne hr/hr;
    exec pcreatesavetable('pivot_table','table_dest');
    --add data to table_dest
    exec pmainproc('table_dest');
    set termout on
    select * from table_dest;
    Table created.
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    Function created.
    Function created.
    Procedure created.
    Procedure created.
    Procedure created.
    PL/SQL procedure successfully completed.
    PL/SQL procedure successfully completed.
    COL1 COL2 COL3 COL4 COL5 COL6 COL7 COL8 COL9 COL10
    12345 2829303132 234234 234234 234234
    67890 2324252627 234234 234234 234234 332545
    11121314 12345 234234 234234 234234 23432 32453245 345435 345435
    151617 67890 234234 234234
    1819202122 1112131415 234234 234234 234234 345435
    2324252627
    2829303132 234234 234234 234234 23432 32453245 345435 345435 4325435 345
    7 rows selected.

  • Break string in column

    Hello to all ,
    Having a strings like this, where pipe(|) is his delimiter
    10:00 | x1 | 2 | RO | P | Con ausilio  | y1
    10:10 | x2 | 1 | RO |  |  | y2
    10:20 |x3 | 3 |  |  |  | y3
    10:30 |x4 | 3 | RO | N | Con aiuto  | y4
    10:40 |x5 | 1 | RO |  |  | y5
    how can I break it up into columns, for example, the first char(before first pipe) insert in first variable,
    then, after first pipe,  second characters in a other column ans so on
    col1 := '10:00';
    col2 := 'x1';
    col3 := '2';
    col4:= 'RO';
    col5 := 'P';
    col6 := ' Con ausilio ';
    col7 := 'y1';
    col1 := '10:10';
    col2 := 'x2';
    .. and so onthanks in advance

    Is this somehow related to oracle forms? For what we know you don't even use an oracle product like forms or the database, so an answer would be near to impossible.
    First of all please indicate the oracle products plus their 5-digit version numbers you are using. After that please share with us what you plan to do with this string tokenizer, where you get the string from (maybe a CSV file?) and what you plan to do with it (maybe insert into a table?)
    cheers

  • Help required- Searching Particular string in column

    Hi,
    I have a table by name temp and 2 values in the table. I'm using LIKE caluse to search a string. I'm getting output for some particular string. Please correct the below query for me.
    I have given a table/data reference for you:
    Create table temp(col1 varchar2(255));
    insert into temp values ('Test_Scale_High');
    1 row inserted
    insert into temp values ('Test_Scale_High');
    1 row inserted
    commit;
    select * from temp;
    col1
    Test_Scale_High
    Test_Scale High
    select * from temp where upper(col1) like '%TEST_SCALE%';
    COL1
    Test_Scale_High
    Test_Scale High
    select * from temp WHERE UPPER(COL1) LIKE '%TEST_SCALE_%';
    COL1
    Test_Scale_High
    Test_Scale High
    select * from temp WHERE UPPER(COL1) LIKE '%TEST_SCALE_H%';
    No Row Selected
    Thanks,
    Santhosh.S

    santhosh.shivaram wrote:
    select * from temp;
    col1
    Test_Scale_High
    Test_Scale High
    select * from temp where upper(col1) like '%TEST_SCALE%';
    COL1
    Test_Scale_High
    Test_Scale High
    select * from temp WHERE UPPER(COL1) LIKE '%TEST_SCALE_%';
    COL1
    Test_Scale_High
    Test_Scale High
    If I understand your requirement correctly you need to escape the Wild Card '_'
    Hope the following code helps:
    SQL> set feedback on;
    SQL> SELECT * FROM TEMP
      2  /
    COL1
    Test_Scale_High
    Test_Scale High
    2 rows selected.
    SQL> SELECT *
      2    FROM temp
      3   WHERE UPPER (col1) LIKE '%TEST_SCALE%'
      4  /
    COL1
    Test_Scale_High
    Test_Scale High
    2 rows selected.
    SQL> SELECT *
      2    FROM temp
      3   WHERE UPPER (col1) LIKE '%TEST_SCALE\_%' ESCAPE '\'
      4  /
    COL1
    Test_Scale_High
    1 row selected.
    SQL> SELECT *
      2    FROM temp
      3   WHERE UPPER (col1) LIKE '%TEST_SCALE_H%'
      4  /
    COL1
    Test_Scale_High
    Test_Scale High
    2 rows selected.
    SQL> SELECT *
      2    FROM temp
      3   WHERE UPPER (col1) LIKE '%TEST_SCALE\_H%' ESCAPE '\'
      4  /
    COL1
    Test_Scale_High
    1 row selected.
    SQL>Regards,
    Jo
    Edited by: Joice John : Added 2 Sample Codes

  • How to replace the string of column value with other column value in same table

      
    I have a temp table  which contains 
    Id  Name CTC   Address                      Content
    1    Ross  $200   6th block                  Dear #Name your  CTC  is #CTC and your address is  #address
    2   Jhon   $300   1oth cross                 Dear #Name your  CTC  is #CTC and your address is  #address
    Now i want to  select content    so that it should get  replace with  the respective  columns  and final output should come like this 
     Dear Ross your  CTC  is 200 and your address is    6th block  
      Dear Jhon your  CTC  is 300 and your address is   10th cross  
    Kindly suggest

    I think RSingh suggestion is ok ... what do you mean by another way? ...maybe something more generic?
    maybe build a table whith the list of col you need to "replace" and dinamically build the replace query ...
    declare @colList table(colName varchar(100))
    insert into @colList
    select 'name'
    union all select 'ctc'
    union all select 'address'
    declare @cmd varchar(2000)
    select @cmd='select '+ (select 'replace(' from @colList for xml path('') +' content '+
    (select ',''#'+ colName +''', '+ colName +')' from @colList for xml path(''))
    +' from YOURTABLENAME '
    exec (@cmd)
    or your request was different ?

  • Tricky Regexp and string to column-row SQL

    Hi All,
    I am TRYING to build an SQL that will convert a string passed as
    HP|250 GB * 2 + 80 GB * 3 + 100 GB | SATAto
    HP | 250 GB | SATA
    HP | 250 GB | SATA
    HP | 80 GB | SATA
    HP | 80 GB | SATA
    HP | 80 GB | SATA
    HP | 100 GB | SATAMy attempt so far is (which tells me to learn more about regexp)
    WITH T AS
      ( SELECT q'[HP|250 GB * 2 + 80 GB * 3 + 100 GB | SATA]' str FROM DUAL
      t2 AS
      (SELECT trim(regexp_substr(str,'[^|]+',1,level)) val
       FROM T
       CONNECT BY level <= LENGTH (str)-LENGTH(REPLACE(str,'|'))+1
      ),t3 AS
    (SELECT DISTINCT trim(regexp_substr(val,'[^+]+',1,level)) val
    FROM t2 WHERE VAL LIKE '%*%' OR VAL LIKE '%+%'
    CONNECT BY level <= LENGTH (val)-LENGTH(REPLACE(val,'+'))+1
      ),t4 as
      (SELECT VAL,ROWNUM RN FROM T2 A1
       WHERE VAL NOT LIKE '%*%' OR VAL NOT LIKE '%+%'),
      t5 as
      (SELECT A.VAL MK, T3.VAL CONFG, B.VAL TYP
       FROM   T3, (SELECT VAL FROM T4 WHERE RN = 1)A,(SELECT VAL FROM T4 WHERE RN = 2) B)
       SELECT *
       FROM   T5;And output I got so far is:
    MK                                        CONFG                                     TYP                                      
    HP                                        80 GB * 3                                 SATA                                     
    HP                                        250 GB * 2                                SATA                                     
    HP                                        100 GB                                    SATA                                      Please suggest what more shall I do to get the desired output(An SQL)?
    BANNER                                                                          
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production          
    PL/SQL Release 11.2.0.1.0 - Production                                          
    CORE     11.2.0.1.0     Production                                                        
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production                         
    NLSRTL Version 11.2.0.1.0 - Production  Thanks for reading this post
    *009*

    with t1 as (
                select 'HP|250 GB * 2 + 80 GB * 3 + 100 GB | SATA' str from dual union all
                select 'INTEL|40 GB  + 55 GB| IDE' from dual
         t2 as (
                select  regexp_substr(str,'^[^|]+') mk,
                        trim(regexp_substr(replace(str,'|','+'),'[^+]+',1,column_value + 1)) element,
                        regexp_substr(str,'[^|]+$') typ
                  from  t1,
                        table(
                              cast(
                                   multiset(
                                            select  level
                                              from  dual
                                              connect by level <= length(regexp_replace(str || '+','[^+]'))
                                   as sys.OdciNumberList
    select  mk,
            trim(regexp_replace(element,'\*.*$')) val,
            typ
      from  t2,
            table(
                  cast(
                       multiset(
                                select  level
                                  from  dual
                                  connect by level <= substr(regexp_substr(element,'\*.*$'),2)
                       as sys.OdciNumberList
    MK         VAL        TYP
    HP         250 GB      SATA
    HP         250 GB      SATA
    HP         80 GB       SATA
    HP         80 GB       SATA
    HP         80 GB       SATA
    HP         100 GB      SATA
    INTEL      40 GB       IDE
    INTEL      55 GB       IDE
    8 rows selected.
    SQL> SY.
    P.S. Post your version. If 11.1 it can be simplified. If 11.2 can be simplified even more.

  • Working with comma seprated string in column

    hi,
    RDBMS:Oracle 10gR2
    I have a table with following structure
    Table : t1
    id int
    emails varchar2 (200)
    newEmail varchar2 (150)
    Sample data is as following
    id   emails                                                                                      newEmail
    1    [email protected],[email protected],[email protected]      null
    2
    [email protected],[email protected],[email protected]            null
    I can use following query to extract data from comma separation to row.
    select id,regexp_substr(emails, '[^,]+', 1, rownum) Emails
      from t1
      connect by level <= length(regexp_replace(emails, '[^,]+')) + 1
    Now I have to perform 2 operations
    1- find /count email ids per id, to estimate how many ids has single and how much  have multiple in emails.I have tried following but  it just remain in execution
    with Email as
    select id,regexp_substr(emails, '[^,]+', 1, rownum) Emails
      from t1
      connect by level <= length(regexp_replace(emails, '[^,]+')) + 1
    select id,emails from email
    group by id,emails
    having count (id)>1;
    2- I want to write update newEmail field from  first value in Emails in table t1 and remove updated value from emails field of table. so If emails has 5 email addresses (1,2,3,4,5) in it , after update it will have 4.I a not sure hoow to do that ?
    thanks

    You need to fix your data model.
    Storing multiple values in a single value column is bad database design and breaches the rules of normalization.
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 1 as id, '[email protected],[email protected],[email protected]' as stupid_string from dual union all
      2             select 2, '[email protected],[email protected],email6.domain.com,[email protected]' from dual)
      3  -- ----------------------------------------------------
      4  -- END OF TEST DATA - USE QUERY BELOW AGAINST OWN TABLE
      5  -- ----------------------------------------------------
      6  select id
      7        ,level as email_id
      8        ,regexp_substr(stupid_string,'[^,]+',1,level) as email
      9  from   t
    10  connect by id = prior id
    11         and level <= regexp_count(stupid_string,',')+1
    12         and prior sys_guid() is not null
    13* order by 1,2
    SQL> /
            ID   EMAIL_ID EMAIL
             1          1 [email protected]
             1          2 [email protected]
             1          3 [email protected]
             2          1 [email protected]
             2          2 [email protected]
             2          3 email6.domain.com
             2          4 [email protected]
    7 rows selected.

Maybe you are looking for

  • What is the Keyboard Backlight attached to?

    Hey there. A while back I spilled some milk on my macbook pro 15" old model (NOT the unibody) keyboard and although I finally got the sticky keys issue sorted out (I spent a good 5-6 hours on my day off taking off all the keys and cleaning them, and

  • Page level column may not be referenced

    I have a report that has a data link connecting two queries. The child layout will not show up if the link is not equal but the parent layout does. What i need to do is show neither layout if the parent and child are not equal. I tried creating a sum

  • Totals for Hierarchys not correct with condition

    Dear All I have a Bex query with two hierarchys, one in rows and the other in column. query is working perfectly fine without condition in query. when there is a condition added in the query for the total amount more than or equal to * the totals are

  • Multiple document for request correspondence FB12

    Hello all, currently i'm using version 4.7. as known in std t-code FB12, we need to request which documents to generate correspondence. steps are:- 1. enter company code 2. choose correspondence type 3. key in document number & fiscal year as for ite

  • Why I can't see some songs in my 30G video Ipod if I search via artist?

    Hi. This is an Ipod question. I load my iTunes library in 2 Ipods,the new 30G video and in the old 20G photo. Why is it that in the 20G Ipod when I search for the songs via artist, all of them appear, but when I search via artist in the 30G Ipod in s