Bulk selection based on PL/SQL table

Hi forum,
I have a defined a pl/sql table named keys, contains 2 column keys(i).key and keys(i).desc.Now my requirement is to fetch the data based on from oracle table based on key strored in pl/sql table.
I know that one option is to iterate through the table.like
for i in 1..keys.count
select value into x from <table> where key = keys(i).key
Any options available to fetch the data in bulk by passing pl/sql table keys at once?
Thanks in advance...
Rgds,
Aneesh A

Something like this:
SELECT empno, ename
  FROM emp
WHERE deptno = 10
ORDER BY deptno
     EMPNO ENAME
      7782 CLARK
      7839 KING
      7934 MILLER
-- "record type"
CREATE TYPE dept_type AS OBJECT (
   deptno NUMBER(2),
   dname  VARCHAR2(14),
   loc    VARCHAR2(13)
-- nested table type
CREATE TYPE dept_tab_type AS TABLE OF dept_type
SET SERVEROUTPUT ON
DECLARE
   l_dept_tab dept_tab_type;
BEGIN
   SELECT dept_type (deptno, dname, loc)
     BULK COLLECT INTO l_dept_tab
     FROM dept
    WHERE deptno = 10;
   FOR rec IN (
     SELECT empno, ename
       FROM emp e,
            TABLE (l_dept_tab) d -- <=
      WHERE e.deptno = d.deptno
      ORDER BY empno)
   LOOP
      DBMS_OUTPUT.PUT_LINE (rec.empno || ' ' || rec.ename);
   END LOOP;
END;
7782 CLARK
7839 KING
7934 MILLERBut:
1. you can't use associative array ("PL/SQL table" is Oracle 7 termin) - you must use nested table
2. nested table type (and "record type") must be server defined
3. (or 1.) using collection for million of records is not good approach - use SQL instead of PL/SQL!
Regards,
Zlatko Sirotic

Similar Messages

  • Forms based on  PL/SQL table/ref_cursor

    I fail to tetrieve selected records from a stored package.procedure(which I have created as a ref_cursor to PL/SQL table and specifying a criteria in the forms where clause)
    Please any one suggest ?

    I suggest you read the [url http://forums.oracle.com/forums/help.jspa]FAQ and [url http://blogs.oracle.com/shay/2007/03/02]The 10 Commandments on OTN Forum Posting
    Forms version and an error message would help us to help you, we don't have crystal balls, we cannot guess.

  • View based on PL/SQL table?

    I'd like to create a view based on a PL/SQL memory table (records of %rowtype). Has anyone done this? The idea is, based on the where clause (or lack of one), the view definition containts call to a stored procedure that builds the rows to be returned. Ideas?
    Tom-

    Pipelined function - based example:
    SQL> create or replace package my_pkg
      2  is
      3   type nested_tab_type is table of emp%rowtype;
      4   nt_instance nested_tab_type := nested_tab_type();
      5   function get_nt_instance return nested_tab_type pipelined;
      6  end;
      7  /
    Package created.
    SQL> create or replace package body my_pkg
      2  is
      3   function get_nt_instance return nested_tab_type pipelined
      4   is
      5   begin
      6    for j in 1..nt_instance.count loop
      7     pipe row(nt_instance(j));
      8    end loop;
      9    return;
    10   end;
    11  end;
    12  /
    Package body created.
    SQL> create or replace view nt_view as
      2  select ename,sal from table(my_pkg.get_nt_instance)
      3  /
    View created.
    SQL> begin
      2   select * bulk collect into my_pkg.nt_instance
      3   from emp
      4   where deptno = 10;
      5  end;
      6  /
    PL/SQL procedure successfully completed.
    SQL> select * from nt_view;
    ENAME             SAL
    CLARK            2450
    KING             5000
    MILLER           1300
    SQL> begin
      2   my_pkg.nt_instance.delete;
      3   select * bulk collect into my_pkg.nt_instance
      4   from emp
      5   where deptno = 20;
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    SQL> select * from nt_view;
    ENAME             SAL
    SMITH            1000
    JONES            2975
    SCOTT            3000
    ADAMS            1100
    FORD             3000Object -based example:
    SQL> create or replace type emp_obj is object (ename varchar2(10), sal number(7,2));
      2  /
    Type created.
    SQL> create or replace type emp_obj_t is table of emp_obj;
      2  /
    Type created.
    SQL> create or replace package my_pkg
      2  is
      3   emp_t_instance emp_obj_t := emp_obj_t();
      4   function get_emp_t_instance return emp_obj_t;
      5  end;
      6  /
    Package created.
    SQL> create or replace package body my_pkg
      2  is
      3   function get_emp_t_instance return emp_obj_t
      4   is
      5   begin
      6    return emp_t_instance;
      7   end;
      8  end;
      9  /
    Package body created.
    SQL> create or replace view nt_view as
      2  select ename,sal from table(my_pkg.get_emp_t_instance)
      3  /
    View created.
    SQL> begin
      2   select emp_obj(ename,sal) bulk collect into my_pkg.emp_t_instance
      3   from emp
      4   where deptno = 10;
      5  end;
      6  /
    PL/SQL procedure successfully completed.
    SQL> select * from nt_view;
    ENAME             SAL
    CLARK            2450
    KING             5000
    MILLER           1300
    SQL> begin
      2   my_pkg.emp_t_instance.delete;
      3   select emp_obj(ename,sal) bulk collect into my_pkg.emp_t_instance
      4   from emp
      5   where deptno = 20;
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    SQL> select * from nt_view;
    ENAME             SAL
    SMITH            1000
    JONES            2975
    SCOTT            3000
    ADAMS            1100
    FORD             3000Rgds.

  • Select in PL/SQL tables ?

    Hi,
    I have create PL/SQL Table , i want to know how can i remove the redundancy of data as
    in SQL query when i used UNION ALL or DISTINCT Operators.
    The second Question is How can show(Retrieve query) only one element in SQL
    SUCH AS
    SELECT ID from PL/SQL Table Name;
    Create or replace PACKAGE Test1 IS
    type REC_DB is RECORD
    (id number(9), name varchar2(50));
    type TB_DATA IS table of REC_DB;
    function get_coll return TB_DATA pipelined;
    temp_TB_DATA TB_DATA := TB_DATA();
    type CV_TEST is REF CURSOR return REC_DB ;
    end;
    Package created.
    Create or replace PACKAGE body TEST1 IS
    function get_coll return TB_DATA pipelined
    is
    begin
    for i in 1..temp_TB_DATA.count loop
    pipe row(temp_TB_DATA (i));
    end loop;
    return;
    end;
    end;
    Package body created.
    declare
    temp_cv TEST1.CV_TEST ;
    rc TEST1.REC_DB ;
    a number(9);
    begin
    TEST1.temp_TB_DATA.delete;
    TEST1.temp_TB_DATA.extend;
    TEST1.temp_TB_DATA(1).id:=1;
    TEST1.temp_TB_DATA(1).name:='SITI';
    TEST1.temp_TB_DATA(1).id:=2;
    TEST1.temp_TB_DATA(1).name:='OMAR';
    TEST1.temp_TB_DATA(1).id:=3;
    TEST1.temp_TB_DATA(1).name:='ALI';
    TEST1.temp_TB_DATA(1).id:=4;
    TEST1.temp_TB_DATA(1).name:='DAID';
    TEST1.temp_TB_DATA(1).id:=1;
    TEST1.temp_TB_DATA(1).name:='SITI';
    TEST1.temp_TB_DATA(1).id:=2;
    TEST1.temp_TB_DATA(1).name:='OMAR';
    -- erroring out
    open temp_cv for select * from table(TEST1.get_coll);
    fetch temp_cv into rc;
    dbms_output.put_line('Deptno is ' || rc.id);
    dbms_output.put_line('ename is ' || rc.name);
    end;
    regards

    Ayham wrote:
    I have create PL/SQL Table , i want to know how can i remove the redundancy of data as
    in SQL query when i used UNION ALL or DISTINCT Operators.Repeat. There is no such thing as a PL/SQL "table". There is no such thing as a PL/SQL "table". There is no such thing as a PL/SQL "table".
    The data structure is called an array. A table in Oracle has a very specific meaning. It is a hash or index table. Can be partitioned. Clustered. Indexed. Etc.
    A PL/SQL array is NOTHING at all like a table.
    The second Question is How can show(Retrieve query) only one element in SQL
    SUCH AS
    SELECT ID from PL/SQL Table Name;And this is almost always WRONG. As you are sending (a potentially large) array that resides in PL/SQL memory as a bind variable to the SQL engine, in order for the array's contents to be processed. Why?
    Why not simply use a (proper SQL) table and not array? A table that can be indexed. That was made for running SQL against? That can take billions of rows without exhausting server memory.
    If you are using SQL against a PL/SQL array, you are basically saying "+I have made the wrong choice for processing this data+". Yes, there are exceptions to this. But exceptions are just that - exceptions.
    So why are you using a PL/SQL array? Why do you need to use SQL against it and duplicate the array's contents as bind values? Why does SET operations in PL/SQL not suffice?

  • Report from PL/SQL Table

    Thanks for answer to my first question. Now I have another problem.
    Is there any way to print a report based on virtual table, which is created during some Pl/SQL procedure and can't be easily decribed by Select statement

    SELECT FROM PL/SQL TABLE IN ORACLE REPORTS 6I
    The requirement is to populate a table and then select from that table in a report. The typical solution is to
    populate a database table, but for situations where that is undesirable there is a way to select from a PL/SQL
    table.
    For example - for each employee we want to populate a PL/SQL table and then select from that table.
    I used the following records in the emp table:
    INSERT INTO Emp VALUES(123,'Bob','Sales',555,'28-JAN-79',35000,12,30);
    INSERT INTO Emp VALUES(321,'Sue','Finance',555,'12-MAY-83',42000,12,10);
    INSERT INTO Emp VALUES(234,'Mary','Account',555,'14-AUG-82',33000,12,20);
    INSERT INTO Emp VALUES(623,'Joe','Sales',555,'28-JAN-79',35000,12,30);
    INSERT INTO Emp VALUES(621,'Jim','Finance',555,'12-MAY-83',42000,12,10);
    INSERT INTO Emp VALUES(634,'Jane','Account',555,'14-AUG-82',33000,12,20);
    INSERT INTO Emp VALUES(723,'Fred','Sales',555,'28-JAN-79',35000,12,30);
    INSERT INTO Emp VALUES(721,'Meg','Finance',555,'12-MAY-83',42000,12,10);
    INSERT INTO Emp VALUES(734,'Jill','Account',555,'14-AUG-82',33000,12,20);
    =============================================================================================
    Step 1: Create a package spec in the report:
    PACKAGE pkg_table IS
    TYPE t_rec IS RECORD (
    field1 NUMBER(6),
    field2 VARCHAR2(30));
    TYPE t_tab IS TABLE OF t_rec INDEX BY BINARY_INTEGER;
    gv_tab t_tab;
    FUNCTION populate (
    p_empno NUMBER) RETURN NUMBER;
    END;
    Step 2: Create the package body:
    PACKAGE BODY pkg_table IS
    FUNCTION populate (
    p_empno NUMBER) RETURN NUMBER IS
    BEGIN
         gv_tab.DELETE;
         -- populate table as required - for demo purposes put in anything
         FOR lv_ind IN 1..MOD(p_empno,20) LOOP
              gv_tab(lv_ind).field1 := lv_ind;
              gv_tab(lv_ind).field2 := 'row '||TO_CHAR(lv_ind)||' for emp '||TO_CHAR(p_empno);
         END LOOP;
         RETURN gv_tab.COUNT;
    END populate;
    END;
    Step 3: Create the master query:
    SELECT empno,
    ename
    FROM emp
    Step 4: Add a formula column CF_populate to the master query that does:
    function CF_populateFormula return Number is
    -- for each emp fetched this formula will repopulate the PL/SQL table
    -- and return the number of records in the table
    begin
    return pkg_table.populate(:empno);
    end;
    Step 5: Create the detail query:
    -- we need to join this to the master and then ensure that for each
    -- empno there are as many records fetched as there will be
    -- records in the PL/SQL table
    SELECT e1.empno,rownum
    FROM emp e1, emp e2, emp e3
    WHERE rownum <= :CF_populate
    Step 6: Add formula columns to the detail query for each of the fields in the
    PL/SQL table we want to display:
    CF_Field1:
    function CF_field1Formula return Number is
    begin
    return pkg_table.gv_tab(:rownum).field1;
    end;
    CF_Field2:
    function CF_field2Formula return Varchar2 is
    begin
    return pkg_table.gv_tab(:rownum).field2;
    end;
    Step 7: Create the repeating frame and layout items to display the formula columns.
    =============================================================================================
    The same technique can be used to populate a master query. In a report level formula column
    CF_Populate populate the PL/SQL table as required. In the master query we just need the rownum:
    SELECT rownum
    FROM emp, emp, emp
    WHERE rownum <= :CF_Populate
    Add the formula columns to display Field1 and Field2.
    =============================================================================================
    Hugh Nelson
    26/04/2005

  • Global Temp Table or PL/SQL Table

    I am trying to determine if this can be done only using PL/SQL table. If not, will the usage of the global temp table affects the performance.
    Here is the situation,
    I have a data block that is based on a stored procedure. This stored procedure will return table of records from different database tables with join conditions. Some of the fields within the table of records will not have data returned from database tables. They will be the fields displayed on the form and the data will be entered by user.
    For example:
    Records will look like:
    Id          (will be populated by procedure)
    Hist_avg     (will be populated by procedure)
    My_avg     (will be used as field on the form so that user can enter their own avg)
    Cheked     (will be populated by procedure)
    My questions are:
    1.     Is this doable in form using a data block based on PL/SQL table?
    2.     Will users be able to manipulate (update) the data that based on the PL/SQL table in the memory as they wish and invoke the procedure to update the underlying table when clicking on a button (Update Avg)?
    3.     What is the advantage of using PL/SQL table and global temp table from database and form point of views?
    Any info is appreciated.

    Hi there...
    Here is the Reference...
    http://asktom.oracle.com/pls/ask/f?p=4950:8:2939484874961025998::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:604830985638
    Best Regards...
    Muhammad Waseem Haroon

  • Pl/sql table(reports)

    HI
    please help me to create a Query using a PL/SQL Table.I want to use the query builder for it, but i don't see the pl/sql table, but i can see all the database tables.I am new to reports, and all of my efforts are in vain.
    Please help me out.
    hsesahdri

    SELECT FROM PL/SQL TABLE IN ORACLE REPORTS 6I
    The requirement is to populate a table and then select from that table in a report. The typical solution is to
    populate a database table, but for situations where that is undesirable there is a way to select from a PL/SQL
    table.
    For example - for each employee we want to populate a PL/SQL table and then select from that table.
    I used the following records in the emp table:
    INSERT INTO Emp VALUES(123,'Bob','Sales',555,'28-JAN-79',35000,12,30);
    INSERT INTO Emp VALUES(321,'Sue','Finance',555,'12-MAY-83',42000,12,10);
    INSERT INTO Emp VALUES(234,'Mary','Account',555,'14-AUG-82',33000,12,20);
    INSERT INTO Emp VALUES(623,'Joe','Sales',555,'28-JAN-79',35000,12,30);
    INSERT INTO Emp VALUES(621,'Jim','Finance',555,'12-MAY-83',42000,12,10);
    INSERT INTO Emp VALUES(634,'Jane','Account',555,'14-AUG-82',33000,12,20);
    INSERT INTO Emp VALUES(723,'Fred','Sales',555,'28-JAN-79',35000,12,30);
    INSERT INTO Emp VALUES(721,'Meg','Finance',555,'12-MAY-83',42000,12,10);
    INSERT INTO Emp VALUES(734,'Jill','Account',555,'14-AUG-82',33000,12,20);
    =============================================================================================
    Step 1: Create a package spec in the report:
    PACKAGE pkg_table IS
    TYPE t_rec IS RECORD (
    field1 NUMBER(6),
    field2 VARCHAR2(30));
    TYPE t_tab IS TABLE OF t_rec INDEX BY BINARY_INTEGER;
    gv_tab t_tab;
    FUNCTION populate (
    p_empno NUMBER) RETURN NUMBER;
    END;
    Step 2: Create the package body:
    PACKAGE BODY pkg_table IS
    FUNCTION populate (
    p_empno NUMBER) RETURN NUMBER IS
    BEGIN
         gv_tab.DELETE;
         -- populate table as required - for demo purposes put in anything
         FOR lv_ind IN 1..MOD(p_empno,20) LOOP
              gv_tab(lv_ind).field1 := lv_ind;
              gv_tab(lv_ind).field2 := 'row '||TO_CHAR(lv_ind)||' for emp '||TO_CHAR(p_empno);
         END LOOP;
         RETURN gv_tab.COUNT;
    END populate;
    END;
    Step 3: Create the master query:
    SELECT empno,
    ename
    FROM emp
    Step 4: Add a formula column CF_populate to the master query that does:
    function CF_populateFormula return Number is
    -- for each emp fetched this formula will repopulate the PL/SQL table
    -- and return the number of records in the table
    begin
    return pkg_table.populate(:empno);
    end;
    Step 5: Create the detail query:
    -- we need to join this to the master and then ensure that for each
    -- empno there are as many records fetched as there will be
    -- records in the PL/SQL table
    SELECT e1.empno,rownum
    FROM emp e1, emp e2, emp e3
    WHERE rownum <= :CF_populate
    Step 6: Add formula columns to the detail query for each of the fields in the
    PL/SQL table we want to display:
    CF_Field1:
    function CF_field1Formula return Number is
    begin
    return pkg_table.gv_tab(:rownum).field1;
    end;
    CF_Field2:
    function CF_field2Formula return Varchar2 is
    begin
    return pkg_table.gv_tab(:rownum).field2;
    end;
    Step 7: Create the repeating frame and layout items to display the formula columns.
    =============================================================================================
    The same technique can be used to populate a master query. In a report level formula column
    CF_Populate populate the PL/SQL table as required. In the master query we just need the rownum:
    SELECT rownum
    FROM emp, emp, emp
    WHERE rownum <= :CF_Populate
    Add the formula columns to display Field1 and Field2.
    =============================================================================================
    Hugh Nelson
    26/04/2005

  • How to get selected Row Index in a table based ona  VO?

    Hi All,
    I'm writing an ADF form wherein I use a VO based on a SQL query. I'd like to know how to get the index of a selected row. I havea selection Listener in place where I can print the selected Row's data using getSelectedRowData().toString() on the table.
    How can I get certain Attributes from this selected row.
    One solution I thought of is to get the row index and then read attributes. But I cant seem to figure out how to get rowIndex for a selected row. Any sugestions?
    Using JDeveloper 11g.
    Thanks
    P.

    If your selected row is marked as current row you can use
    // Get a attribute value of the current row of iterator
    DCIteratorBinding iterBind= (DCIteratorBinding)dcBindings.get("testIterator");
    String attribute = (String)iterBind.getCurrentRow().getAttribute("field1");Where 'testIterator' is the name of the iterator you use for the table and 'field1' is the name of an attribute you want to get.
    Or you can iterate over the selected row keys (even if it's only one):
    // get  selected Rows of a table 2
    for (Object facesRowKey : table.getSelectedRowKeys()) {
    table.setRowKey(facesRowKey);
    Object o = table.getRowData();
    JUCtrlHierNodeBinding rowData = (JUCtrlHierNodeBinding)o;
    Row row = rowData.getRow();
    TestRow testRow = (TestRow)((DCDataRow)row).getDataProvider() ;
    }Where TestRow is the row type of the VO of your table.
    Timo

  • FDM Integration script - Selecting the Period from SQL based on FDM PoV

    Hi,
    I want query SQL Period Column for the month based on the FDM PoV, can or has anyone a sample script of how this is can be achieved?
    My script when run comes back with "No records to load" - msg in my script. Let me know if you can spot anything obvious that's causing this in my script.
    SQL table
    EVENT    YEAR     Period      Entity       Ccy         Acc          ICP         Value     Product
    Actual
    FY14
    May
    HME_AT
    EUR
    ws_inp
    NULL
    39
    HRX537C2VKEA
    Actual
    FY14
    May
    HME_AT
    EUR
    ws_inp
    NULL
    3
    HS2411Z1E
    Dim objSS   'ADODB.Connection
    Dim strSQL    'SQL string
    Dim strSelectPer 'FDM Period
    Dim strCurFDMYear'FDM Year
    Dim rs        'SQL Recordset
    Dim rsAppend   'FDM tTB table append rs object
    Dim recordCount
    Dim sWhere
    Dim sSelect
    'Initialize objects
    Set cnSS = CreateObject("ADODB.Connection")
    Set rs = CreateObject("ADODB.Recordset")
    Set rsAppend = DW.DataAccess.farsTable(strWorkTableName)
    'Get Current POV Period And Year And determine HFM Select Year
    strSelectPer = Left((RES.PstrPer), 3)
    strCurFDMYear = Right(RES.PstrPer, 4)
    Select Case UCase(strSelectPer)
    Case "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"
      strSelectYear = strCurFDMYear + 1
    Case "JAN", "FEB", "MAR"
         strSelectYear = strCurFDMYear
    End Select
    'Watch with this as it can cause looping
    On Error Resume Next
    Err.clear
    'Connect to SQL database
    'cnSS.Open "Driver=SQL Server;Server=EHEINTRADCG\EHEINTRADCG;Database=dw_foundation;UID=hypdb"
    cnSS.Open "Driver=SQL Server;Server=EHEINTRADCG\EHEINTRADCG;Database=ODI_WORK_MARS;UID=hypdb"
    'Connect to SQL Server database
    cnSS.CommandTimeout = 1200
    'Keep the error message handling in for testing but will probably need  to write
    'to a log if running in an overnight batch
    'Error Handling
    If  Err.Number <> 0  Then  
    '  An exception occurred
    RES.PlngActionType = 2
    RES.PstrActionValue =  Err.Description & Chr(10) & "Unable to connect to SQL Data Source"
    Err.clear
    Set cnSS = Nothing
    FinAllLocs_Conv = False
    Exit Function
    End If
    'Create query String
    strSQL = strSQL & "From ODI_WORK_MARS.dbo.TMP_HFM_DATA_EXTRACT_TIN1 "
    strSQL = sWhere & " And YearID =  '" & strSelectYear & "'  And PeriodID = '" & strSelectPer & "'"
    'Get data
    rs.Open strSQL, cnSS
    '    Check For data
    If rs.bof And rs.eof Then
      RES.PlngActionType = 2
             RES.PstrActionValue = "No Records to load!"
      Exit Function
    End If
    '   RecordCount = 0
        'Loop through records and append to FDM tTB table in location's DB
    If Not rs.bof And Not rs.eof Then
      Do While Not rs.eof
    'Create the record 
      rsAppend.AddNew
       rsAppend.Fields("PartitionKey") = RES.PlngLocKey         ' Location ID
       rsAppend.Fields("CatKey") = RES.PlngCatKey          'Current Category ID
       rsAppend.Fields("PeriodKey") = RES.PdtePerKey         'Current Period ID
          rsAppend.Fields("DataView") = "YTD"            'Data View ID
       rsAppend.Fields("CalcAcctType") = 9            'Input data indicator
       rsAppend.Fields("Entity") = rs.fields("Entity").Value        ' Entity/Genpo ID
       rsAppend.Fields("Account")= rs.fields("Account").Value        'Account ID
          rsAppend.Fields("ICP") = rs.fields("Inter_Company_Entity_HFM").Value   ' Inter-Co/Destination
       rsAppend.Fields("Amount") = rs.fields("Value").Value        ' Data Value ID
      rsAppend.Update
      RecordCount = Recordcount + 1
      rs.movenext
      Loop
    End If
    'Records loaded
    RES.PlngActionType = 2
        RES.PstrActionValue = "SQL Import successful!   "  & RecordCount
    'Assign Return value
    SAP_HFM = True
    End Function

    Hi,
    the easiest way to check it is to redirect your SQL query to text file and then execute in a SQL tool.
    You should write the value of strSQL (which actually seems to have missing the SELECT clause)
    In any case, your SQL statement seems to be incomplete:
    strSQL = strSQL & "From ODI_WORK_MARS.dbo.TMP_HFM_DATA_EXTRACT_TIN1 "
    strSQL = sWhere & " And YearID =  '" & strSelectYear & "'  And PeriodID = '" & strSelectPer & "'"
    - You have not initialized strSQL with SELECT clause (maybe sSelect?)
    - You have not initialized sWhere with WHERE clause
    In addition to this, your source year is in FYYY format while you are taking year from POV as YYYY.
    (...And YearID = 2014 while in your table you have FY14)
    After you check this, get the SQL statement, review it, and try to launch against your source DB in a SQL tool.
    Regards

  • SQL Bulk Update using Update query in SQL Table

    Hello All,
    I want to update data in sql table depends on some condition.
    I am getting excel sheet from client and want to change value of field say Status = c.
    Client is sending excel sheet with 300 field and want to change value for all 300 records with unique fields (field1 and field2) comming in that excel sheet...
    How can i write and update records as Bulk.
    Instaed updating one one recors ?
    Example ( Update Table_Name Set Status = 'c' Where Field1 = Value from Excel for Field1 and
    Field2 = Value from Excel for Field2 )
    Same needs to do for 300 records...
    Any help will wellcome.
    Thanks,
    Nilesh....
    Thanks and Regards, Nilesh Thakur.

    you can use OPENROWSET for that
    http://www.mssqltips.com/sqlservertip/1540/insert-update-or-delete-data-in-sql-server-from-excel/
    Another way is to use SSIS with data flow task having Excel source connecting to excel and using OLEDB command to update rows in table using it. You may also use staging table to get data from excel and later use it inexecute sql task to update your table
    to make update set based which would be faster.
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Creating a PL/SQL table based on XML file.

    I have created two procedures to try and achieve the problem at hand.
    It retrieves and displays the record from a DBMS_OUTPUT.PUT_LINE prospective as indicated in (1&2), but I am having difficulty loading these values into a PL/SQL table from the package labeled as (3).
    All code compiles. (1&2) work together, (3) works by itself but will not populate the table, and I get no errors.
    1.The first being the one that retrieves the XML file and parses it.
    CREATE OR REPLACE procedure xml_main is
    P XMLPARSER.Parser;
    DOC CLOB;
    v_xmldoc xmldom.DOMDocument;
    v_out CLOB;
    BEGIN
    P := xmlparser.newParser;
    xmlparser.setValidationMode(p, FALSE);
    DOC := '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <com.welligent.Student.BasicStudent.Create>
    <ControlAreaSync messageCategory="com.welligent.Student" messageObject="BasicStudent" messageAction="Create" messageRelease="1.0" messagePriority="1" messageType="Sync">
    <Sender>
    <MessageId>
    <SenderAppId>com.openii.SyncRouter</SenderAppId>
    <ProducerId>a72af712-90ea-43be-b958-077a87a29bfb</ProducerId>
    <MessageSeq>53</MessageSeq>
    </MessageId>
    <Authentication>
    <AuthUserId>Router</AuthUserId>
    </Authentication>
    </Sender>
    <Datetime>
    <Year>2001</Year>
    <Month>3</Month>
    <Day>23</Day>
    <Hour>13</Hour>
    <Minute>47</Minute>
    <Second>30</Second>
    <SubSecond>223</SubSecond>
    <Timezone>6:00-GMT</Timezone>
    </Datetime>
    </ControlAreaSync>
    <DataArea>
    <NewData>
    <BasicStudent mealCode="" usBorn="Yes" migrant="No" workAbility="No" ellStatus="">
    <StudentNumber>052589F201</StudentNumber>
    <ExternalIdNumber>1234567890</ExternalIdNumber>
    <StateIdNumber>123456</StateIdNumber>
    <Name>
    <LastName>Lopez</LastName>
    <FirstName>Maria</FirstName>
    <MiddleName>S</MiddleName>
    </Name>
    <Gender>Female</Gender>
    <BirthDate>
    <Month>1</Month>
    <Day>1</Day>
    <Year>1995</Year>
    </BirthDate>
    <Race>Hispanic</Race>
    <Ethnicity>Hispanic</Ethnicity>
    <PrimaryLanguage>English</PrimaryLanguage>
    <HouseholdLanguage>Spanish</HouseholdLanguage>
    <Address>
    <Street>123 Any Street</Street>
    <ApartmentNumber>12-D</ApartmentNumber>
    <City>Los Angeles</City>
    <County>Los Angeles</County>
    <State>CA</State>
    <ZipCode>90071</ZipCode>
    </Address>
    </BasicStudent>
    </NewData>
    </DataArea>
    </com.welligent.Student.BasicStudent.Create>';
    --v_out  := DOC;
    SYS.XMLPARSER.PARSECLOB ( P, DOC );
    v_xmldoc := SYS.XMLPARSER.getDocument(P);
    --DBMS_LOB.createtemporary(v_out,FALSE,DBMS_LOB.SESSION);
    --v_out := SYS.XMLPARSER.PARSECLOB ( P, DOC );
    --SYS.XMLDOM.writetoCLOB(v_xmldoc, v_out);
    --INSERT INTO TEST (TEST_COLUMN)
    --VALUES(V_OUT);
    --printElements(v_xmldoc);
    printElementAttributes(v_xmldoc);
    exception
    when xmldom.INDEX_SIZE_ERR then
    raise_application_error(-20120, 'Index Size error');
    when xmldom.DOMSTRING_SIZE_ERR then
    raise_application_error(-20120, 'String Size error');
    when xmldom.HIERARCHY_REQUEST_ERR then
    raise_application_error(-20120, 'Hierarchy request error');
    when xmldom.WRONG_DOCUMENT_ERR then
    raise_application_error(-20120, 'Wrong doc error');
    when xmldom.INVALID_CHARACTER_ERR then
    raise_application_error(-20120, 'Invalid Char error');
    when xmldom.NO_DATA_ALLOWED_ERR then
    raise_application_error(-20120, 'Nod data allowed error');
    when xmldom.NO_MODIFICATION_ALLOWED_ERR then
    raise_application_error(-20120, 'No mod allowed error');
    when xmldom.NOT_FOUND_ERR then
    raise_application_error(-20120, 'Not found error');
    when xmldom.NOT_SUPPORTED_ERR then
    raise_application_error(-20120, 'Not supported error');
    when xmldom.INUSE_ATTRIBUTE_ERR then
    raise_application_error(-20120, 'In use attr error');
    END;
    2. The second which displays the values from the .xml file I initialized above.
    CREATE OR REPLACE procedure printElementAttributes(doc xmldom.DOMDocument) is
    nl XMLDOM.DOMNODELIST;
    len1           NUMBER;
    len2 NUMBER;
    n      XMLDOM.DOMNODE;
    e      XMLDOM.DOMELEMENT;
    nnm      XMLDOM.DOMNAMEDNODEMAP;
    attrname VARCHAR2(100);
    attrval VARCHAR2(100);
    text_value VARCHAR2(100):=NULL;
    n_child XMLDOM.DOMNODE;
    BEGIN
    -- get all elements
    nl := XMLDOM.getElementsByTagName(doc, '*');
    len1 := XMLDOM.getLength(nl);
    -- loop through elements
    FOR j in 0..len1-1 LOOP
    n := XMLDOM.item(nl, j);
    e := XMLDOM.makeElement(n);
    DBMS_OUTPUT.PUT_LINE(xmldom.getTagName(e) || ':');
    -- get all attributes of element
    nnm := xmldom.getAttributes(n);
         n_child:=xmldom.getFirstChild(n);
    text_value:=xmldom.getNodeValue(n_child);
    dbms_output.put_line('val='||text_value);
    IF (xmldom.isNull(nnm) = FALSE) THEN
    len2 := xmldom.getLength(nnm);
              dbms_output.put_line('length='||len2);
    -- loop through attributes
    FOR i IN 0..len2-1 LOOP
    n := xmldom.item(nnm, i);
    attrname := xmldom.getNodeName(n);
    attrval := xmldom.getNodeValue(n);
    dbms_output.put(' ' || attrname || ' = ' || attrval);
    END LOOP;
    dbms_output.put_line('');
    END IF;
    END LOOP;
    END printElementAttributes;
    3. The package trying to insert into a PL/SQL table.
    CREATE OR REPLACE PACKAGE BODY XMLSTUD2 AS
    PROCEDURE STUDLOAD
    IS
    v_parser xmlparser.Parser;
    v_doc xmldom.DOMDocument;
    v_nl xmldom.DOMNodeList;
    v_n xmldom.DOMNode;
    DOC CLOB;
    v_out CLOB;
    n2 XMLDOM.DOMNODELIST;
    TYPE stuxml_type IS TABLE OF STUDENTS%ROWTYPE;
    s_tab stuxml_type := stuxml_type();
    --l_sturec students%rowtype;
    BEGIN
    -- Create a parser.
    v_parser := xmlparser.newParser;
    xmlparser.setValidationMode(v_parser, FALSE);
    DOC := '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <com.welligent.Student.BasicStudent.Create>
    <ControlAreaSync messageCategory="com.welligent.Student" messageObject="BasicStudent" messageAction="Create" messageRelease="1.0" messagePriority="1" messageType="Sync">
    <Sender>
    <MessageId>
    <SenderAppId>com.openii.SyncRouter</SenderAppId>
    <ProducerId>a72af712-90ea-43be-b958-077a87a29bfb</ProducerId>
    <MessageSeq>53</MessageSeq>
    </MessageId>
    <Authentication>
    <AuthUserId>Router</AuthUserId>
    </Authentication>
    </Sender>
    <Datetime>
    <Year>2001</Year>
    <Month>3</Month>
    <Day>23</Day>
    <Hour>13</Hour>
    <Minute>47</Minute>
    <Second>30</Second>
    <SubSecond>223</SubSecond>
    <Timezone>6:00-GMT</Timezone>
    </Datetime>
    </ControlAreaSync>
    <DataArea>
    <NewData>
    <BasicStudent mealCode="" usBorn="Yes" migrant="No" workAbility="No" ellStatus="">
    <StudentNumber>052589F201</StudentNumber>
    <ExternalIdNumber>1234567890</ExternalIdNumber>
    <StateIdNumber>123456</StateIdNumber>
    <Name>
    <LastName>Lopez</LastName>
    <FirstName>Maria</FirstName>
    <MiddleName>S</MiddleName>
    </Name>
    <Gender>Female</Gender>
    <BirthDate>
    <Month>1</Month>
    <Day>1</Day>
    <Year>1995</Year>
    </BirthDate>
    <Race>Hispanic</Race>
    <Ethnicity>Hispanic</Ethnicity>
    <PrimaryLanguage>English</PrimaryLanguage>
    <HouseholdLanguage>Spanish</HouseholdLanguage>
    <Address>
    <Street>123 Any Street</Street>
    <ApartmentNumber>12-D</ApartmentNumber>
    <City>Los Angeles</City>
    <County>Los Angeles</County>
    <State>CA</State>
    <ZipCode>90071</ZipCode>
    </Address>
    </BasicStudent>
    </NewData>
    </DataArea>
    </com.welligent.Student.BasicStudent.Create>';
    -- Parse the document and create a new DOM document.
    SYS.XMLPARSER.PARSECLOB ( v_parser, DOC );
    v_doc := SYS.XMLPARSER.getDocument(v_parser);
    -- Free resources associated with the Parser now it is no longer needed.
    xmlparser.freeParser(v_parser);
    -- Get a list of all the STUD nodes in the document using the XPATH syntax.
    v_nl := xslprocessor.selectNodes(xmldom.makeNode(v_doc),'/com.welligent.Student.BasicStudent.Create/DataArea/NewData/BasicStudent/Address');
    dbms_output.put_line( 'New Stud processed on '||to_char(sysdate, 'YYYY-MON-DD'));
    -- Loop through the list and create a new record in a tble collection
    -- for each STUD record.
    FOR stud IN 0 .. xmldom.getLength(v_nl) - 1 LOOP
    v_n := xmldom.item(v_nl, stud);
    s_tab.extend;
    -- Use XPATH syntax to assign values to he elements of the collection.
         --s_tab(s_tab.last).STUDENT_ID :=xslprocessor.valueOf(v_n,'StudentNumber');
         --s_tab(s_tab.last).SSN :=xslprocessor.valueOf(v_n,'ExternalIdNumber');
         --s_tab(s_tab.last).SHISID :=xslprocessor.valueOf(v_n,'StateIdNumber');
         s_tab(s_tab.last).STUDENT_LAST_NAME :=xslprocessor.valueOf(v_n,'LastName');
         --dbms_output.put_line( s_tab(s_tab.last).STUDENT_LAST_NAME);
         s_tab(s_tab.last).STUDENT_FIRST_NAME :=xslprocessor.valueOf(v_n,'FirstName');
         --s_tab(s_tab.last).STUDENT_MI :=xslprocessor.valueOf(v_n,'MiddleName');
         --s_tab(s_tab.last).STUDENT_GENDER :=xslprocessor.valueOf(v_n,'Gender');
         --s_tab(s_tab.last).SHISID :=xslprocessor.valueOf(v_n,'Month');
         --s_tab(s_tab.last).SHISID :=xslprocessor.valueOf(v_n,'Day');
         --s_tab(s_tab.last).SHISID :=xslprocessor.valueOf(v_n,'Year');
         --s_tab(s_tab.last).STUDENT_RACE :=xslprocessor.valueOf(v_n,'Race');
         --s_tab(s_tab.last).STUDENT_ETHNIC :=xslprocessor.valueOf(v_n,'Ethnicity');
         --s_tab(s_tab.last).STUDENT_PRI_LANG :=xslprocessor.valueOf(v_n,'PrimaryLanguage');
         --s_tab(s_tab.last).STUDENT_SEC_LANG :=xslprocessor.valueOf(v_n,'HouseholdLanguage');
         --s_tab(s_tab.last).STUDENT_STREET :=xslprocessor.valueOf(v_n,'Street');
         --s_tab(s_tab.last).STUDENT_APART_NO :=xslprocessor.valueOf(v_n,'ApartmentNumber');
         --s_tab(s_tab.last).STUDENT_COUNTY :=xslprocessor.valueOf(v_n,'City'); 
         --s_tab(s_tab.last).STUDENT_COUNTY :=xslprocessor.valueOf(v_n,'County');
         --s_tab(s_tab.last).STUDENT_STATE :=xslprocessor.valueOf(v_n,'State');
         --s_tab(s_tab.last).STUDENT_ZIP :=xslprocessor.valueOf(v_n,'ZipCode');
    END LOOP;
    FOR stud IN s_tab.first..s_tab.last LOOP
    dbms_output.put_line( s_tab(s_tab.last).STUDENT_LAST_NAME);
    INSERT INTO STUDENTS (
    SHISID, SSN, DOE_SCHOOL_NUMBER,
    PATIENT_TYPE, TEACHER, HOMEROOM,
    STUDENT_LAST_NAME, STUDENT_FIRST_NAME, STUDENT_MI,
    STUDENT_DOB, STUDENT_BIRTH_CERT, STUDENT_COMM,
    STUDENT_MUSA, STUDENT_FAMSIZE, STUDENT_FAMINCOME,
    STUDENT_UNINSURED, STUDENT_LUNCH, STUDENT_ZIP,
    STUDENT_STATE, STUDENT_COUNTY, STUDENT_STREET,
    STUDENT_APART_NO, STUDENT_PHONE, STUDENT_H2O_TYPE,
    STUDENT_WASTE_TRT, STUDENT_HOME_SET, STUDENT_NONHOME_SET,
    STUDENT_GENDER, STUDENT_RACE, STUDENT_ETHNIC,
    STUDENT_PRI_LANG, STUDENT_SEC_LANG, STUDENT_ATRISK,
    EMER_COND_MEMO, ASSIST_DEVICE_TYPE, SCHOOL_ENTER_AGE,
    STUDENT_CURR_GRADE, S504_ELIG_DATE, S504_DEV_DATE,
    S504_REV_DATE, STUDENT_504, STUDENT_IEP,
    IEP_EXP_DATE, GRAD_CLASS, TYPE_DIPLOMA,
    GRADE_RETAIN, LIT_PASS_TEST_MATH, LIT_PASS_DATE_MATH,
    LIT_PASS_TEST_WRITE, LIT_PASS_DATE_WRITE, LIT_PASS_TEST_READ,
    LIT_PASS_DATE_READ, SPEC_ED_ELIG, SPEC_ED_CODE,
    TRANSPORT_CODE, TRANSPORT_NO, PRIME_HANDICAP,
    PRIME_HANDICAP_PERCENT, PRIME_HANDI_MANAGER, FIRST_ADD_HANDI,
    FIRST_ADD_HANDICAP_PERCENT, FIRST_ADD_HANDI_504, FIRST_ADD_HANDI_504_DATE,
    SECOND_ADD_HANDI, SECOND_ADD_HANDICAP_PERCENT, MED_EXTERNAL_NAME,
    INS_TYPE, INS_PRI, INS_NAME,
    INS_MEDICAID_NO, ELIGDATE, INS_PRIV_INSURANCE,
    INS_APPR_BILL, INS_APPR_DATE, INS_PARENT_APPR,
    INS_POL_NAME, INS_POL_NO, INS_CARRIER_NO,
    INS_CARRIER_NAME, INS_CARRIER_RELATE, INS_AFFECT_DATE,
    INS_COPAY_OV, INS_COPAY_RX, INS_COPAY_AMBUL,
    INS_COPAY_EMER, INS_COPAY_OUTPAT, STUDENT_INACTIVE,
    PHYS_ID, ENCOUNTERNUM, USERID,
    MODDATE, STUDENT_ID, S504_DISABILITY,
    CHAPTER1, WELLNESS_ENROLL, SCHOOL_OF_RESIDENCE,
    INITIAL_IEP_DATE, CALENDAR_TRACK, USA_BORN,
    ALT_ID, FUTURE_SCHOOL, IEP_LAST_MEETING,
    IEP_LAST_SETTING, IEP_LAST_REFER_EVAL, THIRD_ADD_HANDI,
    LEP, GIFTED, IEP_EXIT_REASON,
    CASE_MANAGER_ID, INTAKE_NOTES, CALLER_PHONE,
    CALL_DATE, CALLER_RELATIONSHIP, CALLER_NAME,
    BUSINESS_PHONE, FAX, EMAIL,
    HIGHEST_EDUCATION, INTAKE_DATE, SERVICE_COORDINATOR,
    DISCHARGE_DATE, DISCHARGE_REASON, DISCHARGE_NOTES,
    INTAKE_BY, INTAKE_STATUS, IEP_LAST_SERVED_DATE,
    IEP_APC_DATE, IEP_EXIT_DATE, ADDRESS2,
    LEGAL_STATUS, RELIGION, EMPLOYMENT_STATUS,
    TARG_POP_GROUP1, TARG_POP_GROUP2, MARITAL_STATUS,
    THIRD_ADD_HANDI_PERCENT, LAST_INTERFACE_DATE, SERVICE_PLAN_TYPE,
    CURRENT_JURISDICTION, FIPS, BIRTH_PLACE_JURISDICTION,
    BIRTH_PLACE_HOSPITAL, BIRTH_PLACE_STATE, BIRTH_PLACE_COUNTRY,
    OTHER_CLIENT_NAME, SIBLINGS_WITH_SERVICES, PERM_SHARE_INFORMATION,
    PERM_VERIFY_INSURANCE, REFERRING_AGENCY, REFERRING_INDIVIDUAL,
    AUTOMATIC_ELIGIBILITY, INTAKE_IEP_ID, FUTURE_SCHOOL2,
    FUTURE_SCHOOL3, TRANSLATOR_NEEDED, TOTAL_CHILDREN_IN_HOME,
    REFERRED_BY, FAMILY_ID, SCREENING_CONSENT_FLAG,
    PICTURE_FILE, DUAL_ENROLLED, DOE_SCHOOL_NUMBER2)
    VALUES (123456789012, null,null ,
    null,null,null ,s_tab(stud).STUDENT_LAST_NAME
    , s_tab(stud).STUDENT_LAST_NAME,null ,
    null ,null ,null ,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null ,null , null,
    null, null,null );
    END LOOP;
    COMMIT;
    -- Free any resources associated with the document now it
    -- is no longer needed.
    xmldom.freeDocument(v_doc);
    END STUDLOAD;
    END XMLSTUD2;
    /

    Hi
    I have created a PLSQL package based Oracle Portal
    form. This is created a s a databse provider. I have
    following questions to check :
    1. How to capture return values from the package and
    display different messages on success or failure ?
    - http://download.oracle.com/docs/cd/B14099_19/portal.1014/b14135/pdg_portletbuilder.htm#BABBAFGI
    Step 16
    2. How to return to blank form by intializing already
    entered values after successfuly process of the form
    data.
    - http://download.oracle.com/docs/cd/B14099_19/portal.1014/b14135/pdg_portletbuilder.htm#BABGBCHH
    thanks
    Manjith

  • How to select data from a PL/SQL table

    Hi,
    I am selecting data from database after doing some screening i want to store it in a PL/SQL table (temporary area) and pass it to oracle reports.
    Is there any way to select the data from a PL/SQL table as a cursor. Or is there any other way of holding the temporary data and then pass it back as a cursor.
    Regards
    Kamal

    A PL/SQL "table" is anything but a table. Whoever came up with this term in PL/SQL to describe what is known as dynamic arrays (the correct programming terminology that existed since the 70's if not earlier and what is used in all other programming languages I'm familiar with)... well, several descriptions come to mind and none of them are complimentary.
    You cannot "select" from a PL/SQL dynamic array as it is not a table within the Oracle context of tables.
    Thus you need to convert (cast) a PL/SQL dynamic array into a temporary Oracle data set/table in order to select from it. This is in general a Bad Idea (tm). Oracle tables and SQL and concurrency controls and all that are especially designed for processing data. PL/SQL arrays is a very simplistic data structure with very limited usage. Why would you want to use that in SQL via a SELECT statement when you can use Oracle tables (or proper temp tables) instead? Besides that, it is also slow to cast a dynamic PL/SQL array into an Oracle SQL data set structure (context switching, copying of memory, etc).
    The proper way to use PL/SQL to generate data sets for use via the SQL engine is pipelined table functions.
    This is not to say that you should never use PL/SQL arrays and casting in SQL.. simply that you need to make sure that this is the correct and scalable way to do it. And that will also always be an exception to the rule when you do.

  • Error while retrieving data from PL/SQL Table using SELECT st. (Urgent!!!)

    Hi Friends,
    I am using Oracle 8.1.6 Server, & facing problems while retrieving data from a PL/SQL Table:
    CREATE or REPLACE PROCEDURE test_proc IS
    TYPE tP2 is TABLE of varchar2(10); --declared a collection
    dt2 tP2 := tP2('a','b','c');
    i NUMBER(8);
    begin
    SELECT COUNT(*) INTO i FROM TABLE(CAST(dt2 as tP2));
    DBMS_OUTPUT.PUT_LINE('**'||i);
    end;
    While executing the above procedure, I encountered foll. error:
    ERROR at line 1:
    ORA-00600: internal error code, arguments: [15419], [severe error during PL/SQL execution], [], [],
    ORA-06544: PL/SQL: internal error, arguments: [pfrrun.c:pfrbnd1()], [], [], [], [], [], [], []
    ORA-06553: PLS-801: internal error [0]
    Can anyone please help me, where the problem is??
    Is it Possible to retrieve data from PL/SQL TABLE using SELECT statement? & How ?
    Thanks in advance.
    Best Regards,
    Jay Raval.

    Thanks Roger for the Update.
    It means that have to first CREATE TYPE .. TABLE in database then only I can fire a Select statement on that TYPE.
    Actually I wanted to fire a Select statement on the TABLE TYPE, defined & declared in PLSQL stored procedure using DECLARE TYPE .. TABLE & not using CREATE TYPE .. TABLE.
    I was eager to know this, because my organization is reluctant in using CREATE TYPE .. TABLE defined in the database, so I was looking out for another alternative to access PL/SQL TABLE using Select statement without defining it database. It would have been good if I could access a PLSQL TABLE using Select statement Declared locally in the stored procedure.
    Can I summarize that to access a PL/SQL TABLE using SELECT statement, I have to first CREATE TYPE .. TABLE?
    If someone have any other idea on this, please do let me know.
    Thanks a lot for all help.
    Best Regards,
    Jay Raval.
    You have to define a database type...
    create type tP2 is table of varchar2(10)
    CREATE OR REPLACE PROCEDURE TEST_PROC
    IS
    dt2 tP2 := tP2('a','b','c');
    i NUMBER(8);
    begin
    SELECT COUNT(*) INTO i FROM TABLE(CAST (dt2 AS tP2));
    DBMS_OUTPUT.PUT_LINE('**'||i);
    end;
    This will work.
    Roger

  • Selecting rows as columns in sql table

    i have sql table like 
    currcode    currdesc                  mth    yr        rate
    SGD          SINGAPORE DOLLAR    01    2013      .02
    SGD          SINGAPORE DOLLAR    09    2013      .02  (suppose have rates only for jan and sept )
    RMB          CHINESE RENMINBI     01    2013      .206
    RMB          CHINESE RENMINBI     02    2013      .207
    For each currency rates for 12 months for every year
    i want to show like (user will select the year)
    currcode    currdesc                      Jan       Feb     Mar    Apr     May    Jun    Jul    Aug    
    Sept   oct   nov  Dec
    SGD          SINGAPORE DOLLAR     .02                                                    
                                .02
    RMB          CHINESE RENMINBI      .206      .207
    h2007

    you can use either of the below
    1. Using PIVOT operator
    SELECT currcode,
    currdesc,
    Yr,
    [01] AS Jan,
    [02] AS Feb,
    [03] AS Mar,
    [11] AS Nov,
    [12] AS Dec
    FROM Table t
    PIVOT (MAX(rate) FOR mth IN ([01],[02],[03],[04],..,[11],[12]))p
    2. using classical cross tab logic
    SELECT currcode,
    currdesc,
    yr,
    MAX(CASE WHEN mth = '01' THEN rate END) AS Jan,
    MAX(CASE WHEN mth = '02' THEN rate END) AS Feb,
    MAX(CASE WHEN mth = '03' THEN rate END) AS Mar,
    MAX(CASE WHEN mth = '11' THEN rate END) AS Nov,
    MAX(CASE WHEN mth = '12' THEN rate END) AS Dec
    FROM table
    GROUP BY currcode,currdesc,yr
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
    Thank u for helping. Your 2nd solution working great. But using Pivot table giving me 2 rows,
    RMB CHINESE RENMINBI
    2013 NULL
    NULL NULL
    0.206  NULL  NULL
    RMB CHINESE RENMINBI
    2013 NULL
    NULL NULL
    NULL  NULL
      0.207
    h2007
    Do you've any additional columns you've not shown in the post above?
    to change NULLs to 0 use this
    SELECT currcode,
    currdesc,
    yr,
    MAX(CASE WHEN mth = '01' THEN rate ELSE 0.00 END) AS Jan,
    MAX(CASE WHEN mth = '02' THEN rate ELSE 0.00 END) AS Feb,
    MAX(CASE WHEN mth = '03' THEN rate ELSE 0.00 END) AS Mar,
    MAX(CASE WHEN mth = '11' THEN rate ELSE 0.00 END) AS Nov,
    MAX(CASE WHEN mth = '12' THEN rate ELSE 0.00 END) AS Dec
    FROM table
    GROUP BY currcode,currdesc,yr
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • SQL query problem:  how tp select all duplication in the table?

    Hi all,
    I have a table with the following columns:
    1. contact_id
    2. fname
    3. lname
    4. email
    The email column must be unique (unfortunately it's not); therefore, I have to delete all duplication in the system.
    Question: how can I select all duplication in the table?
    I tried this...didn't work (I'm expecting only the emails that are duplicated)
    THANK YOU!
    SELECT distinct TC1.email, TC1.contact_ID FROM ta_contacts AS TC1 where TC1.email <>'' AND TC1.email not in (   SELECT distinct TC2.email   FROM ta_contacts AS TC2   where TC2.email <>'' )

    Sounds like an SQL and not a JDBC question. In any case, if a column needs to be unique, then you should, of course, designate a unique constraint on the table so you never end up with duplicates in the first place.

Maybe you are looking for

  • JDriver error using WLS6.1 w/ Oracle 8.1.7

    Hello,I am getting the error listed when starting my weblogic server after creating a connection pool and datasource through the weblogic (6.1) console. I am currently using the jDriver 5.1.0 oracle kit. I used this kit previously with the WLS6.0sp1

  • Parameter in select to returns all records.

    Post Author: ComputerMike CA Forum: Crystal Reports Hi, I have a "project" parameter I use in my select formula to return records based the project field.  I would like to pass a value like "All" or "*" and have all reords returned, to see the record

  • Carrier sign still showing after wiping and reloading OS?

    Hello dear users, In my thread of "application installation issues", it seems to be determined that my carrier who I got the phone from, is blocking the install of applications as I get a 910 error, application authorization failure, when i try to in

  • PSD & PSB - 2files, same image, same size, same dpi, any difference?

    Hello Everyone I need some help on just clarifying this: If i had a image: Size: 60mm x 80mm Dpi: 300 ..with a photo of a flower or something IF i save it as a PSD and another exact file but in PSB would there be any difference in quality or resoluti

  • CS6 Error 16 Code after installing on new computer.

    I just purchased a new Mac Pro Desktop. My old machine used Snow Lepoard and this is Mountain Lion.  After migrating data from my ole machine to this one, I am unable to open any program in CS6. When I attempt to, I receive a Error 16 advising me to