Aggregating string fields in straight SQL under Oracle 8, 9, or 10

I have an application that requires the values of a character field to be aggregated over a number of rows and the result returned as a single string in the resulting row. The function needed is like the LIST function in Sybase SQL:
The LIST aggregate function is different from the others in that it doesn't return a single simple value but a string containing a formatted list of multiple values. The simplest form of LIST evaluates the expression for every row in a group, converts those values to strings, and concatenates them together into one long string with a comma (,) separating each value.
Here is an example that eliminates duplicate values, changes the "," separator to ", ", and sorts the results:
SELECT LIST ( DISTINCT state, ', ' ORDER BY state ) AS different_states
FROM employee
WHERE dept_id = 100;
different_states
================
CO, FL, IL, MI, NY, PA, RI, TX, UT, WY
Is there a way to accomplish this in Oracle SQL short of writing a function similar to LIST in PL/SQL?

Thank you all for your responses. The upshot seems to be that once we are on 10g ( 6mo to a year ) there is hope, but for now a PL/SQL function is probably the only answer.
It seems odd that Sybase is the only DBMS that offers such a useful function in such a simple and elegant form.

Similar Messages

  • Performance of PL/SQL-packages under Oracle 11gR2

    Under Oracle 9i I have used PL/SQL-packages/procedures to perform complicated initializations of the tables of a database schema.
    This was always a long job ... but an execution time of about 4 hours was acceptable!
    Now I changed to Oracle 11g.
    And now there is the following behaviour:
    When I create a NEW instance of the database and then create the schema the execution time ( using the same PL/SQL-packages as in Oracle 9i ) is more than 12 hours which is not acceptable anymore!
    When I only drop the schema ( in the EXISTING instance ) with a drop user (owner of the schema) cascading and then create the schema again the execution time for the same initialization is less than 3 hours which is OK.
    Does anyone have an idea about the reason for such a 'strange' behaviour?
    ... Or does anyone have a hint where I could look for such reasons?

    Hi,
    did you compare the execution plan in 9i and 11g R2?
    when you go to 11gR2, did you keep the statistic of the 9i, so if any regression, 11g can use 9i plan?
    thanks

  • A record selection problem with a string field when UNICODE database

    We used report files made by Crystal Reports 9 which access string fields
    (char / varchar2 type) of NON-UNICODE database tables.
    Now, our new product needs to deal with UNICODE database, therefore,
    we created another database schema changing table definition as below.
    (The table name and column name are not changed.)
        char type -> nchar type
        varchar2 type -> nvarchar2 type
    When we tried to access the above table, and output a report,
    the SQL statement created from the report seemed to be wrong.
    We confirmed the SQL statement using Oracle trace function.
        SELECT (abbr.) WHERE "XXXVIEW"."YYY"='123'.
    We think the above '123' should be N'123' because UNICODE string
    is stored in nchar / nvarchar2 type field.
    Question:
    How can we obtain the correct SQL statement in this case?
    Is there any option setting?
    FYI:
    The environment are as follows.
        Oracle version: 11.2.0
        ODBC version: 11.2.0.1
        National character set: AL16UTF16

    With further investigating, we found patterns that worked well.
    Worked well patters:
        Oracle version: 11.2.0
        ODBC version: 11.2.0.1
        National character set: AL16UTF16
        Report file made by Crystal Reports 2011
        Crystal Reports XI
    Not worked patters:
        Oracle version: 11.2.0 (same above)
        ODBC version: 11.2.0.1 (same above)
        National character set: AL16UTF16 (same above)
        Report file made by Crystal Reports 2011 (same above)
        Crystal Reports 2008 / 2011
    We think this phenomenon is degraded behavior of Crystal Reports 2008 / 2011.
    But we have to use the not worked patters.
    Anything wrong with us? Pls help.
    -Nobuhiko

  • How to convert epoch time to datetime in sql*loader Oracle

    Hello,
    I wan't to question how to convert epoch time to datetime in sql*loader Oracle. I try this script for convert epoch time to datetime in sql*loader, but error:
    Record 1: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 2: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 3: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    This is my loader:
    LOAD DATA INFILE 'C:\Documents and Settings\Administrator\My Documents\XL_EXTRACT_211\load.csv'
    into table TEMP_TEST_LANGY append
    FIELDS TERMINATED BY ','
    TRAILING NULLCOLS
    DATADATA CHAR "TO_DATE('01-JAN-1970','DD-MON-YYYY')+:datadata/86400"
    This is my csv file:
    79314313.7066667
    79314336.2933333
    79314214.3466667
    This is my table:
    CREATE TABLE TEMP_TEST_LANGY
    DATADATA DATE
    Thanks
    Edited by: xoops on Sep 21, 2011 8:56 AM
    Edited by: xoops on Sep 21, 2011 8:58 AM

    thanks for your answer, but I asked to use sql loader instead of the external table, which so my question is why can not the epochtime converted to datetime, if there is no way to convert a datetime epochtime using sql loader, so I'm required to use the external table. thank you.
    This is my error log:
    Column Name Position Len Term Encl Datatype
    DATADATA FIRST * , CHARACTER
    SQL string for column : "TO_DATE('1-Jan-1970 00:00:00','dd-MM-YYYY hh24:mi:ss') + (:DATADATA/60/60/24)"
    Record 1: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 2: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 3: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Edited by: xoops on Sep 21, 2011 12:33 PM

  • Updated to CR 2008 - now have new problem with truncated String fields.

    Hi there
    I'm hoping someone has a simple answer for this one...  notice there's a lot of it on forums but I haven't found an answer.
    Since updating to Crystal 2008 (Crystal 12), we have found that some reports are suddenly truncating string fields at 255 characters, despite the field value being much longer in the database.
    Does anyone know what to do to allow these fields to print in completion?
    Database connection is ODBC RDO.
    regards
    -Karen

    What is the database Oracle, SQL server etc.
    Can you query the database directly with another query tool, eg SQL Server Management Studion or SQL developer/Toad for Oracle.
    You can then run the Crystal query directly and see if its your ODBC connection that is truncating the datafield or Crystal.
    I have memo fields on SQL server with up to 2000 characters and these display in Crystal 2008 without any problem. We use ODBC (RDO) too.
    Ian

  • How to Aggregate String Fields

    Hi
    I have a Query in which i Use Sum to aggregate fields , now i have some new fields on the table which are String, i want to add those to same existing queries where Sum is happening. and i want those string values to get aggregated as well like for rows
    where sum is  happening  for same rows i want a concatenated value for string field
    like i have  two rows
                 Field 1 (int)  -- Field 2(string) 
    Row 1:     1                    'abc'
    Row 2:      2                    'xyz'
    When I aplly Sum(Field1) it returns 3 and i want to get back 'abc,xyz' for Field 2  is there a function there SQL which i can use ?
    or any work around in SQL

    Hi,
    This concatinates all the rows , i need only those rows concatinated which sumed up toagather basesd upon group by caluse, so if have a group by  clause on Field 3 then i would like to see result as  Two resultant rows
    Row 1:  Field1 = 3 and Field2 = 'abc,xyz'
    Row 2:  Field1 = 7 and Field2 = 'JGG,AA'
    is there a way to do this
    Field 1 (int)  -- Field 2(string)       Field3 
    Row 1:     1                    'abc'        1
    Row 2:      2                    'xyz'        1
    Row 3:      3                    'JGG'        2
    Row 4:      4                    'AA'        3

  • String Fields Length

    Hi,
    Length of string fields in my crystal report are locked to 20 by default, but my data source's query's field length is 50.  How can I fix the crystal report to show all 50 characters in the report?
    Thanks and regards,
    Al

    Hi Hitesh and Crystalier,
    Thanks for your replies.
    I check marked "Can Grow" option and it didn't work.
    Database is SQL Server 2005 and my connection is OLE DB (ADO).  The database field is VARCHAR(50).
    I noticed, under the Field Explorer -->  Database Fields, the type of the field is showing as "String [20]".  But the field in the datasource (SQL Server 2005) is Varchar(50).  Also, when I right-clicked Browse Data on the field on Field Explorer, the data that was returned are all trimmed to 20 characters.
    Thanks and regards,
    Al

  • Can we use Dynamic SQL in Oracle Reports ?

    Hi ,
    Can we use Dynamic SQL in Oracle Reports ?
    If yes please give some examples .
    Thanx
    srini

    I believe the built-in package SRW.Do_Sql is what you are looking for
    Example from the document:
    /* Suppose you want to create a "table of contents" by getting the
    ** first character of a columns value, and page number on which its
    ** field fires to print. Assume that you want to put the "table of
    contents"
    ** into a table named SHIP. You could write the following construct:
    DECLARE
    PAGE_NO NUMBER;
    PAGE_FOR INDEX NUMBER;
    SORT_CHAR CHAR(1);
    CMD_LINE CHAR(200);
    BEGIN
    SORT_CHAR := :SORT_NAME ;
    IF :CALLED = Y THEN
         SRW.GET_PAGE_NUM(PAGE_FOR_INDEX);
         SRW.USER_EXIT(RWECOP PAGE_FOR_INDEX
         P_START_PAGENO);
         SRW.MESSAGE(2,TO_CHAR(:P_START_PAGENO));
    END IF;
    SRW.GET_PAGE_NUM(PAGE_NO);
    CMD_LINE := INSERT INTO SHIP VALUES
                          (||SORT_CHAR||,||TO_CHAR(PAGE_NO)||);
    SRW.MESSAGE(2,CMD_LINE);
    SRW.DO_SQL(CMD_LINE);
    COMMIT;
    EXCEPTION
      WHEN DUP_VAL_ON_INDEX THEN
            NULL;
      WHEN SRW.DO_SQL_FAILURE THEN
            SRW.MESSAGE(1,FAILED TO INSERT ROW INTO SHIP TABLE);
      WHEN OTHERS THEN
           COMMIT;
    END;

  • SQL to Oracle Migraton - Unable to create source model in Migration Workben

    We are trying to use Oracle Migration Workbench utility to transfer data from SQL to Oracle. when we start creating the source model we get the following error :-
    failed to load source model ora-01401 inserted value too large for column.. this is the error at the ss2k_syslogins table. this is a logical model creation from sql server db.
    In case if this is a data issue with the syslogins table/view, is there any way to overcome this or whether we can do any settings at Workbench Level to overcome this..
    Thanks in advance,
    John.

    I think I figured it out.
    1 - I used the Migration Work Bench that came with the 9.2.0.1 client - BAD IDEA.
    2 - I down loaded the OMWB (10.x) - GOOD IDEA. I also downloaded the plugins so that the versions would match each other. Get rid of any existance of the 'old' OMWB directory under the OracleHome, so as not to get confused.
    3 - I realized that you just extract the OMWB.zip file to the C: drive like some third world DOS application, so it won't show up in under your start menu.**
    **I find this kinda cheesy that the Oracle installer is not involved here to add it to the Oracle Configuration and Migration menu in start up. I suppose you can copy the unzipped struture over top of the existing clint directory structure, but still dumb.
    3 - The other odd piece, you down load the plugin as a zip (and not a jar), BUT DON'T UNZIP IT!! Rather place it in the ..\plugins directory, underneath wherever you unzipped the OMWB, and RENAME IT with a .JAR extension (again don't unzip).
    4 - Make a shortcut on your desktop to the omwb.bat file (from where ever you unzipped the OMWB product)
    5 - Fire up that icon and the product will look at the new .JAR in the plugin folder and 'tada', you have OMWB with your specific database plugin available.
    The new product didn't hang for me. Now I just need to figure out how port this into a shema name OF MY CHOSING, and not the generic OMWB_Login1 that it created.
    I f anyone has info on that, let me know.... I think its in the destination creation (step two of the whole process).
    Jeff Ferrel - State of Nevada

  • How to validate XML Digital Signature with XML DB (o PL/SQL) in Oracle 11g

    Hi,
    Do you know if there is possibility to validate XML Digital Signature using XML DB (or PL/SQL) in Oracle 11g?
    Let say I have CLOB/XMLType containing Digitally Signed XML, and I want to validate, that thsi is proper signature. I also have public key of signer (I could store it in CLOB or file or Oracle wallet).
    Is it possible to do?
    If there is need to install additional component - then which one?
    Regards,
    Paweł

    Hi,
    this is what i got from someone...
    but the links he gave are not opening up...
    u have to place a picture there and have to load the digital signatures as Jpegs on to the server to OA top
    and have to refer them in the XML for dynamically get the signature on the reports
    when u select the properties of the picture placed in the XML template,
    there will be one tab with "URL"... in that u have to give the path for that jpegs
    Pls refer the following documents for enabling digital signature on pdf documents.
    http://iasdocs.us.oracle.com/iasdl/bi_ee/doc/bi.1013/e12187/T421739T481159.htm#5013638    (refer section 'Adding or Designating a Field for Digital Signature'
    http://iasdocs.us.oracle.com/iasdl/bi_ee/doc/bi.1013/e12188/T421739T475591.htm#5013688
    (Implementing a Digital Signature
    Is the BI Publisher installed on your instance of version 10.1.3.4 or higher?
    Pls procure a digital signature as soon as possible. The process can take time. OR we could use any certificate that you already might have OR generate a certificate using Oracle Certificate Authority for demo.

  • String Truncation Exception in SQL Server

    I get an error when issuing an updateRow() after updateString("String Field", "Test"). My exception is:
    java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]String data
    , right truncation
    at sun.jdbc.odbc.JdbcOdbcResultSet.setPos(JdbcOdbcResultSet.java:5068)
    at sun.jdbc.odbc.JdbcOdbcResultSet.updateRow(JdbcOdbcResultSet.java:4053
    at exuberance.remote.JDBCClient.setFieldValue(JDBCClient.java:446)
    I believe this occurs because Java stores strings in Unicode (2 bytes), but I'm not positive. Any help would be much appreciated.

    You are passing a string that is too big.
    Possibilities:
    -String you are passing is bigger than field it is being inserted into.
    -Total length of SQL call exceeds the max len limit (8000?, 2174?)
    -The string is a actually a 'blob' type of string (greater than 8000 on MS SQL?) and you need to use the same sort of handling for blobs to pass it.

  • String Field rendering as Number Field in CR Basic for VS2008

    I recently migrated from CR for VS2005 to CR Basic for VS2008 and am creating my first report using CR 2008. The SQL result set returns rows containing strings (nvarchar), integers and decimal (7,2) fields.
    The report is getting all rows in the result set, but the string fields as defined in the SQL are 1) rendering in the report as numbers, and 2) showing as empty. The non-string fields render fine. I tried reformatting the report field to string, but only the Number tab appears in the formatting dialog. I also tried converting the SQL field result into an unbound string field, as well as tried the ToText function, but the results were the same. I suspect the field appears empty because of the formatting issue.
    How can I get CR Basic for VS2008 to render a string (nvarchar) field as a string?

    Try placing the field inside a formula field or inside a text field.  That should cause the field to be shown no matter what type of data it is.  If the data is still not showing, then perhaps it is not being returned properly. 
    Things to check:
    -Are you connecting directly to the tables - or are you connecting to a stored procedure?  If you are connecting to a stored procedure and you are using Temp Tables, then make sure you add the line "SETNOCOUNT ON" to your stored proc.
    -Run SQL profiler - see what query is being made, then try running that exact same query through the SQL admin console (Or some other utility that lets you run SQL queries)
    Thanks
    Shawn

  • Update Yes/No field in access table through oracle procedure

    Hi,
    How to update Yes/No field in access table through oracle procedure. all other fields like AutoNumber, Text I can update it. Yes/No field how to update? Please, any one can help me?
    Thanks and Regards,
    Sudha.

    Sudha Teki wrote:
    select "fldPost" from tblPHd@ODBCLNKNot quite sure what you mean, but the way you select the column would indicate a case sensitive column name
    Look at this example
    SQL> create table t
      2  ("this" varchar2(10))
      3  /
    Table created.
    SQL> insert into t values ('hello')
      2  /
    1 row created.
    SQL> select *
      2    from t
      3  /
    this
    hello
    SQL> select this
      2    from t
      3  /
    select this
    ERROR at line 1:
    ORA-00904: "THIS": invalid identifier
    SQL> select "this"
      2    from t
      3  /
    this
    helloIs your column name also case sensitive?

  • Converting an old Tom Kyte function to straight SQL

    I am on Oracle 10.2
    There is an old tom kyte function (10+ years old) floating around that will remove constants so I can look for queries that don't use bind variables. It has to loop through each character i a sql so its slow. I was able to convert part of it to using a regular expression. There are alot of new SQL features, so I am trying to replace it with sql.
    The old REMOVE_CONSTRAINTS function is at the bottom.
    I have already converted the really slow part of the function which loops through every character in a query (first loop). I did it with a regular expression. See test case below.
    I am having trouble with the second part that replaces numbers.
    The translate is there because I was having trouble passing a single quote to a regular expression and got tired of looking at it. So I converted all single quotes to '@''
    Basically the translate turns all single quotes to @
    So anything surrounded by an @ and an @ gets turned into a single @
    This is a bit flawed. If I have a literal that has a quote in it, this will get screwed up. It is not something I have to worry about right now though.
    select mytest,regexp_replace(translate(to_char(mytest),chr(39),'@'),'@[^@]+@','@') from test
    create table test (mytest clob);
    insert into test values ('select 1 from mytable where x = '||chr(39)||'v'||chr(39)||' and y = '||chr(39)||'q'||chr(39));
    insert into test values ('select 1 from mytabe where a = '||chr(39)||'xyz'||chr(39));
    commit;
    SQLt>  select mytest,regexp_replace(translate(mytest,chr(39),'@'),'@[^@]+@','@') from test
      2  /
    MYTEST
    REGEXP_REPLACE(TRANSLATE(MYTEST,CHR(39),'@'),'@[^@]+@','@')
    select 1 from mytable where x = 'v' and y = 'q'
    select 1 from mytable where x = @ and y = @
    select 1 from mytabe where a = 'xyz'
    select 1 from mytabe where a = @I can put this in a pipeline function and it will run fast enough. I think I can probably make this straight sql. anyone know how? also, I have some column names with numbers in it. anyone know a good way to ignore numbers on the left side of the where clause?
        l_query := translate( l_query, '0123456789', '@@@@@@@@@@' );
    --   dbms_output.put_line(l_query);  
        for i in 0 .. 8 loop
            l_query := replace( l_query, lpad('@',10-i,'@'), '@' );
            l_query := replace( l_query, lpad(' ',10-i,' '), ' ' );
        end loop;
      function remove_constraints ( p_query in clob ) return clob AS
        l_query clob;
        l_char  varchar2(1);
        l_in_quotes boolean default FALSE;
        l_length number := 0;
        vmodule varchar2(30);
        vaction varchar2(30);
    begin
        dbms_application_info.read_module(vaction,vmodule);
        dbms_application_info.set_module(vaction,nvl(vmodule,0)+1);
        for i in 1 .. length( p_query )
        loop
            l_char := substr(p_query,i,1);
            if ( l_char = '''' and l_in_quotes )
            then
                l_in_quotes := FALSE;
            elsif ( l_char = '''' and NOT l_in_quotes )
            then
                l_in_quotes := TRUE;
                l_query := l_query || '''#';
                dbms_output.put_line('a '||l_char);
                dbms_output.put_line( '''#');
            end if;
            if ( NOT l_in_quotes ) then
                l_query := l_query || l_char;
            end if;
        end loop;
    --dbms_output.put_line(l_query); 
        l_query := translate( l_query, '0123456789', '@@@@@@@@@@' );
    --   dbms_output.put_line(l_query);  
        for i in 0 .. 8 loop
            l_query := replace( l_query, lpad('@',10-i,'@'), '@' );
            l_query := replace( l_query, lpad(' ',10-i,' '), ' ' );
        end loop;
        return upper(l_query);
    end;
       

    In 10g you can use
    FORCE_MATCHING_SIGNATURE     The signature used when the CURSOR_SHARING parameter is set to FORCE
    http://docs.oracle.com/cd/B19306_01/server.102/b14237/dynviews_2113.htm#REFRN30246

  • Truncate numbers from string field

    Afternoon all,
    This time I'd like to extract only 2 strings out of a string field. The field is of sales area which contains numbers and letters. For example, Scotland is given a number 01, West midlands is 02, Ireland however is given IR.
    however, the field which holds the information is like, 012, where 01 is the area number and 2 is type of area number.
    The information which we are interested in is first two strings.
    I have tried this in the formula given below but it doesn't work, it states a field is required
    If hasvalue({?Sales Area}) then
    totext(Minimum({slslsp.slr_slsperson}[1 to 2])) + " - " +
    totext(Maximum({slslsp.slr_slsperson}[1 to 2]))
    else
    "n/a"
    Should I be using a truncate and if yes then how?
    P.S. This is to show only the sales area number or text if selected under a parameter. The values of the parameter will stay the same. In other words it is just to show in the report.
    Many thanks once again
    Regards
    Jehanzeb

    Is it a range parameter? If so try this
    If hasvalue({?Sales Area}) then
    totext(Minimum({slslsp.slr_slsperson})[1 to 2]) + " - " +
    totext(Maximum({slslsp.slr_slsperson})[1 to 2])
    else
    "n/a"
    regards,
    Raghavendra.G
    Edited by: Raghavendra Gadhamsetty on Jan 16, 2009 4:16 PM

Maybe you are looking for