Question on using CAST, MULTISET and TABLE

Hi,
I am trying to do something that is utterly meaningless, but I am studying the use of CAST with MULTISET and TABLE.
I have created a type: a Nested Table of Number values:
create type numTable as table of number;
Now I perform the following query:
select d.dname
, ( select avg(column_value)
from table
( cast( d.salaries as numTable)
) Department_Avg_Salary
from ( select cast
( multiset
( select e.sal
from emp e
where e.deptno = d1.deptno
) as numTable
) salaries
, d1.dname
from dept d1
) d
I had expected to see each department name and the average salary within that department. Instead, I see the same Department_Avg_Salary value for each row - the average of the first department:
DNAME DEPARTMENT_AVG_SALARY
ACCOUNTING 1875
RESEARCH 1875
SALES 1875
OPERATIONS 1875
However, when I change the query to the following:
select d.dname
, d.salaries
from ( select cast
( multiset
( select e.sal
from emp e
where e.deptno = d1.deptno
) as numTable
) salaries
, d1.dname
from dept d1
) d
I get the following result - note that each department shows the correct list of salaries, not the list of the 1st department's salaries over and over.
DNAME
SALARIES
---------------------------------------------------------ACCOUNTING
NUMTABLE(2450, 1300)
RESEARCH
NUMTABLE(800, 2975, 3000, 5000, 1100, 3000)
SALES
NUMTABLE(1600, 1250, 1250, 2850, 1500, 950)
OPERATIONS
NUMTABLE()
Can someone explain why the
, ( select avg(column_value)
from table
( cast( d.salaries as numTable)
) Department_Avg_Salary
does not give an average per department but instead only the first department's average?
thanks for your help!
regards
Lucas Jellema

scott@ORA92> select d.dname,
  2           (select avg(column_value)
  3            from   table (cast (d.salaries as numTable))
  4            where d.dname = dname) Department_Avg_Salary
  5  from   (select cast (multiset (select e.sal
  6                          from   emp e
  7                          where  e.deptno = d1.deptno) as numTable) salaries,
  8                 d1.dname
  9            from    dept d1) d
10  /
DNAME          DEPARTMENT_AVG_SALARY
ACCOUNTING                2916.66667
RESEARCH                        2175
SALES                     1566.66667
OPERATIONS

Similar Messages

  • Question on rectangle with graph and table

    i inserted the graph chart and table in a rectangle for similar values... but when i see the preview of this scenario... its showing seperately.... its mean that first showing the rectangle and then graph and then table in the preview page. when i saved
    it into PDF; both chart and table are coming in same rectangle.
    can any one please give a quick response to this.

    Hi  Nagalinga,
    Based on my understanding, you create a chart and table with same values, then you use a rectangle to contain them. When previewing the report, rectangle, chart, table displays separately. However, when exporting to PDF, the chart and table display in a
    same rectangle.
    In Reporting Service, rectangles can be used as containers to help control the way data regions render in a report. However, a rectangle is only a container for items that you either create in the rectangle or drag into the rectangle. If you draw a rectangle
    around an item that already exists on the design surface, the rectangle will not act as its container. So in your scenario, I suppose you create a chart and table then draw a rectangle around them, rectangle, chart and table will display separately when previewing
    report. As we tested in our environment, we create a chart and table with same values, then drag them into a rectangle, the chart and table both display in a rectangle whether we preview the report or render the report as PDF. Please refer to the screenshots
    below:
    Reference:
    Rectangles and Lines (Report Builder and SSRS)
    If you have any question, please feel free to ask.
    Best regards,
    Qiuyun Yu

  • Beginners question about creating first database and tables

    Hi all,
    i recently have installed 10g express edition, because i want to transform my php-script from mysql to oracle database. (due to the fact that mysql is "not allowed sofware" at the company i work for).
    it is a quit small script, just a shift-report system, build because of frustration about an used shift report system based on excel sheets. Company likes it, but IT-department rejected it, because it is myssql. They do own a lot of oracle servers, so they set up a database for me, got a username and password.(Tnsnames entry). The rest i have to do by myself, no further support from IT department.
    I have made 2 simple php functions to connect to database:
    // for connection home server:
    function conn()
         $user = 'user';
         $password = 'password';
         $conn = oci_connect($user, $password, 'localhost/XE');
         return $conn;
    // for connection at work:
    function Xconn()
         $db = '(DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = xxx.eu.xxx.com)(PORT = 1521))
        (CONNECT_DATA = (SID = NVGPP)))';
         $user = 'xxxxxxxx';
         $password = 'xxxxxxx';
         $conn = oci_connect($user, $password, $db);
         return $conn;
    }I just add or remove X character before function name, for use at home or at work.
    both do work fine.
    First thing i wanted to do, is to create my database and tables.
    Schema dump from mysql:
    -- phpMyAdmin SQL Dump
    -- version 2.11.1
    -- http://www.phpmyadmin.net
    -- Host: localhost
    -- Generatie Tijd: 03 Aug 2010 om 21:35
    -- Server versie: 5.0.24
    -- PHP Versie: 5.2.4
    SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
    -- Database: `ewb`
    -- Tabel structuur voor tabel `afsprakenblad`
    CREATE TABLE IF NOT EXISTS `afsprakenblad` (
      `id` mediumint(8) unsigned NOT NULL auto_increment,
      `naam` tinytext NOT NULL,
      `afspraak` text NOT NULL,
      KEY `id` (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COMMENT='Afsprakenblad' AUTO_INCREMENT=13 ;
    -- Tabel structuur voor tabel `verslag`
    CREATE TABLE IF NOT EXISTS `verslag` (
      `id` int(10) unsigned NOT NULL auto_increment,
      `ewb_id` int(10) unsigned NOT NULL,
      `datum` date NOT NULL,
      `dienst` tinytext NOT NULL,
      `ploeg` tinytext NOT NULL,
      `gebouw` varchar(10) NOT NULL,
      `installatie` tinytext NOT NULL,
      `subdeel` tinytext NOT NULL,
      `subsubdeel` tinytext NOT NULL,
      `sap` int(4) unsigned NOT NULL,
      `tekst` text NOT NULL,
      `status` tinyint(3) unsigned NOT NULL,
      `afdeling` tinytext NOT NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4663 ;
    -- Tabel structuur voor tabel `wachtverslag`
    CREATE TABLE IF NOT EXISTS `wachtverslag` (
      `id` int(10) unsigned NOT NULL auto_increment,
      `datum` date NOT NULL,
      `dienst` tinytext NOT NULL,
      `team` tinytext NOT NULL,
      `afdeling` tinytext NOT NULL,
      `status` enum('open','dicht') NOT NULL default 'open',
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=800 ;When i wanted to create a new databse with: CREATE TABLE ewb, i get an error that databse already is mounted??
    How do i create this database and tables?
    after googling i read something about schema owners, but cant find anything about how to copy my mysql database/tables to oracle.
    Please, help is really appreciated by me.

    Translating from mysql to Oracle will need a bit of fixups for the DDL, once an oracle instance is created, set up and running, you won't create a database but you will have a database user or users that create/own a collection of tables, indexes, functions, procedures, etc.
    It will take a bit of pouring through the oracle documentation to get those table create statements to work, i.e. the engine=, charset=, auto_increment items won't succeed, datatypes need adjustments, the tic marks around the entity names aren't necessary, quite a few other items from the mysql data definition language don't have an oracle equivalent.

  • What is the best font to be used in graphs and tables?

    I want to know what is the best font (or the most used) for discoverer10g graphs and tables.
    I used Arial, Dialog, Veranda, 7, 8, 9 but it seems that there is a space between letters especially on the graph. I’m looking for a font that does not have this space between letters.
    Any help will be appreciated.

    Hi,
    Any font holds good,depends on the choice of the individual user.
    neways go through this link http://docs.tpu.ru/docs/oracle/en/oas/9.0.4.0.0/bi.904/b10268/intro_gr.htm#1026899
    Hope this helps you!!
    Regards,
    Kranthi

  • Need examples of using HEAD, BODY and TABLE options of SET MARKUP

    Hi!
    Looking for examples of using the HEAD, BODY and TABLE options of the SET MARKUP command in SQL*Plus. Will be used in 10.2.04 on Linux.
    Have been trying to set up an "H1" header but not having any success. Documentation and examples in the documentation are not very helpful.
    Thanks for your time and help!
    Dave Venus

    $ echo "select sysdate from dual;"|
      sqlplus -L -s -M 'html on head <title>MyTitle</title> body bgcolor="black" table border="0" scott/tiger
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <meta name="generator" content="SQL*Plus 10.2.0">
    <title>MyTitle</title>
    </head>
    <body bgcolor="black">
    <p>
    <table border="0">
    <tr>
    <th scope="col">
    SYSDATE
    </th>
    </tr>
    <tr>
    <td>
    2009-02-12 15:22:00
    </td>
    </tr>
    </table>
    <p>
    </body>
    </html>Edited by: Laurent Schneider on Feb 12, 2009 3:22 PM

  • Question about using 10g/11g and APEX ...

    Hi,
    I just recently learned of Oracle's APEX and have a few questions about using it.
    Can I use APEX with express, standard, and enterprise editions of 10g and 11g?
    Are all of these free to use?

    You might want to read about APEX rather than jumping into questions that are reasonably well documented. Info at http://www.oracle.com/technology/products/database/application_express/index.html
    Your specific questions:
    1) Apex is a package that can be installed into any properly licensed database.
    2) The price for the production license of the database varies by edition.
    The price for Express Edition is $0 for use in production. Part of the cost for that edition is 'no Oracle Support based support, no patches, data volume limitation, etc.'

  • Questions around use of thesaurus and synonyms

    Q1. Does thesaurus support Japanese/Chinese/Korean? The document didn't say no. But didn't confirm it explicitly.
    Q2. For ctxload to load a thesaurus import file, what encoding should be the file? UTF-8?
    Q3. Is synonym relation reflextive in Oracle Text? After define EUR is Euro, should I define Euro is EUR?
    Q4. From the document, when I define a synonym, I cannot specify language. If I define a synonym between 'USD' and 'US Dollar'. And when I query I use SYN(USD), will this expand into 'USD,US Dollar' no matter what language is the document?

    Here are some information which may answer your questions
    Ans1)
    We have a limitation for language specific character sets
    You can only add knowledge bases for languages with single-byte character sets.
    You cannot create a knowledge base for languages which can be expressed only in multibyte character sets.
    I think Japanese/Chinese/Korean are represented in multi byte character sets, so we cannot.
    Ans2) Supplied knowledge bases with Oracle text are in WE8ISO8859P1. You can store an extended knowledge base in another character set such as US7ASCII.
    Knowledge bases can be in any single-byte character set.
    Ans 3) No you dont need to.It is reflexive.
    you can check the following example
    create table test(id number, text varchar(20));
    insert into test values (1, 'os');
    insert into test values( 2, 'operating system');
    insert into test values(3, 'windows');
    exec ctx_thes.create_thes('my_thes',FALSE);
    exec ctx_thes.create_phrase('my_thes','os');
    exec ctx_thes.create_phrase('my_thes','operating system');
    exec ctx_thes.create_relation('my_thes','os','SYN','operating system');
    declare
    syno varchar2(50);
    begin
    syno := ctx_thes.syn('os','my_thes');
    dbms_output.put_line('the synonym of os is : ' || syno);
    end;
    --o/p is the synonym of os is : {OS}|{OPERATING SYSTEM}
    declare
    syno varchar2(50);
    begin
    syno := ctx_thes.syn('operating system','my_thes');
    dbms_output.put_line('the synonym of operating system is : ' || syno);
    end;
    --o/p is the synonym of op sys is : {OPERATING SYSTEM}|{OS}
    Ans 4) I think you are trying to say the following
    you have a thes file..say in spanish
    and you have an entry in that file for USD Syn in English...
    you want to ask whether still Oracle can return SYN(USD) = 'USD,US Dollar'
    Am I right?

  • Question on using Distinct operator and avoiding ORA-00936 error

    I may have answered my own question, by searching the OTN forums, but I just want to confirm what I've learned.
    I'm trying to use a distinct on one of my columns, where I am pulling multiple columns, and trying to avoid duplicate entries. From most of my textbook example, when an example is using a distinct, they were only pulling one column.
    From my example below, when I try to use a distinct, I get the following error: ORA-00936: missing expression:
    select p.list_id, distinct(p.associate_id), d.first, d.last, c.street1, c.street2, c.city, c.state, c.country, c.postal_code, c.email
    from sf.profiles p, demographics d, contact_info c
    where p.entity_id = d.entity_id
    and p.entity_id = c.entity_id
    and p.list_id = 111
    and associate_id in (insert associate_id in here
    );Once I searched OTN, I saw some examples, where they had the distinct operator as the first column. So I switched it with p.list_id, and the query ran find.
    select distinct p.associate_id, p.list_id, d.first, d.last, c.street1, c.street2, c.city, c.state, c.country, c.postal_code, c.email
    from sf.profiles p, demographics d, contact_info c
    where p.entity_id = d.entity_id
    and p.entity_id = c.entity_id
    and p.list_id = 111
    and associate_id in (insert associate_id in here);So, does the distinct operator have to go first, if using multiple columns?
    thanks
    Message was edited by:
    cmmiller

    With or without parenthesis, it's a distinct clause for all columns in select statement:
    SQL> select * from tt1;
            ID T
         10203 1
         10203 2
    SQL> select distinct(id), text from tt1;
            ID T
         10203 1
         10203 2
    SQL> select id, text from tt1;
            ID T
         10203 1
         10203 2
    SQL> Nicolas.

  • Question regarding use of Log and LogFactory in Servlets

    Hi,
    I saw the following code in an application and I would like to know where the log information would be stored. It appears that the log information is not displayed on the screen and was not able to find out where the log files are. The application was created using NetBeans and was using Tomcat. Thanks in advance.
    import org.apache.common.logging.*;
    public class Test extends HttpServlet
    private static final Log log = LogFactory.getLog(Test.class);
    String theHost;
    String theSource;
    public void init (ServletConfig config) throws ServletException
    super.init(config);
    log.info(�debug Enabled: �+log.isDebugEnabled());
    ServletContext context =config.getServletContext();
    this.thisHost=�/Test/�+config.getServletName();
    etc. etc.
    log.info(�thisHost:�+this.thisHost);
    log.debug(�Source:� +theSource());
    etc, etc.
    }

    It depends on what logging system you have set up.
    Commons.logging is an abstraction layer above logging components. It allows your code to use a variety of logging systems. However those logging systems have to be set up and configured by you. This can be via system properties, properties files, XML config files (depends on the logging system and how you use it).
    So you need to figure out which logging system is being used and then configue that system to write the logs
    matfud

  • Question about use of get_variable and if statement

    Hi!
    I have the following code in an RTF file.
    <?for-each@section:G_NYU_TSRSLT_HDR?>
    Display <?ACAD_CAREER?>
    <?xdoxslt:set_variable($_XDOCTX, 'acad_career_in', ACAD_CAREER)?>
    <?if:xdoxslt:get_variable($_XDOCTX, 'acad_career_in')='UGRD' ?> UGRD <?end if?>
    <?if:xdoxslt:get_variable($_XDOCTX, 'acad_career_in')='GRAD' ?> GRAD <?end if?>
    <?end for?>
    I believe it is looping through two rows. The first row has ACAD_CAREER = 'UGRD' and the second row has ACAD_CAREER = 'GRAD'
    The output is:
    Display UGRD
    UGRD
    Display GRAD
    UGRD
    GRAD
    For some reason, it appears like the second time the if UGRD statement is run, it still thinks the result is true.
    Any ideas?
    Thanks!

    Hi, Sent the email. Thanks for your help!!! The code which is till the problem is (all code is in form fields in the RTF):
    <?for-each@section:G_NYU_TSRSLT_HDR?>
    <?xdoxslt:set_variable($_XDOCTX, 'acad_career_in', ACAD_CAREER)?>
    Display <?ACAD_CAREER?>
    <?if:xdoxslt:get_variable($_XDOCTX, 'acad_career_in')='UGRD' ?> UGRD <?end if?>
    <?if:xdoxslt:get_variable($_XDOCTX, 'acad_career_in')='GRAD' ?> GRAD <?end if?>
    <?end for-each@section?>
    The output is:
    Display UGRD
    UGRD
    <on a new page>
    Display GRAD
    UGRD
    GRAD

  • Can we use multiset and with clause both

    Please let me know how to use both multiset and with clause.

    You need one more inlining, as e.g. in:
    SQL> select *
    from table (cast (multiset (select *
                                from (with t as (select deptno from dept)
                                      select * from t)) as sys.dbms_debug_vc2coll))
    COLUMN_VALUE                           
    10                                     
    20                                     
    30                                     
    40                                     
    50                                     
    5 rows selected.

  • CAST MULTISET...is it supported by BI

    In a precedent POst i explained the problems we had with multiple queries to display data as a hierarchical manner, with more than 2 levels
    We'd like to explore the way with CAST MULTISET...but before to spend time, we'd like to assure that it is supported by BI Publisher.
    As an example ( with one level):
    We prepared the Object Types as is :
    create or replace TYPE ETAG_T AS OBJECT("@S_NUME_OBJE" NUMBER,
                        S_NUME_ETAG NUMBER,
                        C_TYPE_ETAG VARCHAR2(4 CHAR),
                        L_DESC_ETAG VARCHAR2(50 CHAR),
                        N_NOMB_PIEC NUMBER,
                        N_SURF_TOTA NUMBER,
                        D_MODI DATE,
                        R_FONC CHAR(5),
                        R_UTIL CHAR(20),
                        C_CODE_LANG VARCHAR2(4 CHAR)
    create or replace TYPE etaglist_t AS TABLE OF etag_t
    create or replace TYPE obje_t as Object (
    "@S_NUME_OBJE" NUMBER,
    N_NUME_IMME VARCHAR2(5) ,
    N_NUME_OBJE VARCHAR2(5) ,
    etag_list etaglist_t
    Then the data query is (Statement is named Q1):
    SELECT
    obje_t(s_nume_obje, n_nume_obje, n_nume_imme,
    CAST (MULTISET (SELECT S_NUME_OBJE,
                        S_NUME_ETAG,
                        C_TYPE_ETAG,
                        L_DESC_ETAG,
                        N_NOMB_PIEC,
                        N_SURF_TOTA,
                        D_MODI,
                        R_FONC,
                        R_UTIL,
                        C_CODE_LANG
    FROM imm.b12_0 eta
    WHERE eta.s_nume_obje = obj.s_nume_obje)
    AS etaglist_t))
    AS "obj"
    FROM pointi.b02_v obj
    WHERE obj.s_nume_obje= :sNumeObje
    As a result , we get only the <obj> element like this :
    <LIST_Q1>
    <Q1>
    <obj/>
    </Q1>
    </LIST_Q1>
    We tried too :
    SELECT XMLElement("Object",
    obje_t(s_nume_obje, n_nume_obje, n_nume_imme,
    CAST (MULTISET (SELECT S_NUME_OBJE,
                        S_NUME_ETAG,
                        C_TYPE_ETAG,
                        L_DESC_ETAG,
                        N_NOMB_PIEC,
                        N_SURF_TOTA,
                        D_MODI,
                        R_FONC,
                        R_UTIL,
                        C_CODE_LANG
    FROM imm.b12_0 eta
    WHERE eta.s_nume_obje = obj.s_nume_obje)
    AS etaglist_t))
    AS "obj" ) as "objXML"
    FROM pointi.b02_v obj
    WHERE obj.s_nume_obje= :sNumeObje
    And we get :
    <Q1>
    <objXML/>
    </Q1>
    Seems to be not supported isn't it...
    Laurent

    Ok thanks,
    I already checked your blog before to speak about pl/sql tables ;-)
    I think , for maintenance, it will better too , than having a single query with many cast...Multiset , which could have more than 500 lines :-(
    But in our case, as we should have kind of hierarchies in the XML (with levels) and collections, i think we should have a mix :
    store pl/sql tables in a package, that will be reused from the main query, and certainly continue to use cast multiset to manage theses nested collections.
    As you said, i think we could remove the use of Object Types as we do today.

  • Cast multiset

    How does cast multiset work, I have a huge sql whcih is returning one value say p_opp_id ( on the basis of this i need few more coumns) , i was suggested to use cast multiset , what is cast multiset and how it works

    CAST(MULTISET(subquery) AS collection_type) converts the result of a subquery into a collection.
    An example I had lying around:
    CREATE TABLE master (table_name PRIMARY KEY) AS
    SELECT table_name
    FROM   user_tables;
    CREATE TABLE detail AS
    SELECT table_name, column_name, data_type
    FROM   user_tab_columns;
    CREATE OR REPLACE TYPE name_strvalue_ot AS OBJECT
    ( name VARCHAR2(30)
    , value VARCHAR2(50) );
    CREATE OR REPLACE TYPE name_strvalue_tt AS TABLE OF name_strvalue_ot;
    SELECT m.table_name
         , CAST(
           MULTISET
           ( SELECT name_strvalue_ot(d.column_name, d.data_type)
             FROM   detail d
             WHERE  d.table_name = m.table_name
           ) AS name_strvalue_tt) cols
    FROM   master m;
    BEGIN
         FOR r IN
              SELECT m.table_name
                   , CAST(
                     MULTISET
                     ( SELECT name_strvalue_ot(d.column_name, d.data_type)
                       FROM   detail d
                       WHERE  d.table_name = m.table_name
                     ) AS name_strvalue_tt) cols
              FROM   master m
         LOOP
              DBMS_OUTPUT.PUT_LINE(r.table_name || ': ' || r.cols.count || ' columns');
         END LOOP;
    END;
    /

  • Using SQL with Nested Table

    Hi ,
    Please assist as how can we do this thing
    i have a nested table of object type
    create or replace type a1 as object
    a number,
    b varchar2(30),
    region varchar2(30)
    create type a1_array s table of a1;
    declare
    v_a1 a1;
    v_a1_array a1_array:=a1_array();
      begin
    v_a1= a1(1, '1' , 'AUS');
    v_a1_array.EXTEND;
    v_a1_array(1):=v_a1;
    v_a1= a1(2, '2' , 'AUS');
    v_a1_array.EXTEND;
    v_a1_array(2):=v_a1;
    v_a1= a1(3, '3' , 'NAM');
    v_a1_array.EXTEND;
    v_a1_array(3):=v_a1;
      end;
    Now, i have v_a1_array having 3 rows 2 with AUS region and one with NAM region.
    Using SQL can i extract only 'AUS'  rows and fetch in  ARRAY OF TYPE v_a1_array (using Where clause  and Table () functions )
    Any help will be highly appreciated. Please assist. I have oracle 11g
    Thanks

    Hi,
    GPU has already shown you how to do. I will just modify my original one:
    SQL*Plus: Release 11.2.0.1.0 Production on Thu Aug 22 22:14:42 2013
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> set serveroutput on
    SQL>
    SQL> DECLARE
      2     v_a1           a1;
      3     v_a1_array     a1_array := a1_array ();
      4     v_a1_array2    a1_array;
      5  BEGIN
      6     v_a1 := a1 (1, '1', 'AUS');
      7     v_a1_array.EXTEND;
      8     v_a1_array (1) := v_a1;
      9     v_a1 := a1 (2, '2', 'AUS');
    10     v_a1_array.EXTEND;
    11     v_a1_array (2) := v_a1;
    12     v_a1 := a1 (3, '3', 'NAM');
    13     v_a1_array.EXTEND;
    14     v_a1_array (3) := v_a1;
    15
    16     SELECT a1(a, b, region)
    17       BULK COLLECT INTO v_a1_array2
    18       FROM TABLE (v_a1_array)
    19      WHERE region = 'AUS';
    20
    21     FOR c1 IN (SELECT *
    22                  FROM TABLE (v_a1_array2))
    23     LOOP
    24        DBMS_OUTPUT.put_line ('A='||c1.a||', B='||c1.b||', REGION='||c1.region);
    25     END LOOP;
    26  END;
    27  /
    A=1, B=1, REGION=AUS
    A=2, B=2, REGION=AUS
    PL/SQL procedure successfully completed.
    If you consider your question answered, please mark this thread as answered.
    Regards.
    Alberto

  • Unexpected "numeric or value error" when using CAST COLLECT

    I am having trouble with string aggregation using CAST / COLLECT and the to_string function described on various sites around the net including AskTom and http://www.oracle-developer.net/display.php?id=306.
    I am getting "numeric or value error: character string buffer too small" but cannot see which limit I am exceeding.
    I have put together a simple test case to highlight this problem which I have pasted below.
    The error does not seem to be coming from the to_string function itself (else I expect we would see "TO_STRING raised an exception" in the returned error message).
    Any thoughts much appreciated,
    Thanks, Andy
    SQL*Plus: Release 10.1.0.4.2 - Production on Tue Jun 15 09:56:53 2010
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> CREATE TYPE table_of_varchar2 AS TABLE OF VARCHAR2(32000);
      2  /
    Type created.
    SQL> CREATE OR REPLACE FUNCTION to_string (
      2              nt_in IN   table_of_varchar2
      3      ,       delimiter_in    IN VARCHAR2 DEFAULT ',')
      4      RETURN VARCHAR2
      5      IS
      6          l_idx   PLS_INTEGER;
      7          l_str   VARCHAR2(32767);
      8          l_dlm   VARCHAR2(10);
      9
    10      BEGIN
    11
    12          l_idx := nt_in.FIRST;
    13          WHILE l_idx IS NOT NULL LOOP
    14              l_str := l_str || l_dlm || nt_in(l_idx);
    15              l_dlm := delimiter_in;
    16              l_idx := nt_in.NEXT(l_idx);
    17          END LOOP;
    18
    19          RETURN l_str;
    20      EXCEPTION
    21          WHEN OTHERS THEN
    22              raise_application_error(-20000
    23                                  ,   'TO_STRING raised an exception. '||
    24                                      'The reported error was: '||sqlerrm);
    25     END to_string;
    26  /
    Function created.
    SQL> DECLARE
      2      l_longstring varchar2(32000);
      3  BEGIN
      4      SELECT  to_string(CAST( COLLECT( substr(object_name,1,1) ) AS table_of_varchar2 ) )
      5      INTO    l_longstring
      6      FROM    all_objects
      7      WHERE   rownum < 2001;
      8
      9  EXCEPTION
    10      WHEN OTHERS THEN
    11          raise_application_error(-20001
    12                ,   'The anonymous block raised an exception: '||
    13                    sqlerrm||'. '||DBMS_UTILITY.format_error_backtrace);
    14  END;
    15  /
    PL/SQL procedure successfully completed.
    SQL> DECLARE
      2      l_longstring varchar2(32000);
      3  BEGIN
      4      SELECT  to_string(CAST( COLLECT( substr(object_name,1,1) ) AS table_of_varchar2 ) )
      5      INTO    l_longstring
      6      FROM    all_objects
      7      WHERE   rownum < 2002;
      8
      9  EXCEPTION
    10      WHEN OTHERS THEN
    11          raise_application_error(-20001
    12                ,   'The anonymous block raised an exception: '||
    13                    sqlerrm||'. '||DBMS_UTILITY.format_error_backtrace);
    14  END;
    15  /
    DECLARE
    ERROR at line 1:
    ORA-20001: The anonymous block raised an exception: ORA-06502: PL/SQL: numeric
    or value error: character string buffer too small
    ORA-06512: at line 1. ORA-06512: at line 1
    ORA-06512: at line 4
    ORA-06512: at line 11

    Aha, of course.
    I was aware of the 4000 character SQL VARCHAR2 limit but didn't think it would apply here since we are calling a PLSQL function and trying to assign the value it returns into a PLSQL varchar2(32000) variable. BUT... we are of course doing this via a SELECT statement and hence via SQL. Therefore the SQL 4000 limit applies.
    With this in mind, I changed the RETURN type of the to_string function to be CLOB. This solved the problem.
    Thank you,
    Andy

Maybe you are looking for

  • Acrobat 8 Pro keeps giving me a "...has stopped working" popup, but....

    it's still running and working fine. And even when it's not running, nor have I used it in a while, out of nowhere I'll get a popup saying "Adobe Acrobat 8 has stopped working". Intersting. How can it stop working if it isn't running? And when it's o

  • Blank Screen (Raid/BIOS Problem?)

    Have been running a stable setup for several months with the following components: 845 Ultra ARU (PIV 1.6A) Gainward Geoforce III  128 MB 2 - Seagate Barracuda IV Kingston 512MB DDR Enermax EG365P-VE Windows XP All running at default values (i.e. no

  • Re: Forte /FileNet integration

    Hi Jelic, We, at the County of Alameda, are using Forte and FileNet for some time now. As I was not clear on what specific interface issues you are dealing with I thought it is a good idea to decribe what we are doing and hopefully that may answer so

  • Minor Mouse bug in the FP 10.1.52.14 ?

    Hi, It seems that the release version of Flash Player 10.1.52.14 that comes with Flash Builder 4 has minor mouse bug on Mac OS X 10.6.3. Once the cursor changes to 'hand' on hovering, it does NOT return to default arrow on roll out. One a positive si

  • Header conditions calculated on item level.

    Hello, We are on SRM 4.0 (server 500). I have created a header pricing condition as a copy of 01RH for a surcharge. I created a contract with the condidition that a surcharge of ZAR 65 to be added for all orders below ZAR 1000. When I create a shoppi