Load a table in a PL/SQL variable

Hi!
I'm using Oracle 8i and I'm interested in load a table from my database in a PL/SQL variable.In addition,I'm using Nested Table Type for loading a database table in a variable.When I load the table in the variable, I try doing a SQL query to the variable (is a nested table) but it doesn't work.There is some solution?
In the following lines there is an example about what I'm trying:
PACKAGE Types AS
TYPE cursor_type IS REF CURSOR;
END Types;
CREATE TABLE EXAMPLE(
ID NUMBER(4),
VAL Number(3)
CREATE or replace TYPE My_Row_Type AS OBJECT
ID NUMBER(4),
NStreet Number(3)
CREATE OR REPLACE PACKAGE PROVA AS
TYPE My_Tab_Type IS TABLE OF My_Row_Type;
PROCEDURE GetEXAMPLE (p_recordset OUT types.cursor_type);
END PROVA;
CREATE OR REPLACE PACKAGE BODY PROVA AS
PROCEDURE GetEXAMPLE (p_recordset OUT types.cursor_type) AS
v_tab My_Tab_Type := My_Tab_Type();
BEGIN
FOR cur_row IN (SELECT * FROM EXAMPLE) LOOP
v_tab.extend;
v_tab(v_tab.Last) := My_Row_Type(cur_row.ID,     cur_row.NStreet);
END LOOP;
-- Open REF CURSOR for outout.
OPEN p_recordset FOR
SELECT *
FROM Table(Cast(v_tab As My_Tab_Type));
END GetEXAMPLE ;
END PROVA;
When I execute the procedure GetEXAMPLE, Oracle shows me the following error:
ERROR en línea 1:
ORA-00600: código de error interno, argumentos: [15419], [severe error during
PL/SQL execution], [], [], [], [], [], []
ORA-06544: PL/SQL: error interno, argumentos: [pfrrun.c:pfrbnd1()], [], [], [],
ORA-06553: PLS-801: error interno [0]

Create your My_Tab_Type as a SQL Object Type, instead of a PL/SQL Table Type:
SQL> CREATE TABLE example
  2    (id     NUMBER (4),
  3       nstreet NUMBER (3))
  4  /
Table created.
SQL> INSERT INTO example VALUES (1234, 123)
  2  /
1 row created.
SQL> INSERT INTO example VALUES (2345, 234)
  2  /
1 row created.
SQL> COMMIT
  2  /
Commit complete.
SQL> CREATE OR REPLACE TYPE My_Row_Type AS OBJECT
  2    (id     NUMBER (4),
  3       nstreet NUMBER (3));
  4  /
Type created.
SQL> CREATE OR REPLACE TYPE My_Tab_Type AS TABLE OF My_Row_Type;
  2  /
Type created.
SQL> CREATE OR REPLACE PACKAGE types
  2  AS
  3    TYPE cursor_type IS REF CURSOR;
  4  END types;
  5  /
Package created.
SQL> CREATE OR REPLACE PACKAGE prova
  2  AS
  3    PROCEDURE GetExample
  4        (p_recordset OUT types.cursor_type);
  5  END prova;
  6  /
Package created.
SQL> SHOW ERRORS
No errors.
SQL> CREATE OR REPLACE PACKAGE BODY prova
  2  AS
  3    PROCEDURE GetExample
  4        (p_recordset OUT types.cursor_type)
  5    AS
  6        v_tab My_Tab_Type := My_Tab_Type();
  7    BEGIN
  8        FOR cur_row IN (SELECT * FROM example) LOOP
  9          v_tab.EXTEND;
10          v_tab(v_tab.LAST) := My_Row_Type(cur_row.id, cur_row.nstreet);
11        END LOOP;
12        -- Open REF CURSOR for output.
13        OPEN p_recordset FOR
14        SELECT *
15        FROM TABLE(CAST(v_tab AS My_Tab_Type));
16    END GetExample;
17  END prova;
18  /
Package body created.
SQL> SHOW ERRORS
No errors.
SQL> VARIABLE g_ref REFCURSOR
SQL> EXEC prova.GetExample (:g_ref)
PL/SQL procedure successfully completed.
SQL> PRINT g_ref
        ID    NSTREET                                                          
      1234        123                                                          
      2345        234                                                          
2 rows selected.

Similar Messages

  • How can I load a .xlsx File into a SQL Server Table using a Foreach Loop Container in SSIS?

    I know I've REALLY struggled with this before. I just don't understand why this has to be soooooo difficult.
    I can very easily do a straight Data Pump of a .xlsX File into a SQL Server Table using a normal Excel Connection and a normal Excel Source...simply converting Unicode to DT_STR and then using an OLE DB Destination of the SQL Server Table.
    If I want to make the SSIS Package a little more flexible by allowing multiple .xlsX spreadsheets to be pumped in by using a Foreach Loop Container, the whole SSIS Package seems to go to hell in a hand basket. I simply do the following...
    Put the Data Flow Task within the Foreach Loop Container
    Add the Variable Mapping Variable User::FilePath that I defined as a Variable and a string within the FOreach Loop Container
    I change the Excel Connection and its Expression to be ExcelFilePath ==> @[User::FilePath]
    I then try and change the Excel Source and its Data Access Mode to Table Name or view name variable and provide the Variable Name User::FilePath
    And that's when I run into trouble...
    Exception from HRESULT: 0xC02020E8
    Error at Data Flow Task [Excel Source [56]]:SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occured. Error code: 0x80004005.
    Error at Data Flow Task [Excel Source [56]]: Opening a rowset for "...(the EXACT Path and .xlsx File Name)...". Check that the object exists in the database. (And I know it's there!!!)
    I don't understand by adding a Foreach Loop Container to try and make this as efficient as possible has caused such an error unless I'm overlooking something. I have even tried delaying my validations and that doesn't seem to help.
    I have looked hard in Google and even YouTube to try and find a solution for this but for the life of me I cannot seem to find anything on pumping a .xlsX file into SQL Server using a Foreach Loop Container.
    Can ANYONE please help me out here? I'm at the end of my rope trying to get this to work. I think the last time I was in this quandry, trying to pump a .xlsX File into a SQL Server Table using a Foreach Loop Container in SSIS, I actually wrote a C# Script
    to write the contents of the .xlsX File into a .csv File and then Actually used the .csv File to pump the data into a SQL Server Table.
    Thanks for your review and am hoping and praying for a reply and solution.

    Hi ITBobbyP,
    If I understand correctly, you want to load data from multiple sheets in an .xlsx file into a SQL Server table.
    If in this scenario, please refer to the following tips:
    The Foreach Loop container should be configured as shown below:
    Enumerator: Foreach ADO.NET Schema Rowset Enumerator
    Connection String: The OLE DB Connection String for the excel file.
    Schema: Tables.
    In the Variable Mapping, map the variable to Sheet_Name, and change the Index from 0 to 2.
    The connection string for Excel Connection Manager is the original one, we needn’t make any change.
    Change Table Name or View name to the variable Sheet_Name.
    If you want to load data from multiple sheets in multiple .xlsx files into a SQL Server table, please refer to following thread:
    http://stackoverflow.com/questions/7411741/how-to-loop-through-excel-files-and-load-them-into-a-database-using-ssis-package
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Loading multiple tables with SQL Loader

    Hi,
    I want to load multiple tables from a single data file using SQL Loader.
    Here's the basic idea of what I want. Let's say I have two tables, table =T1
    and table T2:
    SQL> desc T1;
    COL1 VARCHAR2(20)
    COL2 VARCHAR2(20)
    SQL> desc T2;
    COL1 VARCHAR2(20)
    COL2 VARCHAR2(20)
    COL3 VARCHAR2(20)
    My data file, test.dat, looks like this:
    AAA|KBA
    BBR|BBCC|CCC
    NNN|BBBN|NNA
    I want to load the first record into T1, and the second and third record load into T2. How do I set up my control file to do that?
    Thank!

    Tough Job
    LOAD DATA
    truncate
    INTO table t1
    when col3 = 'dummy'
    FIELDS TERMINATED BY '|'
    TRAILING NULLCOLS
    (col1,col2,col3 filler char nullif col3='dummy')
    INTO table t2
    when col3 != 'dummy'
    FIELDS TERMINATED BY '|'
    (col1,col2,col3 nullif col3='dummy')
    This will load t2 tbl but not t1.
    T1 Filler col3 is not accepting nullif. Its diff to compare columns have null using when condition. If i find something i will let you know.
    Can you seperate records into 2 file. Will a UNIX command work for you which will seperate 2col and 3col record types for you. and then you can execute 2 controlfiles on it.
    Thanks,
    http://www.askyogesh.com

  • SQL LOADER , EXTERNAL  TABLE and ODBS DATA SOURCE

    hello
    Can any body help loading data from dbase file .dbt to an oracle 10g table.
    I tried last day with SQL LOADER, EXTERNAL table , and ODBC data source.
    Why all of these utilities still failing to solve my problem ?
    Is there an efficient way to reach this goal ?
    Thanks in advance

    export the dbase data file to text file,
    then you have choice of using either sql loader or external table option to use.
    regards

  • Extract Data from XML and Load into table using SQL*Loader

    Hi All,
    We have a XML file (sample.xml) which contains credit card transaction information. We have a standard SQL*Loader control file which loads the data from a flat file and the control file code is written as position based method. Our requirement is to use this control file as per our requirement(i.e) load the data into the table from our XML file), But we need help in converting the XML to a flat file or Extract the data from the XML tags and pass the information to the control file and in turn it loads the table.
    Your suggestion is highly appreciated.
    Thanks in advance

    Hi,
    First of all go to PSA maintanance ( Where you will see PSA records ).
    Goto list---> Save-> File---> Spreadsheet (Choose Radio Button)
    > Give the proper file name where you want to download and then-----> Generate.
    You will get ur PSA data in Excel Format.
    Thanks
    Mayank

  • Populating a load-status table from SQL*Loader

    Hello,
    I am using SQL*LDR to load a table and once I'm done with this load I am supposed to populate a status table which will capture the 'SYSDATE', and the total number of rows I loaded in the other table.
    Can anybody help me?
    Thanks

    BTW, the load-status table would take the error-record-count as well as the load-count?
    Sorry missed that earlier!

  • SQL Loader : Loading multiple tables using same ctl file

    Hi ,
    We tried loading multiple tables using the same ctl file but the data was not loaded and no errors were thrown.
    The ctl file content is summarised below :
    LOAD DATA
    APPEND INTO TABLE TABLE_ONE
    when record_type ='EVENT'
    TRAILING NULLCOLS
    record_type char TERMINATED BY ',' ,
    EVENT_SOURCE_FIELD CHAR TERMINATED BY ',' ENCLOSED BY '"',
    EVENT_DATE DATE "YYYY-MM-DD HH24:MI:SS" TERMINATED BY ',' ENCLOSED BY '"',
    EVENT_COST INTEGER EXTERNAL TERMINATED BY ',' ENCLOSED BY '"',
    EVENT_ATTRIB_1 CHAR TERMINATED BY ',' ENCLOSED BY '"',
    VAT_STATUS INTEGER EXTERNAL TERMINATED BY ',' ENCLOSED BY '"',
    ACCOUNT_REFERENCE CONSTANT 'XXX',
    bill_date "to_date('02-'||to_char(sysdate,'mm-yyyy'),'dd-mm-yyyy')",
    data_date "trunc(sysdate)",
    load_date_time "sysdate"
    INTO TABLE TABLE_TWO
    when record_type ='BILLSUMMARYRECORD'
    TRAILING NULLCOLS
    RECORD_TYPE char TERMINATED BY ',' ,
    NET_TOTAL INTEGER EXTERNAL TERMINATED BY ',' ENCLOSED BY '"',
    LOAD_DATE_TIME "sysdate"
    INTO TABLE BILL_BKP_ADJUSTMENTS
    when record_type ='ADJUSTMENTS'
    TRAILING NULLCOLS
    RECORD_TYPE char TERMINATED BY ',' ,
    ADJUSTMENT_NAME CHAR TERMINATED BY ',' ENCLOSED BY '"',
    LOAD_DATE_TIME "sysdate"
    INTO TABLE BILL_BKP_CUSTOMERRECORD
    when record_type ='CUSTOMERRECORD'
    TRAILING NULLCOLS
    RECORD_TYPE char TERMINATED BY ',' ,
    GENEVA_CUSTOMER_REF CHAR TERMINATED BY ',' ENCLOSED BY '"',
    LOAD_DATE_TIME "sysdate"
    INTO TABLE TABLE_THREE
    when record_type ='PRODUCTCHARGE'
    TRAILING NULLCOLS
    RECORD_TYPE char TERMINATED BY ',' ,
    PROD_ATTRIB_1_CHRG_DESC CHAR TERMINATED BY ',' ENCLOSED BY '"',
    LOAD_DATE_TIME "sysdate"
    Has anyone faced similar errors or are we going wrong somewhere ?
    Regards,
    Sandipan

    This is the info on the discard in the log file :
    Record 1: Discarded - failed all WHEN clauses.
    Record 638864: Discarded - failed all WHEN clauses.
    While some of the records were loaded for one table.
    Regards,
    Sandipan

  • SQL Loader to Load Multiple Tables from Multiple Files

    Hi
    I wish to create a control file to load multiple tables from multiple files
    viz.Emp.dat into emp table and Dept.dat into Dept table and so on
    How could I do it?
    Can I create a control file like this:
    OPTIONS(DIRECT=TRUE,
    SKIP_UNUSABLE_INDEXES=TRUE,
    SKIP_INDEX_MAINTENANCE=TRUE)
    UNRECOVERABLE
    LOAD DATA
    INFILE 'EMP.dat'
    INFILE 'DEPT.dat'
    INTO TABLE emp TRUNCATE
    FIELDS TERMINATED BY "|" OPTIONALLY ENCLOSED BY '"'
    (empno,
    ename,
    deptno)
    INTO TABLE dept TRUNCATE
    FIELDS TERMINATED BY "|" OPTIONALLY ENCLOSED BY '"'
    (deptno,
    dname,
    dloc)
    Appreciate a Quick Reply
    mailto:[email protected]

    Which operating system? ("Command Prompt" sounds like Windows)
    UNIX/Linux: a shell script with multiple calls to sqlldr run in the background with "&" (and possibly nohup)
    Windows: A batch file using "start" to launch multiple copies of sqlldr.
    http://www.pctools.com/forum/showthread.php?42285-background-a-process-in-batch-%28W2K%29
    http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/start.mspx?mfr=true
    Edited by: Brian Bontrager on May 31, 2013 4:04 PM

  • Using sql:variable in an insert statement

    I'm writing an insert statement for a table with an XML column.  Most of the XML is static, but I need to replace the value of an element with the value of a T-SQL variable, as shown here:
    CREATE TABLE [dbo].[OrderDetail](
    [OrderID] [int] NULL,
    [OrderDetail] [xml] NULL
    GO
    DECLARE @XMLData XML;
    DECLARE @ItemID INT;
    SET @ItemID = 1000;
    SELECT @XMLData = N'
    <OrderDetail xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    </OrderDetail>
    SET @XMLData.modify('insert <ItemID>[sql:variable("@ItemID")]</ItemID> into (/OrderDetail)[1]')
    INSERT INTO [dbo].[OrderDetail] ([OrderID], [OrderDetail])
    VALUES (@ItemID, @XMLData);
    When I run this, it inserts "[sql:variable("@ItemID")]" instead of the value of @ItemID.  If someone could show me the proper syntax, I would really appreciate it.  Thanks.

    Yes, that worked.  Now I want to change it a little.  I also have an attribute that I need to update with the value of a variable.
    DECLARE @XMLData XML;
    DECLARE @SetID INT;
    DECLARE @SetIDStr VARCHAR(12);
    DECLARE @SetIDXML XML;
    SET @SetID = 9999;
    SET @SetIDStr = CONVERT(VARCHAR(12), @SetID);
    SET @SetIDXML = CONVERT(XML, @SetIDStr);
    SELECT @XMLData = N'
    <OrderDetail xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <ItemID>1000</ItemID>
    <RightOperand ID="15524" Name="ItemName" Value="15524" />
    </OrderDetail>
    SET @XMLData.modify('replace value of (/OrderDetail/RightOperand/@ID)[1] with sql:variable("@SetIDXML")');
    INSERT INTO [dbo].[OrderDetail] ([OrderID], [OrderDetail])
    VALUES (@SetID, @XMLData);
    SELECT * FROM [dbo].[OrderDetail];
    I'm trying to replace "ID="15524"" with the value of @SetID.  This code throws an exception:
    Msg 9342, Level 16, State 1, Line 23
    XQuery [modify()]: An XML instance is only supported as the direct source of an insert using sql:column/sql:variable.
    Thanks again for your help.

  • How i pass table column  value to string variable or return to java applete

    Hi Master,
    How do I pass a table column value into string variable. See my code below:
    import java.sql.*;
    public class Waheed {
    public Waheed() {
    public static void main (String args [])
    String s = "9 23 45.4 56.7";
    System.out.println ("going for connection");
    // DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
    try{
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn =
    DriverManager.getConnection("jdbc:oracle:thin:@fahim:1521:aamir","muhammad","mfa786");
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("select accid from accbal");
    System.out.println ("going for connection");
    while (rset.next())
    s= rset.getString("accid"); this line give me error
    System.out.println (rset.getString("accid"));
    System.out.println (s);
    catch(Exception e){
    e.printStackTrace();
    This line give me an error:
    s= rset.getString("accid");
    s is string variable
    Plese give me an idea how I can pass accid in s variable.
    Thanks.
    Aamir

    See the code sample in the following thread (try using upeercase).
    JDBC  connection
    Kuassi

  • Is it possible to load a dump file collected from sql server to orcle 10gR2

    Hi..
    As a part of data migration from legacy systems , we need to migrate only required tables from Sql server to Oracle 10gr2 .
    At present client is telling that he will give it as dump file.
    My question is , Is it possible to load the dump file collected from sql server to oracle 10gR2?
    Thanks in advance ..

    yes, it is.
    Using for example SQL Developer Migration Workbench even allows you to create unload scripts for the desired SQL Server tables and it also creates the DDL scripts for you to create the Oracle tables similar to the SQL Server table AND it alows creates the SQL*Loader scripts that allow you to load the SQL Server generated dump file into the Oracle db.
    Here the link:
    http://www.oracle.com/technology/tech/migration/workbench/index_sqldev_omwb.html
    If you do not want to use this utility, you can also use SQL*Loader to load the content of the SQL Server dump file into the Oracle database; but in this case you have to write the whole SQL*Loader control scripts on your own.
    Edited by: kgronau on Sep 16, 2009 1:54 PM

  • Sql:variable and XML query performance

    Can someone help with sql:variable() in xml queries?  It seems that when I attempt to reference variables with the sql:variable(...) function in an xpath function (exist or nodes) it comes up with a totally different query plan, possibly ignoring
    my secondary indices like the ones for VALUE, PATH.
    But if I replace sql:variable("@p_ObjectIdentifierForReference") with the literal (ie. "ord/p/ord0616.p") then it uses secondary indices more consistently.
    Below you will see an unsuccessful attempt to get the query to "OPTIMIZE FOR" a specific literal value of @p_ObjectIdentifierForReference.  But this doesn't give work.  It doesn't give me a plan using the secondary index I expect.
    Ideally there would be a way to get the sql:variable(...) function to give the same query plan as a literal. Not sure why that isn't the default behavior.
    DECLARE
    @p_ObjectIdentifierForReference
    varchar(500);
    SET
    @p_ObjectIdentifierForReference
    = 'ord/p/ord0616.p';
    WITH
    XMLNAMESPACES ('uri:schemas-progress-com:XREFD:0004'
    as D)
    SELECT  
    XREF_FileDataReference.XREF_FileData     
    AS XrefFileData,
    InnerRowNode.value('/D:Reference[1]/D:File-num[1]',
    'int') 
    AS FileNumber,
    InnerRowNode.value('/D:Reference[1]/D:Line-num[1]',
    'int') 
    AS LineNumber
    FROM
    (SELECT
    XREF.XREF_FileData.XREF_FileData,
    XREF.XREF_FileData.XREF_FileEntry,
    InnerRow.query('.')
    AS InnerRowNode
     FROM
    XREF.XREF_FileData
    OUTER APPLY
    DataXref.nodes('/D:Cross-reference/D:Source/D:Reference[@Object-identifier = sql:variable("@p_ObjectIdentifierForReference")
    and @Reference-type = "RUN"]')
    as T(InnerRow)                                                           
    WHERE    DataXref.exist('/D:Cross-reference/D:Source/D:Reference[@Object-identifier
    = sql:variable("@p_ObjectIdentifierForReference") and @Reference-type = "RUN"]')
    = 1) 
    AS XREF_FileDataReference
     INNER
    JOIN  XREF.XREF_MemberBuilt  
    ON XREF_MemberBuilt.XREF_FileData  
    = XREF_FileDataReference.XREF_FileData
     INNER
    JOIN  XREF.XREF_FileEntry 
    ON XREF_FileEntry.XREF_FileEntry
    = XREF_FileDataReference.XREF_FileEntry 
    WHERE
    XREF_MemberBuilt.XREF_ProjectBuilt
    = 69
    OPTION(RECOMPILE,
    OPTIMIZE FOR (@p_ObjectIdentifierForReference
    = 'ord/p/ord0616.p')

    I tried to create a "repro" of your query so we can work on it and try and improve it, but I got the best results by just adding text() and [1] to it, eg
    SELECT
    XREF_FileDataReference.XREF_FileData AS XrefFileData,
    InnerRowNode.value('(/D:Reference/D:File-num/text())[1]', 'int') AS FileNumber,
    InnerRowNode.value('(/D:Reference/D:Line-num/text())[1]', 'int') AS LineNumber
    FROM (
    In my main repro, even with a large piece of xml with 100,000 elements, there still wasn't much difference between the queries:
    USE tempdb
    GO
    IF NOT EXISTS ( SELECT * FROM sys.schemas WHERE name = 'XREF' )
    EXEC( 'CREATE SCHEMA XREF' )
    GO
    IF OBJECT_ID('XREF.XREF_FileData') IS NOT NULL DROP TABLE XREF.XREF_FileData
    CREATE TABLE XREF.XREF_FileData
    rowId INT IDENTITY,
    DataXref XML,
    XREF_FileData INT,
    XREF_FileEntry INT,
    CONSTRAINT PK_XREF_FileData PRIMARY KEY ( rowId )
    GO
    IF OBJECT_ID('XREF.XREF_MemberBuilt') IS NOT NULL DROP TABLE XREF.XREF_MemberBuilt
    CREATE TABLE XREF.XREF_MemberBuilt
    XREF_ProjectBuilt INT,
    XREF_FileData INT
    GO
    IF OBJECT_ID('XREF.XREF_FileEntry') IS NOT NULL DROP TABLE XREF.XREF_FileEntry
    CREATE TABLE XREF.XREF_FileEntry
    XREF_FileEntry INT
    GO
    -- Create larger piece of xml for repro
    ;WITH XMLNAMESPACES ( DEFAULT 'uri:schemas-progress-com:XREFD:0004' ), cte AS (
    SELECT TOP 100000 ROW_NUMBER() OVER ( ORDER BY ( SELECT 1 ) ) rn
    FROM master.sys.columns c1
    CROSS JOIN master.sys.columns c2
    CROSS JOIN master.sys.columns c3
    INSERT INTO XREF.XREF_FileData ( DataXref, XREF_FileData, XREF_FileEntry )
    SELECT
    SELECT
    CASE rn WHEN 9999 THEN 'ord/p/ord0616.p' ELSE CAST( rn AS VARCHAR(20) ) END AS "@Object-identifier",
    'RUN' AS "@Reference-type",
    SELECT
    rn AS "File-num",
    rn * 10 AS "Line-num"
    FOR XML PATH(''), TYPE
    ) AS "*"
    FROM cte
    FOR XML PATH('Reference'), ROOT('Source'), TYPE
    ).query('<Cross-reference xmlns="uri:schemas-progress-com:XREFD:0004">{.}</Cross-reference>'), 1, 100
    INSERT INTO XREF.XREF_FileEntry ( XREF_FileEntry )
    VALUES ( 100 )
    INSERT INTO XREF.XREF_MemberBuilt ( XREF_ProjectBuilt, XREF_FileData )
    VALUES ( 69, 1 )
    GO
    --SELECT * FROM XREF.XREF_FileData
    --SELECT * FROM XREF.XREF_FileEntry
    --SELECT * FROM XREF.XREF_MemberBuilt
    --GO
    -- Add primary XML index
    CREATE PRIMARY XML INDEX xidx_XREF_FileData ON XREF.XREF_FileData (DataXref)
    GO
    -- Add value, property and path xml indexes
    CREATE XML INDEX xvalidx_XREF_FileData ON XREF.XREF_FileData (DataXref)
    USING XML INDEX xidx_XREF_FileData FOR VALUE
    CREATE XML INDEX xpthidx_XREF_FileData ON XREF.XREF_FileData (DataXref)
    USING XML INDEX xidx_XREF_FileData FOR PATH
    CREATE XML INDEX xprpidx_XREF_FileData ON XREF.XREF_FileData (DataXref)
    USING XML INDEX xidx_XREF_FileData FOR PROPERTY
    GO
    :exit
    DBCC DROPCLEANBUFFERS
    DBCC FREEPROCCACHE
    GO
    DECLARE @p_ObjectIdentifierForReference varchar(500);
    SET @p_ObjectIdentifierForReference = 'ord/p/ord0616.p';
    ;WITH XMLNAMESPACES ('uri:schemas-progress-com:XREFD:0004' as D)
    SELECT
    XREF_FileDataReference.XREF_FileData AS XrefFileData,
    InnerRowNode.value('/D:Reference[1]/D:File-num[1]', 'int') AS FileNumber,
    InnerRowNode.value('/D:Reference[1]/D:Line-num[1]', 'int') AS LineNumber
    FROM (
    SELECT
    XREF.XREF_FileData.XREF_FileData,
    XREF.XREF_FileData.XREF_FileEntry,
    InnerRow.query('.') AS InnerRowNode
    FROM XREF.XREF_FileData
    OUTER APPLY DataXref.nodes('/D:Cross-reference/D:Source/D:Reference[@Object-identifier = sql:variable("@p_ObjectIdentifierForReference") and @Reference-type = "RUN"]') as T(InnerRow)
    WHERE DataXref.exist('/D:Cross-reference/D:Source/D:Reference[@Object-identifier = sql:variable("@p_ObjectIdentifierForReference") and @Reference-type = "RUN"]') = 1
    ) AS XREF_FileDataReference
    INNER JOIN XREF.XREF_MemberBuilt ON XREF_MemberBuilt.XREF_FileData = XREF_FileDataReference.XREF_FileData
    INNER JOIN XREF.XREF_FileEntry ON XREF_FileEntry.XREF_FileEntry = XREF_FileDataReference.XREF_FileEntry
    WHERE XREF_MemberBuilt.XREF_ProjectBuilt = 69
    OPTION( RECOMPILE, OPTIMIZE FOR (@p_ObjectIdentifierForReference = 'ord/p/ord0616.p') )
    GO
    DBCC DROPCLEANBUFFERS
    DBCC FREEPROCCACHE
    GO
    DECLARE @p_ObjectIdentifierForReference varchar(500);
    SET @p_ObjectIdentifierForReference = 'ord/p/ord0616.p';
    ;WITH XMLNAMESPACES ('uri:schemas-progress-com:XREFD:0004' as D)
    SELECT
    XREF_FileDataReference.XREF_FileData AS XrefFileData,
    InnerRowNode.value('(/D:Reference/D:File-num/text())[1]', 'int') AS FileNumber,
    InnerRowNode.value('(/D:Reference/D:Line-num/text())[1]', 'int') AS LineNumber
    FROM (
    SELECT
    XREF.XREF_FileData.XREF_FileData,
    XREF.XREF_FileData.XREF_FileEntry,
    InnerRow.query('.') AS InnerRowNode
    FROM XREF.XREF_FileData
    OUTER APPLY DataXref.nodes('/D:Cross-reference/D:Source/D:Reference[@Object-identifier = sql:variable("@p_ObjectIdentifierForReference") and @Reference-type = "RUN"]') as T(InnerRow)
    WHERE DataXref.exist('/D:Cross-reference/D:Source/D:Reference[@Object-identifier = sql:variable("@p_ObjectIdentifierForReference") and @Reference-type = "RUN"]') = 1
    ) AS XREF_FileDataReference
    INNER JOIN XREF.XREF_MemberBuilt ON XREF_MemberBuilt.XREF_FileData = XREF_FileDataReference.XREF_FileData
    INNER JOIN XREF.XREF_FileEntry ON XREF_FileEntry.XREF_FileEntry = XREF_FileDataReference.XREF_FileEntry
    WHERE XREF_MemberBuilt.XREF_ProjectBuilt = 69
    OPTION( RECOMPILE, OPTIMIZE FOR (@p_ObjectIdentifierForReference = 'ord/p/ord0616.p') )
    GO
    So I guess I'm saying I cannot reproduce your problem on SQL 2008 R2 or SQL 2012.  Does anything about this repro stand out as different from your situation?
    Looking at your query I would say you might consider the following:
    are you really seeing big differences in query duration?
    pretty much ignore estimated plan costs for xml queries
    consider breaking it up; eg carve off the xml then do the joins?  If poor cardinality estimation is part of the problem this might help
    Understand what PATH, PROPERTY and VALUE are for, then only create the ones you need
    do you really have the range of queries that requires all three?
    this is still a great article on xml indexes:
    http://technet.microsoft.com/en-us/library/ms191497.aspx
    What's performance like with the primary xml index only?
    If performance is that important, consider materialising the columns permanently
    I think the buffer_descriptors stuff is a distraction - mostly your cache is warm right?
    plan forcing could be a last resort
    Selective XML indexes in SQL 2012 onwards are great : )  much less storage required for example but much more specific

  • Problems with loading source model using omw from sql server 7 into oracle 9i

    I am migrating data from sql servr 7 into oracle 9i. when doing capture phase i get the following error.
    ==>failed to load source model.[microsoft][odbc sql server][sql server]select permission
    denied on column 'password' of object 'syslogins', database master, owner dbo.
    Why is this so...is it bcz of something with my odbc link...
    also is there any way to load only tables and not system tables when doing capture phase.
    any help asap will be much appreciated.
    thanks

    Hi,
    You must ensure that you have the correct password to login to SQL Server.
    The Workbench requires some of the tables in the Master database.
    Regards
    John

  • Passing Pl/Sql variables into shell variables.

    I have written a file that ftp information from one pc to another in unix.
    All you have to do is supply a user_name/password and machine name to which ftp program will connect to.
    All connection information like user_id,password, machine name are stored in an oracle table FTP_TBL.
    It has the following fields:
    FTP_TBL
    ================
    USER_ID      NOT NULL VARCHAR2(100);
    USR_PASSWD      NOT NULL VARCHAR2(50);
    TO_MACHINE     NOT NULL VARCHAR2(50);
    I have called a pl/sql script in unix shell.
    This script selects all the connection information from FTP_TBL and populates the pl/sql variables with the
    information.
    Now i want the pl/sql variables like V_TO_MACHINE,V_USR_ID,V_USR_PASSWD to be passed on to unix variables
    To_MACHINE, USR_ID AND USR_PASSWD.
    How can i do this?
    ============================================================================================================
    sqlplus -s <<+++ >> $LOG_FILE
    $USER/$PASSWD
    set serverout on SIZE 1000000
    DECLARE
    V_TO_MACHINE VARCHAR2(100);
    V_USR_ID VARCHAR2(50);
    V_USR_PASSWD VARCHAR2(50);
    BEGIN
         BEGIN
              SELECT TO_MACHINE, USER_ID, USR_PASSWD
              INTO V_TO_MACHINE,V_USR_ID,V_USR_PASSWD
              FROM FTP_TBL;
         EXCEPTION
              when others then
              dbms_output.put_line('ERROR|SQLPLUS|'||ERROR||'|'||sqlcode||'|Failed during selecting configuration information.'||sqlerrm );
         END;
    END;
    +++
    #======================== VARIABLES =====================
    TO_MACHINE=$1
    USR_ID=$2
    USR_PASSWD=$3
    #========================== MAIN ========================
    ftp -vnd $TO_MACHINE << ++ 1>>$STA_LOG_FILE 2>&1
    user $USR_ID $USR_PASSWD
    prompt off
    get $OR_DATA_DIR/ASC.STADATA $HOME_DIR/ASC.STADATA
    bye
    ++
    # testing the exit status of FTP
    egrep "Transfer complete" $STA_LOG_FILE >/dev/null
    if [ $? = 0 ]
    then
    echo >> $STA_LOG_FILE
    echo "FTP Successfully Done" >> $STA_LOG_FILE
    else
    echo >> $STA_LOG_FILE
    echo "FTP UnSuccessfull" >> $STA_LOG_FILE
    exit 1
    fi

    Here an example of how to pass variables to the shell script :
    TEST@db102 SQL> select ename, job, dname from emp,dept
      2  where empno = 7902
      3  and emp.deptno = dept.deptno;
    ENAME      JOB       DNAME
    FORD       ANALYST   RESEARCH
    TEST@db102 SQL> exit
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    [ora102 work db102]$ cat disp_var.sh
    set `sqlplus -s test/test << EOF
    set pages 0
    select ename, job, dname from emp,dept
    where empno = 7902
    and emp.deptno = dept.deptno;
    exit
    EOF`
    echo $1 $2 $3
    [ora102 work db102]$ ./disp_var.sh
    FORD ANALYST RESEARCH
    [ora102 work db102]$                                                  

  • Create a cursor from a PL/SQL variable or an external file

    Dear friends,
    is there a way for me to make Oracle Forms read a cursor from a PL/SQL variable, or an external file? Let's suppose we have the code below:
    DECLARE
    cursor c_values is select * from my_table;
    r_values c_values%ROWTYPE;
    BEGIN
    for r_values in c_values loop
    do_something;
    end loop;
    END;
    In the situation described above, could I create "select * from my_table" from a PL/SQL variable (it could be something like p_cursor = 'select * from my_table'), or an external file - for example, make my form read the contents of c:\my_select.sql , where we see the "select * from my table" text?
    My question comes because I need to export data from select instructions that were dinamically created inside the form - that is, via PL/SQL -, and I don't want to rewrite it, but I'll have to do it if I have no choice. Your help will be greatly appreciated.
    Best regards,
    Franklin
    Edited by: franklinbrasil on 12/03/2009 11:33
    Edited by: franklinbrasil on 12/03/2009 11:35

    Dear friends,
    I am using DBMS_SQL package, which solved my problem. Please let me explain it better, if it's not clear.
    I have some PL/SQL blocks inside my form, which creates SQL queries dinamically, and a dinamically created SQL is stored into a VARCHAR2 variable. These SQL queries are exported for use in Oracle Graphics, but since OG is not being developed by Oracle anymore then I am trying to find a substitute for it.
    So I thought about creating an option for the final user: he/she can choose exporting data into Microsoft Excel, and user does what he/she wants, creating a customized graphic. Exporting into Excel works finely, with no problems at all - I could find a routine by searching on the web.
    My goal was to use the same queries created above to export data dinamically to Microsoft Excel, and I absolutely don't want to rewrite all these dinamically created queries - one which works dinamically, other with no flexibility inside my form. Worse than it, I have many other dinamically created queries, and I obviously don't want to rewrite them all - any maintenance in this form would be terrible, with each SQL instruction written twice.
    Since all dinamically created SQL instructions are stored inside a VARCHAR2 variable, I thought about reusing the same SQL, as explained above - and here we have your suggestions about using a ref cursor, execute immediate, and so on. And (answering Andreas) query structure is always based on the same table, but its structure changes a lot, depending on what the final user chooses in a drop-down list (it's a list of graphics options, where final user chooses one option, and form must mount SQL dinamically, based on user's choice).
    By using your explanations, I could find DBMS_SQL solution here: http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96590/adg09dyn.htm#26799
    . Please notice that I had to change DBMS_SQL.native into 1 for it to work in my form. I'll mark all your answers as helpful because I can use them both for database and form purposes.
    If my message was not clear enough, please tell me and I'll try to make it more clear.
    Best regards,
    Franklin

Maybe you are looking for

  • How can I scan documents with HP Office jet and airport

    I am unable to scan from my HP Office Jet L7680 with it hooked up to the iMac through the Time Capsule.  Any advice?

  • CRM 7.0 - New mailform in the email profile causing BSP error

    Hi all, I want to start to use standard responses in IC to make it more easier to reply to incoming emails... and also the tracking service ticket ID text in replies... I followed John Burton's ERMS guide, but after I created new mailform via txt  CR

  • Can You Help Me Install The OS 10.5.6 Update?

    I receive the following error message when I attempt to install the OS 10.5.6 update: "The installer could not install some files in "/". Contact the software manufacturer for assistance." I have tried each of the following, without success: * Using

  • Could not lock and unlock my bb on the top left. PLEASE HELP ME

    Hi everybody. I really need your help. My bb is 9780 and suddenly my button lock and unlock on the top left doesn't seems like working. And now when i hold the alphabet 'A' my bb can be lock but when i want to unlock it ,i cant just seems to unlock i

  • J2SDK 1.4.2 download package

    With 1.4.0 I was able to download a package and then copy that package locally to multiple machines. With 1.4.2, however, the "package" is only a small bootstrap installer, which means I need to download the whole 37MB on each machine I wish to insta