Using dbms_xmlgen with a CAST statement

The following code populates a plsql collection and then attempts to select from it using dbms_xmlgen.
the following error results --
DECLARE
ERROR at line 1:
ORA-19206: Invalid value for query or REF CURSOR parameter
ORA-06512: at "SYS.DBMS_XMLGEN", line 83
ORA-06512: at line 56
The query is correct as the commented out select at end of block works fine.
Can dbms_xmlgen be used in such a way and if not is there a workaround.
Thanks
DECLARE
types declared on the database
create or replace type bus_tab_obj AS object
( BUSINESS_MODEL_ID NUMBER(10)
,BUSINESS_MODEL_VER_NO NUMBER(5)
,BUSINESS_MODEL_NAME VARCHAR2(30));
create or replace TYPE bus_table AS TABLE of bus_tab_obj;
package level variable bus_table_recs in package get_values_pkg
myxml sys.xmltype;
queryCtx DBMS_XMLGen.ctxhandle;
BEGIN
-- initialise and delete
get_values_pkg.bus_table_recs := bus_table(NULL,NULL,NULL);
get_values_pkg.bus_table_recs.DELETE;
-- select some records to put in the collection
for x in ( select BUSINESS_MODEL_ID
,BUSINESS_MODEL_VER_NO
,BUSINESS_MODEL_NAME
from BRK_BUSINESS_MODEL )
LOOP
get_values_pkg.bus_table_recs.extend;
get_values_pkg.bus_table_recs := bus_table(bus_tab_obj(x.business_model_id
,x.business_model_ver_no
,x.business_model_name));
END LOOP;
-- retrieve the records from the collection as xml
queryCtx := DBMS_XMLGen.newContext('select a.business_model_name data from THE ( select cast( get_values_pkg.bus_table_recs as bus_table ) from dual ) a order by data');
dbms_xmlgen.setMaxRows(queryCtx,1);
myxml := DBMS_XMLGen.getXMLType(queryCtx);
dbms_output.put_line(myxml.extract('/*').getStringVal());
this works!
for x in ( select a.business_model_name data
from THE ( select cast( get_values_pkg.bus_table_recs as bus_table ) from dual ) a
order by data )
loop
dbms_output.put_line( x.data );
end loop;
END;
/

891794 wrote:
Thank you all , see I am new to this database field , I am not a pro.Not a problem. However, one of the very first things you should learn is that dynamic SQL is seldom needed and invariably just plain wrong.
If a table name is dynamic, or a column name is dynamic - then chances are excellent that your data model is already fubar'ed (or malema'ed to put it in a za.org perspective).
And even when you are in the very exceptional situation where dynamic SQL is needed, SQL injection is a MAJOR security concern.. and almost always ignored by implementing shoddy code to create and execute the dynamic SQL.

Similar Messages

  • Creating XML using DBMS_XMLGEN with a namespace

    Is it possible to create an XMLTYPE using the DBMS_XMLGEN function set that contains a namespace. As far as I can see only the 'setrowsettag' function allows any control over what goes into the root element - should I be including, for example, an attribute called 'xmlns' with a value?
    The reason I ask all this is I'm trying to validate xml created from a select statement against a registered xsd.
    The xsd I've registered:
    <?xml version="1.0" encoding="WINDOWS-1252"?>
    <xs:schema targetNamespace="http://www.sepa.org/2007/XMLSchemas/Site" xmlns:sit="http://www.sepa.org/2007/XMLSchemas/Site" elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sepa.org/2007/XMLSchemas/Site Site.xsd" xmlns:oraxdb="http://xmlns.oracle.com/xdb" oraxdb:flags="311" oraxdb:schemaURL="http://www.sepa.org/2007/XMLSchemas/Site.xsd" oraxdb:schemaOwner="XMLDBMASTER" oraxdb:numProps="14">
    <xs:element name="site" oraxdb:propNumber="5953" oraxdb:global="true" oraxdb:SQLName="site" oraxdb:SQLType="site1681_T" oraxdb:SQLSchema="XMLDBMASTER" oraxdb:memType="258" oraxdb:defaultTable="site1683_TAB" oraxdb:defaultTableSchema="XMLDBMASTER">
    <xs:annotation>
    <xs:documentation>Comment describing your root element</xs:documentation>
    </xs:annotation>
    <xs:complexType oraxdb:SQLType="site1681_T" oraxdb:SQLSchema="XMLDBMASTER">
    <xs:sequence>
    <xs:element name="SiteIDType" type="xs:ID" oraxdb:propNumber="5940" oraxdb:global="false" oraxdb:SQLName="SiteIDType" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
    <xs:element name="SiteNameType" type="xs:string" minOccurs="1" oraxdb:propNumber="5941" oraxdb:global="false" oraxdb:SQLName="SiteNameType" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
    <xs:element name="SiteAddressStructure" oraxdb:propNumber="5947" oraxdb:global="false" oraxdb:SQLName="SiteAddressStructure" oraxdb:SQLType="SiteAddressStructure1682_T" oraxdb:SQLSchema="XMLDBMASTER" oraxdb:memType="258" oraxdb:SQLInline="true" oraxdb:MemInline="false" oraxdb:JavaInline="false">
    <xs:complexType oraxdb:SQLType="SiteAddressStructure1682_T" oraxdb:SQLSchema="XMLDBMASTER">
    <xs:sequence>
    <xs:element name="AddressLine1" type="xs:string" minOccurs="1" oraxdb:propNumber="5942" oraxdb:global="false" oraxdb:SQLName="AddressLine1" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
    <xs:element name="AddressLine2" type="xs:string" minOccurs="0" oraxdb:propNumber="5943" oraxdb:global="false" oraxdb:SQLName="AddressLine2" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
    <xs:element name="AddressLine3" type="xs:string" minOccurs="0" oraxdb:propNumber="5944" oraxdb:global="false" oraxdb:SQLName="AddressLine3" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
    <xs:element name="AddressLine4" type="xs:string" minOccurs="1" oraxdb:propNumber="5945" oraxdb:global="false" oraxdb:SQLName="AddressLine4" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
    <xs:element name="PostCode" type="xs:string" minOccurs="0" oraxdb:propNumber="5946" oraxdb:global="false" oraxdb:SQLName="PostCode" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:element name="SiteTelephoneNoType" type="xs:string" minOccurs="0" oraxdb:propNumber="5948" oraxdb:global="false" oraxdb:SQLName="SiteTelephoneNoType" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
    <xs:element name="SiteMobilePlantType" type="xs:string" minOccurs="0" oraxdb:propNumber="5949" oraxdb:global="false" oraxdb:SQLName="SiteMobilePlantType" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
    <xs:element name="SiteFaxNoType" type="xs:string" minOccurs="0" oraxdb:propNumber="5950" oraxdb:global="false" oraxdb:SQLName="SiteFaxNoType" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
    <!--***Location code must reference the code in the Location Dataset***-->
    <xs:element name="SiteLocationCode" type="xs:string" minOccurs="1" oraxdb:propNumber="5951" oraxdb:global="false" oraxdb:SQLName="SiteLocationCode" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
    <xs:element name="SitePopulationEquivType" type="xs:positiveInteger" minOccurs="0" oraxdb:propNumber="5952" oraxdb:global="false" oraxdb:SQLName="SitePopulationEquivType" oraxdb:SQLType="NUMBER" oraxdb:memType="2" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    The method for generating the XML:
    DECLARE
    v_ctx DBMS_XMLGEN.ctxhandle;
    v_xml XMLTYPE;
    BEGIN
    v_ctx:=DBMS_XMLGEN.newcontext
    SELECT e.site_id "SiteIDType", e.site_name "SiteNameType", sit_address(e.addr_line1, e.addr_line2,
    e.addr_line3, e.addr_line4, e.post_code) AS "SiteAddressStructure", e.tel_no "SiteTelephoneNoType"
    , e.mobile_plant "SiteMobilePlantType",
    e.fax_no "SiteFaxNoType", e.ge1_location_code "SiteLocationCodeType" ,e.population_equivalent "SitePopulationEquivType"
    FROM EL03_SITES e
    WHERE e.site_id = 15'
    DBMS_XMLGEN.setrowsettag (v_ctx, 'site');
    DBMS_XMLGEN.setrowtag (v_ctx, NULL);
    v_xml := DBMS_XMLGEN.getxmltype (v_ctx);
    INSERT INTO js_xml_test
    (ID, xml_data
    VALUES ('site test', v_xml
    COMMIT;
    DBMS_XMLGEN.closecontext (v_ctx);
    END;
    The resulting XML:
    <site>
    <SiteIDType>15</SiteIDType>
    <SiteNameType>Finlas Water Treatment Works</SiteNameType>
    <SiteAddressStructure>
    <AddressLine1>Finlas Water Treatment Works</AddressLine1>
    <AddressLine2>Shermor Farm</AddressLine2>
    <AddressLine3>Luss</AddressLine3>
    <AddressLine4>Alexandria</AddressLine4>
    <PostCode>G83 8RH</PostCode>
    </SiteAddressStructure>
    <SiteTelephoneNoType>01389 850224</SiteTelephoneNoType>
    <SiteMobilePlantType>N</SiteMobilePlantType>
    <SiteLocationCodeType>123428</SiteLocationCodeType>
    </site>
    When I try to validate it, I get:
    ORA-30937: No schema definition for 'site' (namespace '') in parent '/'
    ORA-06512: at "SYS.XMLTYPE", line 345
    ORA-06512: at line 30
    How do I get a namespace declaration in the XML? Any suggestions gratefully received.

    Did you change any of the text in the lob write statements ?
    I believe you get this error if you increase the number of characters without increasing the 1st argument which looks as though it represents the number of characters

  • How to get UTF-8 encoding when create XML using DBMS_XMLGEN and UTL_FILE ?

    How to get UTF-8 encoding when create XML using DBMS_XMLGEN and UTL_FILE ?
    Hi,
    I do generate XML-Files by using DBMS_XMLGEN with output by UTL_FILE
    but it seems, the xml-Datafile I get on end is not really UTF-8 encoding
    ( f.ex. cannot verifying it correct in xmlspy )
    my dbms is
    NLS_CHARACTERSET          = WE8MSWIN1252
    NLS_NCHAR_CHARACTERSET     = AL16UTF16
    NLS_RDBMS_VERSION     = 10.2.0.1.0
    I do generate it in this matter :
    declare
    xmldoc CLOB;
    ctx number ;
    utl_file.file_type;
    begin
    -- generate fom xml-view :
    ctx := DBMS_XMLGEN.newContext('select xml from xml_View');
    DBMS_XMLGEN.setRowSetTag(ctx, null);
    DBMS_XMLGEN.setRowTag(ctx, null );
    DBMS_XMLGEN.SETCONVERTSPECIALCHARS(ctx,TRUE);
    -- create xml-file:
    xmldoc := DBMS_XMLGEN.getXML(ctx);
    -- put data to host-file:
    vblob_len := DBMS_LOB.getlength(xmldoc);
    DBMS_LOB.READ (xmldoc, vblob_len, 1, vBuffer);
    bHandle := utl_file.fopen(vPATH,vFileName,'W',32767);
    UTL_FILE.put_line(bHandle, vbuffer, FALSE);
    UTL_FILE.fclose(bHandle);
    end ;
    maybe while work UTL_FILE there is a change the encoding ?
    How can this solved ?
    Thank you
    Norbert
    Edited by: astramare on Feb 11, 2009 12:39 PM with database charsets

    Marco,
    I tryed to work with dbms_xslprocessor.clob2file,
    that works good,
    but what is in this matter with encoding UTF-8 ?
    in my understandig, the xmltyp created should be UTF8 (16),
    but when open the xml-file in xmlSpy as UTF-8,
    it is not well ( german caracter like Ä, Ö .. ):
    my dbms is
    NLS_CHARACTERSET = WE8MSWIN1252
    NLS_NCHAR_CHARACTERSET = AL16UTF16
    NLS_RDBMS_VERSION = 10.2.0.1.0
    -- test:
    create table nh_test ( s0 number, s1 varchar2(20) ) ;
    insert into nh_test (select 1,'hallo' from dual );
    insert into nh_test (select 2,'straße' from dual );
    insert into nh_test (select 3,'mäckie' from dual );
    insert into nh_test (select 4,'euro_€' from dual );
    commit;
    select * from nh_test ;
    S0     S1
    1     hallo
    1     hallo
    2     straße
    3     mäckie
    4     euro_€
    declare
    rc sys_refcursor;
    begin
    open rc FOR SELECT * FROM ( SELECT s0,s1 from nh_test );
    dbms_xslprocessor.clob2file( xmltype( rc ).getclobval( ) , 'XML_EXPORT_DIR','my_xml_file.xml');
    end;
    ( its the same when using output with DBMS_XMLDOM.WRITETOFILE )
    open in xmlSpy is:
    <?xml version="1.0"?>
    <ROWSET>
    <ROW>
    <S0>1</S0>
    <S1>hallo</S1>
    </ROW>
    <ROW>
    <S0>2</S0>
    <S1>straޥ</S1>
    </ROW>
    <ROW>
    <S0>3</S0>
    <S1>m㢫ie</S1>
    </ROW>
    <ROW>
    <S0>4</S0>
    <S1>euro_€</S1>
    </ROW>
    </ROWSET>
    regards
    Norbert

  • Is it possible to use e.getsource with a switch statement?

    Is it possible to use e.getsource for a switch statement? I keep getting an error, which I understand. I'm just not sure if it can be done by using another method or casting e.getsource to something. Any ideas? Thanks!
         public void actionPerformed(ActionEvent e)
              switch(e.getSource())
                   //buttons 0 - 6
                   case buttons[0]:
                        Master_Clock.tickPos();
                        break;
                   case buttons[1]:
                        Master_Clock.tockPos();
                        break;
                   case buttons[2]:
                        Master_Clock.reset();
                        break;
                   case buttons[3]:
                        Master_Clock.tickNeg();
                        break;
                   case buttons[4]:
                        Master_Clock.tockNeg();
                        break;
                   case buttons[5]:
                        Master_Clock.dayPos();
                        break;
            }

    Using the same actionPerformed method for all the buttons is an obsolete technique.
    Use a seperate object implementing ActionListener with each button.
    There's a lot to be said for using Action objects, which you can also connect to key presses menu items and so on.
    Typically you create objects using the anonymous class technique. You'd do something like:
    Action tickAction = new AbstractAction("Tick") { // create anonymous action
       public void actionPerformed(ActionEvent e) {
          MasterClock.tickPos();
    JButton tickButton = new JButton(tickAction);

  • I have an iMac and have been using Adobe reader successfully for sometime. Recently, however, whenever I go to sign a document on Adobe reader The document closes unexpectedly with an error statement. I have already uninstalled and reinstalled Adobe reade

    I have an iMac and have been using Adobe reader successfully for sometime. Recently, however, whenever I go to sign a document on Adobe reader The document closes unexpectedly with an error statement. I have already uninstalled and reinstalled Adobe reader with no improvement. What do I do next?

    Please post the full error message, plus OS and Reader versions.

  • Problem Using Multiple With Statements

    I'm having a problem using multiple WITH statements. Oracle seems to be expecting a SELECT statement after the first one. I need two in order to reference stuff from the second one in another query.
    Here's my code:
    <code>
    WITH calculate_terms AS (SELECT robinst_current_term_code,
    CASE
    WHEN robinst_current_term_code LIKE '%60' THEN robinst_current_term_code - '40'
    WHEN robinst_current_term_code LIKE '%20' THEN robinst_current_term_code - '100'
    END first_term,
    CASE
    WHEN robinst_current_term_code LIKE '%60' THEN robinst_current_term_code - '100'
    WHEN robinst_current_term_code LIKE '%20' THEN robinst_current_term_code - '160'
    END second_term
    FROM robinst
    WHERE robinst_aidy_code = :aidy)
    /*Use terms from calculate_terms to generate attendance periods*/
    WITH gen_attn_terms AS
    SELECT
    CASE
    WHEN first_term LIKE '%60' THEN 'Fall '||substr(first_term,0,4)
    WHEN first_term LIKE '%20' THEN 'Spring '||substr(first_term,0,4)
    END first_attn_period,
    CASE
    WHEN second_term LIKE '%60' THEN 'Fall '||substr(second_term,0,4)
    WHEN second_term LIKE '%20' THEN 'Spring '||substr(second_term,0,4)
    END second_attn_period
    FROM calculate_terms
    SELECT *
    FROM gen_attn_terms
    <code>
    I get ORA-00928: missing SELECT keyword error. What could be the problem?

    You can just separate them with a comma:
    WITH calculate_terms AS (SELECT robinst_current_term_code,
    CASE
    WHEN robinst_current_term_code LIKE '%60' THEN robinst_current_term_code - '40'
    WHEN robinst_current_term_code LIKE '%20' THEN robinst_current_term_code - '100'
    END first_term,
    CASE
    WHEN robinst_current_term_code LIKE '%60' THEN robinst_current_term_code - '100'
    WHEN robinst_current_term_code LIKE '%20' THEN robinst_current_term_code - '160'
    END second_term
    FROM robinst
    WHERE robinst_aidy_code = :aidy),
    /*Use terms from calculate_terms to generate attendance periods*/
    gen_attn_terms AS
    SELECT
    CASE
    WHEN first_term LIKE '%60' THEN 'Fall '||substr(first_term,0,4)
    WHEN first_term LIKE '%20' THEN 'Spring '||substr(first_term,0,4)
    END first_attn_period,
    CASE
    WHEN second_term LIKE '%60' THEN 'Fall '||substr(second_term,0,4)
    WHEN second_term LIKE '%20' THEN 'Spring '||substr(second_term,0,4)
    END second_attn_period
    FROM calculate_terms
    )Not tested because there are no scripts.

  • How to use the pid vis with a two-state output

    Hello
    Could someone tell me how to regulate the temperature of a room with
    a two-state heater (on/off), using the pid vi's.
    Thanks,

    >> Could someone tell me how to regulate the temperature of a room
    >> with a two-state heater (on/off), using the pid vi's.
    In <[email protected]> [email protected] (Helmut Hullen) writes:
    >You don't need the PID. A simple 2-state control does the work.
    ^^^^^^ ^^^^^^^ ^^^^^^^
    Frankly, I tend to agree. However, if you _need_ PID control and _if_
    your two-state heater is solid-state switched, there are other
    options. For example, commerical PID temperature controllers with
    zero-voltage switching (ZVS) operate by generating a slow enabling
    pulse, then achieving proportional control by varying the duty cycle of
    this enabling pulse. For instanance, if your enabling pulse is running
    at 10-Hz, with 50% duty cycle,
    then your heating element will be on for
    50% of the time every 0.1 second.
    You can use a programmable timer (National includes two on their MIO
    cards) to program the 5 or 10 Hz output and its duty cycle. You might
    have LabView execute the PID subVI once every two or three seconds to
    adjust the duty cycle on the programmable timer so as to minimize the
    feedback error=(tempSetPoint-currentTemp).
    Why are you wanting to use LabView for PID temperature control in the
    first place? There are some very good PID temperature controllers
    (programmable through a serial port) with built-in solid-state ZVSs
    and readouts for $900 that you can buy. They'll fit right into
    a control panel, display and all. Sure beats messing with a
    programmable timer card and its outputs, plus you get a digital panel
    readout to boot.
    /\ Mark M Mehl, alias Superticker (Supertickler to some)
    <><> Internet: [email protected]
    \/ Preferred UUCP: uunet!iastate.edu!mehl
    Disclaimer: You got to be kidding; who would w
    ant to claim anything I said?

  • HT1918 hi, i used to live in the states, since 7 years ago came back to my country Ecuador, I wuold like to change my payment info but since I have $0.08 cents in my account I cannot proceed with the changes..please help.

    hi there, i need help with my itunes acrcount, i used to live in the States but I cambe back yo my country seven years ago (ecuador).  Now i would like to change my account info but I can't, because I have $0.08 cents and i need to clear that balance to chance my info payment...but there's nothing i can but for $0.08 cents and obviously I don't have a credit card with a Unite States address please help meeeee!!!

    Try contacting iTunes support and see if they can remove the balance from your account : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page

  • HT204032 Why can you not use powernap with a custom order iMac with solid state?

    Why can you not use powernap with a custom order iMac with solid state?
    Find it quite ridiculous that a 3 year old mba supports it and not a new iMac

    Agreed.  Why wouldn't you want your Photostream updated while your iMac is sleeping?  I am bummed about this.

  • Greetings, I'm having trouble with my iMouse continually disconnecting from my MacBook Pro in Mavericks.  The batteries are solid.  I just eliminated the bluetooth for my headphone.  I have used the mac to cast on my TV.  I use bluetooth.  ANy ideas?

    Greetings, I'm having trouble with my iMouse continually disconnecting from my MacBook Pro in Mavericks.  The batteries are solid.  I just eliminated the bluetooth for my headphone.  I have used the mac to cast on my TV.  I use bluetooth.  ANy ideas?

    Hi clemenbw,
    Welcome to the Apple Support Communities!
    In your situation, I would recommend reading over the attached article to help you troubleshoot your Magic Mouse Bluetooth connectivity issues. 
    Troubleshooting wireless mouse and keyboard issues
    Have a great day,
    Joe

  • Is there going to be a firmware upgrade for mountain lion customers that have a Macbook with a soild state drive so we can use the Power Nap feature?

    Is there going to be a firmware upgrade for mountain lion customers that have a Macbook with a soild state drive so we can use the Power Nap feature?

    here: http://www.apple.com/osx/whats-new/
    "Power Nap requires a Mac notebook with built-in flash storage. May require a firmware update."
    We have to wait for the Firmware-Updates. Some are already here: http://support.apple.com/kb/HT5394
    And I am shure, that you will need for Power Nap one of the newer Macs with SSD from 2011 and 2012.

  • Formatting XML using DBMS_XMLGEN

    Hi.
    Having Problems with generating XML out of a query using nested table types
    -- Heres a test case
    drop type test_tab
    drop type test_type
    drop type sub_type_tab
    drop type sub_type
    create or replace type sub_type as object ( "@a" varchar2(10), "@b" varchar2(10) );
    create or replace type sub_type_tab as table of sub_type;
    create or replace type test_type as object ( "@c" VARCHAR2(10), test sub_type_tab );
    CREATE OR REPLACE TYPE test_tab AS TABLE OF test_type;
    CREATE OR REPLACE VIEW test_view OF test_type
    WITH OBJECT IDENTIFIER ("@c")
    AS
    SELECT
    'C',
    CAST(MULTISET(SELECT 'A', 'B' FROM DUAL) AS sub_type_tab)
    FROM dual
    The resultant XML out of DBMS_XMLGEN.GETXML is :
    <?xml version="1.0"?>
    <ROWSET>
    <ROW c = "C">
    <TEST>
    <SUB_TYPE a="A" b="B"/>
    </TEST>
    </ROW>
    </ROWSET>
    As you can see as a consequence of the column collection type alias in the view
    i have an extraneous <TEST> tag.
    Does anyone know how I can remove this tag entry?
    Thanks in advance

    Marco,
    I tryed to work with dbms_xslprocessor.clob2file,
    that works good,
    but what is in this matter with encoding UTF-8 ?
    in my understandig, the xmltyp created should be UTF8 (16),
    but when open the xml-file in xmlSpy as UTF-8,
    it is not well ( german caracter like Ä, Ö .. ):
    my dbms is
    NLS_CHARACTERSET = WE8MSWIN1252
    NLS_NCHAR_CHARACTERSET = AL16UTF16
    NLS_RDBMS_VERSION = 10.2.0.1.0
    -- test:
    create table nh_test ( s0 number, s1 varchar2(20) ) ;
    insert into nh_test (select 1,'hallo' from dual );
    insert into nh_test (select 2,'straße' from dual );
    insert into nh_test (select 3,'mäckie' from dual );
    insert into nh_test (select 4,'euro_€' from dual );
    commit;
    select * from nh_test ;
    S0     S1
    1     hallo
    1     hallo
    2     straße
    3     mäckie
    4     euro_€
    declare
    rc sys_refcursor;
    begin
    open rc FOR SELECT * FROM ( SELECT s0,s1 from nh_test );
    dbms_xslprocessor.clob2file( xmltype( rc ).getclobval( ) , 'XML_EXPORT_DIR','my_xml_file.xml');
    end;
    ( its the same when using output with DBMS_XMLDOM.WRITETOFILE )
    open in xmlSpy is:
    <?xml version="1.0"?>
    <ROWSET>
    <ROW>
    <S0>1</S0>
    <S1>hallo</S1>
    </ROW>
    <ROW>
    <S0>2</S0>
    <S1>straޥ</S1>
    </ROW>
    <ROW>
    <S0>3</S0>
    <S1>m㢫ie</S1>
    </ROW>
    <ROW>
    <S0>4</S0>
    <S1>euro_€</S1>
    </ROW>
    </ROWSET>
    regards
    Norbert

  • Use NEXTVAL in an insert statement Part II

    db - 10g
    I am asking this question out of curiosity.
    I posted a question and recieved a successful answer at the following address on this forum;
    Use NEXTVAL in an insert statement
    The following insert statement uses a sequence to create an arbitrary number for each null record. The problem is, the sequence is firing regardless of the condition being true or false (but it is working in that it only inserts values when the condition is true). The result is the sequence appears to increment each time it loops through the cursor and so the first arbitrary number to be inserted is not 1001 but some other higher number.
    INSERT INTO psp_trees
    ( plot_id
    , tree_name
    , species_code)
    VALUES
    ( get_plot_id
    , c1.treenum          
    , c1.species
    ) RETURNING tree_id INTO get_tree_id;   I have gotten around the issue by removing the sequence from the insert statement and placing it outside the cursor loop as an update statement.
          UPDATE psp_trees
             SET tree_name = to_char(tree_arbitrary_name_seq.nextval)
           WHERE tree_name IS NULL;Is there anyway to get the sequence to only fire in the insert statement when the condition is true.
    This is the complete anonymous block for your reference;
    DECLARE p_access_num NUMBER;
    col_access_var VARCHAR2(30);
    type number_ptb IS table OF VARCHAR2(4000);
    p_access_nam number_ptb;
    get_plot_measurement_id NUMBER;
    update_plot_measurements VARCHAR2(4000);
    get_tree_id NUMBER;
    get_plot_id NUMBER;
    BEGIN
        p_access_num := 6;
        p_access_nam := number_ptb();
        p_access_nam.extend(7);
        p_access_nam(1) := 535;
        p_access_nam(2) := 548;
        p_access_nam(3) := 898;
        p_access_nam(4) := 544;
        p_access_nam(5) := 551;
        p_access_nam(6) := 724;
        FOR loop_int IN 1 .. p_access_num
        LOOP
          col_access_var := p_access_nam(loop_int);
          -- 1. Initiate insert process by getting PK from psp_plots.
          SELECT plot_id INTO get_plot_id FROM psp_plots WHERE plot_name = col_access_var;    
          -- 2. Insert records into psp_plot_measurements and keep relationship with psp_plots with variable get_plot_id.
          --    and get primary key value of psp_plot_measurements to insert into psp_tree_measurements during loop process.
          INSERT INTO psp_plot_measurements (plot_id) VALUES (get_plot_id) RETURNING plot_measurement_id INTO get_plot_measurement_id;   
          -- 3. Update record created at point 2.
          UPDATE psp_plot_measurements
             SET measurement_date    = (SELECT DISTINCT date_ FROM pspdata)
               , codominant_height   = (SELECT DISTINCT height_codom FROM pspdata)
               , assessor            = (SELECT DISTINCT assessor FROM pspdata)
           WHERE plot_measurement_id = col_access_var
          -- 4. Open cursor to insert rows one at a time and maintain relationships between related tables.
          FOR c1 IN (SELECT treenum
                          , dbhob
                          , treecomments
                          , species
                       FROM pspdata
                      WHERE plotnumber = col_access_var
                        AND date_ IS NOT NULL)     
              LOOP   
                -- 5. Insert record into psp_trees
                --    and get primary key value of psp_trees to insert into psp_tree_measurements.
                INSERT INTO psp_trees
                ( plot_id
                , tree_name
                , species_code)
                VALUES
                ( get_plot_id
                , c1.treenum
                --, NVL(c1.treenum , to_char(tree_arbitrary_name_seq.nextval))
                --, (CASE WHEN c1.treenum IS NULL THEN to_char(tree_arbitrary_name_seq.nextval) ELSE c1.treenum END)
                , c1.species
                ) RETURNING tree_id INTO get_tree_id;   
                -- 6. Insert records into psp_tree_measurements and keep relationship with psp_trees with variable get_tree_id.
                INSERT INTO psp_tree_measurements
                ( plot_measurement_id
                , tree_id
                , dbhob          
                , comments
                VALUES
                ( get_plot_measurement_id
                , get_tree_id
                , c1.dbhob
                , c1.comment
              END LOOP;         
      END LOOP; 
          -- 7. Update null columns with arbitrary number.
          UPDATE psp_trees
             SET tree_name = to_char(tree_arbitrary_name_seq.nextval)
           WHERE tree_name IS NULL;
    END;
    /Edited by: benton on Sep 6, 2011 1:53 PM

    Or use a function (I'll use dbms_xml.getxml):
    SQL> create sequence s_seq nocache
    Sequence created.
    SQL> select case when mod (level, 2) = 0
                then extractvalue(dbms_xmlgen.getxmltype('select s_seq.nextval from dual'), '//text()')
                else '0' end col1
              from dual connect by level < 20
    COL1                                                                           
    0                                                                              
    1                                                                              
    0                                                                              
    2                                                                              
    0                                                                              
    3                                                                              
    0                                                                              
    4                                                                              
    0                                                                              
    5                                                                              
    0                                                                              
    6                                                                              
    0                                                                              
    7                                                                              
    0                                                                              
    8                                                                              
    0                                                                              
    9                                                                              
    0                                                                              
    19 rows selected.
    SQL> select sequence_name, last_number from user_sequences where sequence_name = 'S_SEQ'
    SEQUENCE_NAME                  LAST_NUMBER
    S_SEQ                                   10
    1 row selected.

  • How much do CAST statements affect performance?

    I have an 800+ line SELECT that I am tuning before using it as the source in an SSIS package. I have reduced the original time it took from around 19 minutes down to just under 2 minutes and now I'm running out of ideas.
    My last gain was a 30 second reduction by removing all UDF calls.
    There are a large number of CAST statements as my source data needs to be converted for the target table (such as casting decimal as money, varchar as nvarchar, etc.).
    Is this likely to have any significant impact on the performance of my statement or not enough to bother about? Maybe using the SSIS convert option would be more efficient?
    In some places I have CAST(0 as money). Would it be quicker to define a variable as money with value zero and assign that?
    Nick Ryan SQL Server Developer OnePath (NZ) Ltd

    There are a large number of CAST statements as my source data needs to be converted for the target table (such as casting decimal as money, varchar as nvarchar, etc.).
    Is this likely to have any significant impact on the performance of my statement or not enough to bother about? Maybe using the SSIS convert option would be more efficient?
    In some places I have CAST(0 as money). Would it be quicker to define a variable as money with value zero and assign that?
    Nick Ryan SQL Server Developer OnePath (NZ) Ltd
    As a general rule, doing CASTs or CONVERTs on items in your SELECT clause cost almost nothing.  (Note that CASTs or CONVERTs in WHERE or ON clauses can be very expensive since they will keep SQL Server from making effective use of indexes). 
    The reason is it's not expensive in the SELECT clause that most SQL commands take almost all their time doing disk I/O.  But doing the CASTs in a SELECT clause is almost entirely CPU.  And since the CPU is so much faster than the I/O system, the
    CASTs don't add much if any time since the CASTs on one group of rows can be done while the I/O system is retrieving the next group of rows and the CPU will finish before the I/O system and then just be sitting there waiting.  As always, there are exceptions
    and your mileage may vary.  For example, you might have a server that is already CPU bound for other reasons.
    As a test, I ran the following code against a Numbers table that I have that has a bigint column and contains 1,048,575 rows with the numbers from 1 to 1,048,575.
    Declare @StartTime datetime2;
    Declare @EndTime datetime2;
    DBCC FreeProcCache
    DBCC DropCleanBuffers
    set @StartTime = GETDATE()
    select sum(Number) From dbo.Numbers
    set @EndTime = GETDATE()
    select DateDiff(ms, @StartTime, @EndTime) As 'No Convert'
    DBCC FreeProcCache
    DBCC DropCleanBuffers
    set @StartTime = GETDATE()
    select sum(len(Cast(Number As nvarchar(20)))) From dbo.Numbers
    set @EndTime = GETDATE()
    select DateDiff(ms, @StartTime, @EndTime) As 'With Convert'
    As you can see, in one case, I just summed the numbers, in the second, I converted the number, found the length and summed the lengths.  I ran it several times, sometimes the first one was faster, sometimes the second.  They were always within
    less than 0.1 seconds of each other.  So the extra function calls on 1,000,000 rows essentially cost nothing.
    And I definitely would not worry about CAST(0 AS money).  SQL is smart enough to figure out that that is just a money constant.  So it will just create a constant value of 0 of type money and use that.  It will not do that cast for every row.
    Tom

  • How do I use user_datastore with a feeder proc to add an mdata section?

    Hi,
    I have text data spread across a number of different tables. I have created a user_datastore with a feeder procedure that creates an xml document which is then indexed into a dummy column on the parent table. This works fine. However I need to add an mdata section to the index, via my xml document. I haven't seen any examples of this being done in conjunction with the ctxsys.auto_section_group option of the create index statement, and am wondering if it is possible?
    Could somebody furnish me an example of how I achieve this.
    Oracle 11.2.
    Thanks
    Ralph

    You can't use MDATA with AUTO_SECTION_GROUP. AUTO means it automatically assigns zone sections for every tag it finds - if you want anything other than zone sections you must use BASIC_SECTION_GROUP, XML_SECTION_GROUP or HTML_SECTION_GROUP and manually define your sections.

Maybe you are looking for