For loop or table cast to collection variable

Hi ,
I have a collection variable (Table type) which can have at-most 20 variables in it. I want to fetch one particular record.
Which is more efficient; a For loop* or a table cast* ?
Thanks,

@Karthick, The requirement is like I have a query (with 2 joins in it) in a procedure which is executing about 50Lac times, and out of 50Lac execution it is fetching same data for say 25000 records.
I mean query output is same for 25000 records (not fixed) and then it is same for next 25000 records. So I took a collection variable and did a BULK COLLECT to a variable and trying to process (fetch) data in memory instead of hitting the query again (and table ) again.
Also query is taking 0.001 sec per execution but it is running for so many times thats why procedure is taking time. Oracle performs 2 type of I/O
1. Physical I/O
This happens when oracle picks up the data blocks from the data file and puts it in the Data buffer (SGA)
2. Logical I/O
This happens when oracle picks up data block from Data buffer (SGA)
In Data Buffer the data is stored in FIFO basis. So when you hit a table for the first time oracle goes for a physical I/O the subsequent time it will go for Logical I/O.
What you are trying to do oracle does it already. You don't have to use a collection. Collection uses expensive private memory (PGA).
And again the basic question is why are you executing a procedure 50,00,000 times?

Similar Messages

  • 10g: parallel pipelined table func. using table(cast(SQL collect.))?

    Hi,
    i try to distribute SQL data objects - stored in a SQL data type TABLE OF <object-Type> - to multiple (parallel) instances of a table function,
    by passing a CURSOR(...) to the table function, which selects from the SQL TABLE OF storage via "select * from TABLE(CAST(<storage> as <storage-type>)".
    But oracle always only uses a single table function instance :-(
    whatever hints i provide or setting i use for the parallel table function (parallel_enable ...)
    Could it be, that this is due to the fact, that my data are not
    globally available, but only in the main thread data?
    Can someone confirm, that it's not possible to start multiple parallel table functions
    for selecting on SQL data type TABLE OF <object>storages?
    Here's an example sqlplus program to show the issue:
    -------------------- snip ---------------------------------------------
    set serveroutput on;
    drop table test_table;
    drop type ton_t;
    drop type test_list;
    drop type test_obj;
    create table test_table
         a number(19,0),
         b timestamp with time zone,
         c varchar2(256)
    create or replace type test_obj as object(
         a number(19,0),
         b timestamp with time zone,
         c varchar2(256)
    create or replace type test_list as table of test_obj;
    create or replace type ton_t as table of number;
    create or replace package test_pkg
    as
         type test_rec is record (
              a number(19,0),
              b timestamp with time zone,
              c varchar2(256)
         type test_tab is table of test_rec;
         type test_cur is ref cursor return test_rec;
         function TF(mycur test_cur)
    return test_list pipelined
    parallel_enable(partition mycur by hash(a));
    end;
    create or replace package body test_pkg
    as
         function TF(mycur test_cur)
    return test_list pipelined
    parallel_enable(partition mycur by hash(a))
    is
              sid number;
              counter number(19,0) := 0;
              myrec test_rec;
              mytab test_tab;
              mytab2 test_list := test_list();
         begin
              select userenv('SID') into sid from dual;
              dbms_output.put_line('test_pkg.TF( sid => '''|| sid || ''' ): enter');
              loop
                   fetch mycur into myRec;
                   exit when mycur%NOTFOUND;
                   mytab2.extend;
                   mytab2(mytab2.last) := test_obj(myRec.a, myRec.b, myRec.c);
              end loop;
              for i in mytab2.first..mytab2.last loop
                   -- attention: saves own SID in test_obj.a for indication to caller
                   --     how many sids have been involved
                   pipe row(test_obj(sid, mytab2(i).b, mytab2(i).c));
                   counter := counter + 1;
              end loop;
              dbms_output.put_line('test_pkg.TF( sid => '''|| sid || ''' ): exit, piped #' || counter || ' records');
         end;
    end;
    declare
         myList test_list := test_list();
         myList2 test_list := test_list();
         sids ton_t := ton_t();
    begin
         for i in 1..10000 loop
              myList.extend; myList(myList.last) := test_obj(i, sysdate, to_char(i+2));
         end loop;
         -- save into the real table
         insert into test_table select * from table(cast (myList as test_list));
         dbms_output.put_line(chr(10) || 'copy ''mylist'' to ''mylist2'' by streaming via table function...');
         select test_obj(a, b, c) bulk collect into myList2
         from table(test_pkg.TF(CURSOR(select /*+ parallel(tab,10) */ * from table(cast (myList as test_list)) tab)));
         dbms_output.put_line('... saved #' || myList2.count || ' records');
         select distinct(tab.a) bulk collect into sids from table(cast (myList2 as test_list)) tab;
         dbms_output.put_line('worker thread''s sid list:');
         for i in sids.first..sids.last loop
              dbms_output.put_line('sid #' || sids(i));
         end loop;
         dbms_output.put_line(chr(10) || 'copy physical ''test_table'' to ''mylist2'' by streaming via table function:');
         select test_obj(a, b, c) bulk collect into myList2
         from table(test_pkg.TF(CURSOR(select /*+ parallel(tab,10) */ * from test_table tab)));
         dbms_output.put_line('... saved #' || myList2.count || ' records');
         select distinct(tab.a) bulk collect into sids from table(cast (myList2 as test_list)) tab;
         dbms_output.put_line('worker thread''s sid list:');
         for i in sids.first..sids.last loop
              dbms_output.put_line('sid #' || sids(i));
         end loop;
    end;
    -------------------- snap ---------------------------------------------
    Here's the output:
    -------------------- snip ---------------------------------------------
    copy 'mylist' to 'mylist2' by streaming via table function...
    test_pkg.TF( sid => '98' ): enter
    test_pkg.TF( sid => '98' ): exit, piped #10000 records
    ... saved #10000 records
    worker thread's sid list:
    sid #98 -- ONLY A SINGLE SID HERE!
    copy physical 'test_table' to 'mylist2' by streaming via table function:
    ... saved #10000 records
    worker thread's sid list:
    sid #128 -- A LIST OF SIDS HERE!
    sid #141
    sid #85
    sid #125
    sid #254
    sid #101
    sid #124
    sid #109
    sid #142
    sid #92
    PL/SQL procedure successfully completed.
    -------------------- snap ---------------------------------------------
    I posted it to newsgroup comp.databases.oracle.server.
    (summary: "10g: parallel pipelined table functions with cursor selecting from table(cast(SQL collection)) doesn't work ")
    But i didn't get a response.
    There i also wrote some background information about my application:
    -------------------- snip ---------------------------------------------
    My application has a #2 steps/stages data selection.
    A 1st select for minimal context base data
    - mainly to evaluate for due driving data records.
    And a 2nd select for all the "real" data to process a context
    (joining much more other tables here, which i don't want to do for non-due records).
    So it's doing stage #1 select first, then stage #2 select - based on stage #1 results - next.
    The first implementation of the application did the stage #1 select in the main session of the pl/sql code.
    And for the stage #2 select there was done a dispatch to multiple parallel table functions (in multiple worker sessions) for the "real work".
    That worked.
    However there was a flaw:
    Between records from stage #1 selection and records from stage #2 selection there is a 1:n relation (via key / foreign key relation).
    Means, for #1 resulting record from stage #1 selection, there are #x records from stage #2 selection.
    That forced me to use "cluster curStage2 by (theKey)".
    Because the worker sessions need to evaluate the all-over status for a context of #1 record from stage #1 and #x records from stage #2
    (so it needs to have #x records of stage #2 together).
    This then resulted in delay for starting up the worker sessions (i didn't find a way to get rid of this).
    So i wanted to shift the invocation of the worker sessions to the stage #1 selection.
    Then i don't need the "cluster curStage2 by (theKey)" anymore!
    But: i also need to do an update of the primary driving data!
    So the stage #1 select is a 'select ... for update ...'.
    But you can't use such in CURSOR for table functions (which i can understand, why it's not possible).
    So i have to do my stage #1 selection in two steps:
    1. 'select for update' by main session and collect result in SQL collection.
    2. pass collected data to parallel table functions
    And for 2. i recognized, that it doesn't start up multiple parallel table function instances.
    As a work-around
    - if it's just not possible to start multiple parallel pipelined table functions for dispatching from 'select * from TABLE(CAST(... as ...))' -
    i need to select again on the base tables - driven by the SQL collection data.
    But before i do so, i wanted to verify, if it's really not possible.
    Maybe i just miss a special oracle hint or whatever you can get "out of another box" :-)
    -------------------- snap ---------------------------------------------
    - many thanks!
    rgds,
    Frank

    Hi,
    i try to distribute SQL data objects - stored in a SQL data type TABLE OF <object-Type> - to multiple (parallel) instances of a table function,
    by passing a CURSOR(...) to the table function, which selects from the SQL TABLE OF storage via "select * from TABLE(CAST(<storage> as <storage-type>)".
    But oracle always only uses a single table function instance :-(
    whatever hints i provide or setting i use for the parallel table function (parallel_enable ...)
    Could it be, that this is due to the fact, that my data are not
    globally available, but only in the main thread data?
    Can someone confirm, that it's not possible to start multiple parallel table functions
    for selecting on SQL data type TABLE OF <object>storages?
    Here's an example sqlplus program to show the issue:
    -------------------- snip ---------------------------------------------
    set serveroutput on;
    drop table test_table;
    drop type ton_t;
    drop type test_list;
    drop type test_obj;
    create table test_table
         a number(19,0),
         b timestamp with time zone,
         c varchar2(256)
    create or replace type test_obj as object(
         a number(19,0),
         b timestamp with time zone,
         c varchar2(256)
    create or replace type test_list as table of test_obj;
    create or replace type ton_t as table of number;
    create or replace package test_pkg
    as
         type test_rec is record (
              a number(19,0),
              b timestamp with time zone,
              c varchar2(256)
         type test_tab is table of test_rec;
         type test_cur is ref cursor return test_rec;
         function TF(mycur test_cur)
    return test_list pipelined
    parallel_enable(partition mycur by hash(a));
    end;
    create or replace package body test_pkg
    as
         function TF(mycur test_cur)
    return test_list pipelined
    parallel_enable(partition mycur by hash(a))
    is
              sid number;
              counter number(19,0) := 0;
              myrec test_rec;
              mytab test_tab;
              mytab2 test_list := test_list();
         begin
              select userenv('SID') into sid from dual;
              dbms_output.put_line('test_pkg.TF( sid => '''|| sid || ''' ): enter');
              loop
                   fetch mycur into myRec;
                   exit when mycur%NOTFOUND;
                   mytab2.extend;
                   mytab2(mytab2.last) := test_obj(myRec.a, myRec.b, myRec.c);
              end loop;
              for i in mytab2.first..mytab2.last loop
                   -- attention: saves own SID in test_obj.a for indication to caller
                   --     how many sids have been involved
                   pipe row(test_obj(sid, mytab2(i).b, mytab2(i).c));
                   counter := counter + 1;
              end loop;
              dbms_output.put_line('test_pkg.TF( sid => '''|| sid || ''' ): exit, piped #' || counter || ' records');
         end;
    end;
    declare
         myList test_list := test_list();
         myList2 test_list := test_list();
         sids ton_t := ton_t();
    begin
         for i in 1..10000 loop
              myList.extend; myList(myList.last) := test_obj(i, sysdate, to_char(i+2));
         end loop;
         -- save into the real table
         insert into test_table select * from table(cast (myList as test_list));
         dbms_output.put_line(chr(10) || 'copy ''mylist'' to ''mylist2'' by streaming via table function...');
         select test_obj(a, b, c) bulk collect into myList2
         from table(test_pkg.TF(CURSOR(select /*+ parallel(tab,10) */ * from table(cast (myList as test_list)) tab)));
         dbms_output.put_line('... saved #' || myList2.count || ' records');
         select distinct(tab.a) bulk collect into sids from table(cast (myList2 as test_list)) tab;
         dbms_output.put_line('worker thread''s sid list:');
         for i in sids.first..sids.last loop
              dbms_output.put_line('sid #' || sids(i));
         end loop;
         dbms_output.put_line(chr(10) || 'copy physical ''test_table'' to ''mylist2'' by streaming via table function:');
         select test_obj(a, b, c) bulk collect into myList2
         from table(test_pkg.TF(CURSOR(select /*+ parallel(tab,10) */ * from test_table tab)));
         dbms_output.put_line('... saved #' || myList2.count || ' records');
         select distinct(tab.a) bulk collect into sids from table(cast (myList2 as test_list)) tab;
         dbms_output.put_line('worker thread''s sid list:');
         for i in sids.first..sids.last loop
              dbms_output.put_line('sid #' || sids(i));
         end loop;
    end;
    -------------------- snap ---------------------------------------------
    Here's the output:
    -------------------- snip ---------------------------------------------
    copy 'mylist' to 'mylist2' by streaming via table function...
    test_pkg.TF( sid => '98' ): enter
    test_pkg.TF( sid => '98' ): exit, piped #10000 records
    ... saved #10000 records
    worker thread's sid list:
    sid #98 -- ONLY A SINGLE SID HERE!
    copy physical 'test_table' to 'mylist2' by streaming via table function:
    ... saved #10000 records
    worker thread's sid list:
    sid #128 -- A LIST OF SIDS HERE!
    sid #141
    sid #85
    sid #125
    sid #254
    sid #101
    sid #124
    sid #109
    sid #142
    sid #92
    PL/SQL procedure successfully completed.
    -------------------- snap ---------------------------------------------
    I posted it to newsgroup comp.databases.oracle.server.
    (summary: "10g: parallel pipelined table functions with cursor selecting from table(cast(SQL collection)) doesn't work ")
    But i didn't get a response.
    There i also wrote some background information about my application:
    -------------------- snip ---------------------------------------------
    My application has a #2 steps/stages data selection.
    A 1st select for minimal context base data
    - mainly to evaluate for due driving data records.
    And a 2nd select for all the "real" data to process a context
    (joining much more other tables here, which i don't want to do for non-due records).
    So it's doing stage #1 select first, then stage #2 select - based on stage #1 results - next.
    The first implementation of the application did the stage #1 select in the main session of the pl/sql code.
    And for the stage #2 select there was done a dispatch to multiple parallel table functions (in multiple worker sessions) for the "real work".
    That worked.
    However there was a flaw:
    Between records from stage #1 selection and records from stage #2 selection there is a 1:n relation (via key / foreign key relation).
    Means, for #1 resulting record from stage #1 selection, there are #x records from stage #2 selection.
    That forced me to use "cluster curStage2 by (theKey)".
    Because the worker sessions need to evaluate the all-over status for a context of #1 record from stage #1 and #x records from stage #2
    (so it needs to have #x records of stage #2 together).
    This then resulted in delay for starting up the worker sessions (i didn't find a way to get rid of this).
    So i wanted to shift the invocation of the worker sessions to the stage #1 selection.
    Then i don't need the "cluster curStage2 by (theKey)" anymore!
    But: i also need to do an update of the primary driving data!
    So the stage #1 select is a 'select ... for update ...'.
    But you can't use such in CURSOR for table functions (which i can understand, why it's not possible).
    So i have to do my stage #1 selection in two steps:
    1. 'select for update' by main session and collect result in SQL collection.
    2. pass collected data to parallel table functions
    And for 2. i recognized, that it doesn't start up multiple parallel table function instances.
    As a work-around
    - if it's just not possible to start multiple parallel pipelined table functions for dispatching from 'select * from TABLE(CAST(... as ...))' -
    i need to select again on the base tables - driven by the SQL collection data.
    But before i do so, i wanted to verify, if it's really not possible.
    Maybe i just miss a special oracle hint or whatever you can get "out of another box" :-)
    -------------------- snap ---------------------------------------------
    - many thanks!
    rgds,
    Frank

  • How to pass parameter to cursor for loop having table type?

    Hi Friends,
    I am wondering how to pass a parameter into second for loop in the example code below.Please see the bold statements and answer my queries.
    Thanks a lot .Here is the code .
    declare
    l_bom_header_tbl BOM_BO_PUB.BOM_HEADER_TBL_TYPE ; ---TABLE TYPE
    V_bom_header_tbl Bom_Bo_Pub.Bom_Head_Rec_Type := Bom_Bo_Pub.G_MISS_BOM_HEADER_REC; ---Record type
    v_bom_components_tbl Bom_Bo_Pub.Bom_Comps_Tbl_Type := Bom_Bo_Pub.G_MISS_BOM_COMPONENT_TBL;---nested table type
    c:=0 number ;
    k:=1 number ;
    begin
    BOMPXINQ.Export_BOM(
    P_org_hierarchy_name => l_org_hierarchy_name,
    P_assembly_item_name => l_assembly_item_name,
    P_organization_code => l_organization_code,
    P_alternate_bm_designator => '1Test',
    P_Costs => l_costs,
    P_Cost_type_id => l_cost_type_id,
    X_bom_header_tbl => l_bom_header_tbl,
    X_bom_revisions_tbl => l_bom_revisions_tbl,
    X_bom_components_tbl => l_bom_components_tbl,
    X_bom_ref_designators_tbl => l_bom_ref_designators_tbl,
    X_bom_sub_components_tbl => l_bom_sub_components_tbl,
    X_bom_comp_ops_tbl => l_bom_comp_ops_tbl,
    X_Err_Msg => l_Err_Msg,
    X_Error_Code => l_Error_Code);
    if l_Error_Code = 0 then
    for i in 1 .. l_bom_header_tbl.COUNT LOOP
    V_bom_header_tbl.organization_code :='DSC';
    Can we assign a table type to record type like below statement?
    V_bom_header_tbl.assembly_item_name:= l_bom_header_tbl(i).assembly_item_name ;
    k:=1;
    I want to pass parameter  l_bom_header_tbl(i).assembly_item_name  into the for statement below: How to achieve this?
    for j in 1 .. l_bom_components_tbl.COUNT LOOP
    Can we assign a table type to table  type like below statement?
    v_bom_components_tbl(k).Assembly_Item_name := l_bom_header_tbl(i).assembly_item_name ;
    k := k + 1;
    end LOOP;
    end loop;
    end;
    Edited by: ILovePlSql on Mar 22, 2010 7:51 AM
    Edited by: ILovePlSql on Mar 22, 2010 8:16 AM

    ILovePlSql wrote:
    V_bom_header_tbl.assembly_item_name:= l_bom_header_tbl(i).assembly_item_name ;
    v_bom_header_tabl is a record type and l_bom_header_tbl is a table type .So is the above statement ok?I asked you for type definition. Please provide definition of BOM_BO_PUB.BOM_HEADER_TBL_TYPE and Bom_Bo_Pub.Bom_Head_Rec_Type. If BOM_BO_PUB.BOM_HEADER_TBL_TYPE is table of Bom_Bo_Pub.Bom_Head_Rec_Type then your statment is OK. For example:
    SQL> declare
      2      type BOM_HEADER_TBL_TYPE is table of emp%rowtype index by binary_integer;
      3      l_bom_header_tbl BOM_HEADER_TBL_TYPE;
      4      V_bom_header_tbl emp%rowtype;
      5  begin
      6      select * bulk collect into l_bom_header_tbl from emp;
      7      for i in 1 .. l_bom_header_tbl.count loop
      8        V_bom_header_tbl.ename := l_bom_header_tbl(i).ename;
      9      end loop;
    10  end;
    11  /
    PL/SQL procedure successfully completed.
    SQL> SY.

  • For Loop in Struts ?(without Collections)

    Hi all,
    Pls tell me how can v use FOR LOOP IN JSP STRUTS without using scriplets and collections .
    suppose i want to display 20 times "hello world "in jsp .How can i display it using STRUTS as conventionally scriplets are not allowed in it.
    and Iterator is only for Collections .
    thanx

    TestBean.java
    * $Id: TestBean.java 54929 2004-10-16 16:38:42Z germuska $
    * Copyright 1999-2004 The Apache Software Foundation.
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
    * http://www.apache.org/licenses/LICENSE-2.0
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    * See the License for the specific language governing permissions and
    * limitations under the License.
    package org.apache.struts.webapp.exercise;
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.Vector;
    import javax.servlet.http.HttpServletRequest;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.util.LabelValueBean;
    * General purpose test bean for Struts custom tag tests.
    * @version $Rev: 54929 $ $Date: 2004-10-16 17:38:42 +0100 (Sat, 16 Oct 2004) $
    public class TestBean extends ActionForm {
    // ------------------------------------------------------------- Properties
    * A collection property where the elements of the collection are
    * of type <code>LabelValueBean</code>.
    private Collection beanCollection = null;
    public Collection getBeanCollection() {
    if (beanCollection == null) {
    Vector entries = new Vector(10);
    entries.add(new LabelValueBean("Label 0", "Value 0"));
    entries.add(new LabelValueBean("Label 1", "Value 1"));
    entries.add(new LabelValueBean("Label 2", "Value 2"));
    entries.add(new LabelValueBean("Label 3", "Value 3"));
    entries.add(new LabelValueBean("Label 4", "Value 4"));
    entries.add(new LabelValueBean("Label 5", "Value 5"));
    entries.add(new LabelValueBean("Label 6", "Value 6"));
    entries.add(new LabelValueBean("Label 7", "Value 7"));
    entries.add(new LabelValueBean("Label 8", "Value 8"));
    entries.add(new LabelValueBean("Label 9", "Value 9"));
    beanCollection = entries;
    return (beanCollection);
    public void setBeanCollection(Collection beanCollection) {
    this.beanCollection = beanCollection;
    * A multiple-String SELECT element using a bean collection.
    private String[] beanCollectionSelect = { "Value 1", "Value 3",
    "Value 5" };
    public String[] getBeanCollectionSelect() {
    return (this.beanCollectionSelect);
    public void setBeanCollectionSelect(String beanCollectionSelect[]) {
    this.beanCollectionSelect = beanCollectionSelect;
    * A boolean property whose initial value is true.
    private boolean booleanProperty = true;
    public boolean getBooleanProperty() {
    return (booleanProperty);
    public void setBooleanProperty(boolean booleanProperty) {
    this.booleanProperty = booleanProperty;
    * A multiple-String SELECT element using a collection.
    private String[] collectionSelect = { "Value 2", "Value 4",
    "Value 6" };
    public String[] getCollectionSelect() {
    return (this.collectionSelect);
    public void setCollectionSelect(String collectionSelect[]) {
    this.collectionSelect = collectionSelect;
    * A double property.
    private double doubleProperty = 321.0;
    public double getDoubleProperty() {
    return (this.doubleProperty);
    public void setDoubleProperty(double doubleProperty) {
    this.doubleProperty = doubleProperty;
    * A boolean property whose initial value is false
    private boolean falseProperty = false;
    public boolean getFalseProperty() {
    return (falseProperty);
    public void setFalseProperty(boolean falseProperty) {
    this.falseProperty = falseProperty;
    * A float property.
    private float floatProperty = (float) 123.0;
    public float getFloatProperty() {
    return (this.floatProperty);
    public void setFloatProperty(float floatProperty) {
    this.floatProperty = floatProperty;
    * Integer arrays that are accessed as an array as well as indexed.
    private int intArray[] = { 0, 10, 20, 30, 40 };
    public int[] getIntArray() {
    return (this.intArray);
    public void setIntArray(int intArray[]) {
    this.intArray = intArray;
    private int intIndexed[] = { 0, 10, 20, 30, 40 };
    public int getIntIndexed(int index) {
    return (intIndexed[index]);
    public void setIntIndexed(int index, int value) {
    intIndexed[index] = value;
    private int intMultibox[] = new int[0];
    public int[] getIntMultibox() {
    return (this.intMultibox);
    public void setIntMultibox(int intMultibox[]) {
    this.intMultibox = intMultibox;
    * An integer property.
    private int intProperty = 123;
    public int getIntProperty() {
    return (this.intProperty);
    public void setIntProperty(int intProperty) {
    this.intProperty = intProperty;
    * A long property.
    private long longProperty = 321;
    public long getLongProperty() {
    return (this.longProperty);
    public void setLongProperty(long longProperty) {
    this.longProperty = longProperty;
    * A multiple-String SELECT element.
    private String[] multipleSelect = { "Multiple 3", "Multiple 5",
    "Multiple 7" };
    public String[] getMultipleSelect() {
    return (this.multipleSelect);
    public void setMultipleSelect(String multipleSelect[]) {
    this.multipleSelect = multipleSelect;
    * A nested reference to another test bean (populated as needed).
    private TestBean nested = null;
    public TestBean getNested() {
    if (nested == null)
    nested = new TestBean();
    return (nested);
    * A String property with an initial value of null.
    private String nullProperty = null;
    public String getNullProperty() {
    return (this.nullProperty);
    public void setNullProperty(String nullProperty) {
    this.nullProperty = nullProperty;
    * A short property.
    private short shortProperty = (short) 987;
    public short getShortProperty() {
    return (this.shortProperty);
    public void setShortProperty(short shortProperty) {
    this.shortProperty = shortProperty;
    * A single-String value for a SELECT element.
    private String singleSelect = "Single 5";
    public String getSingleSelect() {
    return (this.singleSelect);
    public void setSingleSelect(String singleSelect) {
    this.singleSelect = singleSelect;
    * String arrays that are accessed as an array as well as indexed.
    private String stringArray[] =
    { "String 0", "String 1", "String 2", "String 3", "String 4" };
    public String[] getStringArray() {
    return (this.stringArray);
    public void setStringArray(String stringArray[]) {
    this.stringArray = stringArray;
    private String stringIndexed[] =
    { "String 0", "String 1", "String 2", "String 3", "String 4" };
    public String getStringIndexed(int index) {
    return (stringIndexed[index]);
    public void setStringIndexed(int index, String value) {
    stringIndexed[index] = value;
    private String stringMultibox[] = new String[0];
    public String[] getStringMultibox() {
    return (this.stringMultibox);
    public void setStringMultibox(String stringMultibox[]) {
    this.stringMultibox = stringMultibox;
    * A String property.
    private String stringProperty = "This is a string";
    public String getStringProperty() {
    return (this.stringProperty);
    public void setStringProperty(String stringProperty) {
    this.stringProperty = stringProperty;
    * An empty String property.
    private String emptyStringProperty = "";
    public String getEmptyStringProperty() {
    return (this.emptyStringProperty);
    public void setEmptyStringProperty(String emptyStringProperty) {
    this.emptyStringProperty = emptyStringProperty;
    * A single-String value for a SELECT element based on resource strings.
    private String resourcesSelect = "Resources 2";
    public String getResourcesSelect() {
    return (this.resourcesSelect);
    public void setResourcesSelect(String resourcesSelect) {
    this.resourcesSelect = resourcesSelect;
    * A property that allows a null value but is still used in a SELECT.
    private String withNulls = null;
    public String getWithNulls() {
    return (this.withNulls);
    public void setWithNulls(String withNulls) {
    this.withNulls = withNulls;
    * A List property.
    private List listProperty = null;
    public List getListProperty() {
    if (listProperty == null) {
    listProperty = new ArrayList();
    listProperty.add("dummy");
    return listProperty;
    public void setListProperty(List listProperty) {
    this.listProperty = listProperty;
    * An empty List property.
    private List emptyListProperty = null;
    public List getEmptyListProperty() {
    if (emptyListProperty == null) {
    emptyListProperty = new ArrayList();
    return emptyListProperty;
    public void setEmptyListProperty(List emptyListProperty) {
    this.emptyListProperty = emptyListProperty;
    * A Map property.
    private Map mapProperty = null;
    public Map getMapProperty() {
    if (mapProperty == null) {
    mapProperty = new HashMap();
    mapProperty.put("dummy", "dummy");
    return mapProperty;
    public void setMapProperty(Map mapProperty) {
    this.mapProperty = mapProperty;
    * An empty Map property.
    private Map emptyMapProperty = null;
    public Map getEmptyMapProperty() {
    if (emptyMapProperty == null) {
    emptyMapProperty = new HashMap();
    return emptyMapProperty;
    public void setEmptyMapProperty(Map emptyMapProperty) {
    this.emptyMapProperty = emptyMapProperty;
    // --------------------------------------------------------- Public Methods
    * Reset the properties that will be received as input.
    public void reset(ActionMapping mapping, HttpServletRequest request) {
    booleanProperty = false;
    collectionSelect = new String[0];
    intMultibox = new int[0];
    multipleSelect = new String[0];
    stringMultibox = new String[0];
    if (nested != null)
    nested.reset(mapping, request);
    }

  • Cursor scope : cursor is not recognising in for loop.

    CREATE or REPLACE PROCEDURE TEST(
    date3 IN DATE,
    Out_Entity OUT Test1.RefCsr
    AS
    FirstNameListTable LIST_TABLE;
    FinalFirstNameListTable LIST_TABLE := LIST_TABLE();
    firstName employee.first_name%TYPE;
    date1 employee.start_date%TYPE;
    date2 employee.start_date%TYPE;
    CURSOR main_cur
       IS
          WITH include_rec
            AS (select first_name,count(1) over (partition by first_name) firstNameCount,start_date  from employee where city='Vancouver')
    SELECT distinct first_name
            FROM include_rec
           WHERE firstNameCount>500;
    BEGIN
        OPEN main_cur;
        FETCH main_cur BULK COLLECT INTO FirstNameListTable;
        CLOSE main_cur;
    FOR i IN FirstNameListTable.FIRST .. FirstNameListTable.LAST
        LOOP
    firstName:=FirstNameListTable(i);
    SELECT min(start_date),max(start_date) into date1,date2 FROM include_rec where first_name=firstName;
    --business logic
        END LOOP;
    OPEN Out_Entity FOR SELECT * FROM TABLE(
                                                    CAST (
                                                            FinalFirstNameListTable AS LIST_TABLE
                                            ) Nos;
    END;
    create or replace TYPE "LIST_TABLE" as table of varchar2(20);
    SELECT min(start_date),max(start_date) into date1,date2 FROM include_rec where first_name=firstName;In above query, getting error:table or view doesnt exit. When i replaced "include_rec" with "employee",error is resolved.But i have to use include_rec,Because i dont want to query on lage table employee, i know my final query output will be subset of include_rec table.
    Means it is clear that cursor is not recognising in for loop and how can i resolve it?

    Can u please tell me code about "creating permanent object or view." in this context. I don't really want to. This is not a route you should be encouraged to go down.
    A view is the correct mechanism for reusing SQL. So I just mean:
    CREATE OR REPLACE VIEW include_rec AS
    select first_name,count(1) over (partition by first_name) firstNameCount,start_date  from employee where city='Vancouver';Then you get rid of "WITH include_rec AS ()..." from both statements.
    But this is pants.
    Surely all this should just be:
    CREATE or REPLACE PROCEDURE TEST (
      date3 IN DATE,
      Out_Entity OUT Test1.RefCsr
    AS
    BEGIN
      OPEN Out_Entity FOR
        SELECT first_name, count(*), min(start_date), max(start_date)
        FROM   include_rec
        WHERE  employee
        GROUP BY first_name
        HAVING COUNT(*) > 500;
    END;
    /

  • Open cursor for a nested table

    Hi,
    I want to open a cursor like:
    open c1 for select * from emp;
    BUT
    I what the cursor results to be populated with contents of a nested table or associative array..
    How can this be done???
    Thanks in advance,
    teo

    Well, given a variable YOUR_EMP of nested table type EMP_NT it could be as simple as
    open c1 for select * from TABLE( CAST(your_emp AS emp_nt));Cheers, APC

  • Table cast PL/SQL: ORA-00902: invalid datatype

    I m getting
    PL/SQL: ORA-00902: invalid datatype
    error in
    OPEN pPymtCur FOR
    SELECT *
    FROM TABLE(CAST( up_gap_tra_reports.myArray AS traArray));
    in my package up_gap_tra_reports.
    CREATE OR REPLACE PACKAGE GAPSDVEL.up_gap_tra_reports
    AS
    TYPE traRecord IS RECORD
    group1StudEnrol NUMBER(6,1),
    group2StudEnrol NUMBER(6,1),
    pymtAmt gap_payment.NET_AMT%TYPE
    TYPE traArray IS TABLE OF traRecord;
    myArray traArray := traArray() ;
    END up_gap_tra_reports;
    I hv alreay declared traArray type.
    pls help me to solve this.

    Meghna wrote:
    is there any way to use pl/sql collection in SQL or refcur without creating it because i am not able to create type in database.The only way I am aware of is pipelined function:
    create or replace
      package pkg1
        is
          type traRecord
            is record(
                      ename emp.ename%type,
                      sal   emp.sal%type
          TYPE traArray IS TABLE OF traRecord;
          function f1
            return traArray
            pipelined;
    end;
    create or replace
      package body pkg1
        is
        function f1
            return traArray
            pipelined
          is
              v_rec traRecord;
          begin
              v_rec.ename := 'Sam';
              v_rec.sal := 1000;
              pipe row(v_rec);
              v_rec.ename := 'John';
              v_rec.sal := 1500;
              pipe row(v_rec);
              v_rec.ename := 'Mary';
              v_rec.sal := 2000;
              pipe row(v_rec);
              return;
        end;
    end;
    /Now you can:
    SQL> select * from table(pkg1.f1)
      2  /
    ENAME             SAL
    Sam              1000
    John             1500
    Mary             2000
    SQL>Keep in mind, it will create system generated types:
    SQL> select type_name from user_types
      2  /
    TYPE_NAME
    SYS_PLSQL_73305_9_1
    SYS_PLSQL_73305_DUMMY_1
    SYS_PLSQL_73305_34_1
    SQL> desc SYS_PLSQL_73305_9_1
    Name                                      Null?    Type
    ENAME                                              VARCHAR2(10)
    SAL                                                NUMBER(7,2)
    SQL> desc SYS_PLSQL_73305_DUMMY_1
    SYS_PLSQL_73305_DUMMY_1 TABLE OF NUMBER
    SQL> desc SYS_PLSQL_73305_34_1
    SYS_PLSQL_73305_34_1 TABLE OF SYS_PLSQL_73305_9_1
    Name                                      Null?    Type
    ENAME                                              VARCHAR2(10)
    SAL                                                NUMBER(7,2)
    SQL> SY.

  • Open sys_refcursor for select from table variable?

    Hi,
    I've got a challenge for you! :-)
    I've got a procedure that has a lot of logic to determine what data should be loaded into a table variable. Because of various application constraints, i can not create a global temporary table. Instead, i'd like to create a table variable and populate it with stuff as i go through the procedure.
    The end result of the procedure is that i must be able to pass the results back as a sys_refcursor. This is a requirement that is beyond my control as well.
    Is there a way to make this sort of procedure work?
    Create Or Replace Procedure Xtst
    Mu_Cur In Out Sys_Refcursor
    Is
    Type Xdmlrectype Is Record (Col1 Varchar2(66));
    Type Xdmltype Is Table Of Xdmlrectype;
    Rtn Xdmltype;
    Begin
    Select Internal_Id Bulk Collect Into Rtn From Zc_State;
    open mu_cur for select col1 from table(rtn);
    end;
    11/42 PLS-00642: local collection types not allowed in SQL statements
    11/36 PL/SQL: ORA-22905: cannot access rows from a non-nested table item
    11/19 PL/SQL: SQL Statement ignored
    Show Errors;

    Not anything i'd want to personally implement.
    But for educational purposes only of course....
    create table this_will_be_gross
       column1 number,
       column2 varchar2(30)
    insert into this_will_be_gross values (1, 'begin the ugliness');
    insert into this_will_be_gross values (2, 'end the ugliness');
    variable x refcursor;
    ME_XE?
    declare
       Rtn sys.ODCIVARCHAR2LIST;
    BEGIN
       SELECT
          column1 || '-' || column2 Bulk Collect
       INTO
          Rtn
       FROM
          this_will_be_gross;
       OPEN :x FOR
       SELECT 
          regexp_substr (column_value, '[^-]+', 1, 1) as column1,
          regexp_substr (column_value, '[^-]+', 1, 2) as column2      
       FROM TABLE(CAST(rtn AS sys.ODCIVARCHAR2LIST));
    end;
    17  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.09
    ME_XE?
    ME_XE?print :x
    COLUMN1                        COLUMN2
    1                              begin the ugliness
    2                              end the ugliness
    2 rows selected.
    Elapsed: 00:00:00.11In the above example i 'knew' that a hypen was a safe character to use to break up my data elements (as it would not be found anywhere in the data itself).
    I would strongly encourage you not to implement something like this. I realize it's tempting when you are working in strict environments where it can take a serious battle to get structures like temporary tables or SQL Types created, but that's really the proper approach to be taking.

  • Which is more (faster) performance oriented? Collections or Cursor For Loop

    Hi,
    Please help me regarding a dilemma.
    Is, using a Cursor For Loop faster than a loop run upon a collection variable that was being populated using bulk collect? Why?
    Thanks in advance
    rollerz

    You can just test it by yourself. Can’t you? Ok I was bit curious to know myself so I did this…
    TEST ROUND 1
    SQL> declare
      2     ltime integer;
      3  begin
      4     ltime := dbms_utility.get_time;
      5
      6     for i in (select level from dual connect by level <= 100000)
      7     loop
      8             null;
      9     end loop;
    10
    11     ltime := dbms_utility.get_time - ltime;
    12     dbms_output.put_line('ExecTime:'||ltime/100||' seconds...');
    13  end;
    14  /
    ExecTime:.19 seconds...
    PL/SQL procedure successfully completed.
    SQL> declare
      2     ltime integer;
      3     type my_type is table of integer;
      4     lType my_type;
      5  begin
      6     ltime := dbms_utility.get_time;
      7     select level bulk collect into lType from dual connect by level <= 100000;
      8
      9     for i in 1..lType.count
    10     loop
    11             null;
    12     end loop;
    13
    14     ltime := dbms_utility.get_time - ltime;
    15     dbms_output.put_line('ExecTime:'||ltime/100||' seconds...');
    16  end;
    17  /
    ExecTime:.14 seconds...
    PL/SQL procedure successfully completed.
    TEST ROUND 2
    SQL> declare
      2     ltime integer;
      3  begin
      4     ltime := dbms_utility.get_time;
      5
      6     for i in (select level from dual connect by level <= 100000)
      7     loop
      8             null;
      9     end loop;
    10
    11     ltime := dbms_utility.get_time - ltime;
    12     dbms_output.put_line('ExecTime:'||ltime/100||' seconds...');
    13  end;
    14  /
    ExecTime:.17 seconds...
    PL/SQL procedure successfully completed.
    SQL> declare
      2     ltime integer;
      3     type my_type is table of integer;
      4     lType my_type;
      5  begin
      6     ltime := dbms_utility.get_time;
      7     select level bulk collect into lType from dual connect by level <= 100000;
      8
      9     for i in 1..lType.count
    10     loop
    11             null;
    12     end loop;
    13
    14     ltime := dbms_utility.get_time - ltime;
    15     dbms_output.put_line('ExecTime:'||ltime/100||' seconds...');
    16  end;
    17  /
    ExecTime:.13 seconds...
    TEST ROUND 3
    PL/SQL procedure successfully completed.
    SQL> declare
      2     ltime integer;
      3  begin
      4     ltime := dbms_utility.get_time;
      5
      6     for i in (select level from dual connect by level <= 100000)
      7     loop
      8             null;
      9     end loop;
    10
    11     ltime := dbms_utility.get_time - ltime;
    12     dbms_output.put_line('ExecTime:'||ltime/100||' seconds...');
    13  end;
    14  /
    ExecTime:.16 seconds...
    PL/SQL procedure successfully completed.
    SQL> declare
      2     ltime integer;
      3     type my_type is table of integer;
      4     lType my_type;
      5  begin
      6     ltime := dbms_utility.get_time;
      7     select level bulk collect into lType from dual connect by level <= 100000;
      8
      9     for i in 1..lType.count
    10     loop
    11             null;
    12     end loop;
    13
    14     ltime := dbms_utility.get_time - ltime;
    15     dbms_output.put_line('ExecTime:'||ltime/100||' seconds...');
    16  end;
    17  /
    ExecTime:.13 seconds...
    TEST ROUND 4
    PL/SQL procedure successfully completed.
    SQL> declare
      2     ltime integer;
      3  begin
      4     ltime := dbms_utility.get_time;
      5
      6     for i in (select level from dual connect by level <= 100000)
      7     loop
      8             null;
      9     end loop;
    10
    11     ltime := dbms_utility.get_time - ltime;
    12     dbms_output.put_line('ExecTime:'||ltime/100||' seconds...');
    13  end;
    14  /
    ExecTime:.16 seconds...
    PL/SQL procedure successfully completed.
    SQL> declare
      2     ltime integer;
      3     type my_type is table of integer;
      4     lType my_type;
      5  begin
      6     ltime := dbms_utility.get_time;
      7     select level bulk collect into lType from dual connect by level <= 100000;
      8
      9     for i in 1..lType.count
    10     loop
    11             null;
    12     end loop;
    13
    14     ltime := dbms_utility.get_time - ltime;
    15     dbms_output.put_line('ExecTime:'||ltime/100||' seconds...');
    16  end;
    17  /
    ExecTime:.13 seconds...
    PL/SQL procedure successfully completed.So bulk collect looks faster...
    Thanks,
    Karthick.

  • Nested for loop in the collections

    Hi Experts,
    collection1
    ============
    SELECT o.object_id
          BULK COLLECT INTO l_obj_info
            FROM (SELECT     n.node_id, n.object_id
                        FROM nodes n
                  START WITH n.node_id = 100
                  CONNECT BY PRIOR n.node_id = n.parent_node_id) n
                 INNER JOIN
                 objects o ON n.object_id = o.object_id
           WHERE o.object_type_id = 285;
    collection2
    ============
    SELECT *
          BULK COLLECT INTO l_tab
            FROM ((SELECT     REGEXP_SUBSTR (i_l_text, '[^,]+', 1, LEVEL)
                         FROM DUAL
                   CONNECT BY REGEXP_SUBSTR (i_l_text, '[^,]+', 1, LEVEL) IS NOT NULL));
       END;
    collection3
    ============
    SELECT o.object_id
                   BULK COLLECT INTO l_fin_tab
                     FROM objects o JOIN ATTRIBUTES att
                          ON o.object_id = att.object_id
                    WHERE o.object_id = collection1.object_id
                      --AND att.VALUE = collection2.val;
    Please tell me how to implement for loop in the collection3 to get the values from collection1 and collection2.
    i have tried in the below way
    CREATE OR REPLACE TYPE LIST_OF_ATTRIBUTES_TYPE AS TABLE OF varchar2(4000);
    CREATE OR REPLACE TYPE LIST_OF_OBJECT_IDS_TYPE AS TABLE OF number(9);
    CREATE OR REPLACE FUNCTION f_get_objects_by_type_id (
       i_object_type_id   IN   NUMBER,
       i_l_text           IN   VARCHAR2,
       i_scope_node_id         NUMBER
       RETURN list_of_object_ids_type
    AS
       CURSOR objs_info
       IS
          SELECT o.object_id
            FROM (SELECT     n.node_id, n.object_id
                        FROM nodes n
                  START WITH n.node_id = i_scope_node_id
                  CONNECT BY PRIOR n.node_id = n.parent_node_id) n
                 INNER JOIN
                 objects o ON n.object_id = o.object_id
           WHERE o.object_type_id = i_object_type_id;
       l_tab       list_of_attributes_type := list_of_attributes_type ();
       --l_obj_info   list_of_object_ids_type := list_of_object_ids_type ();
       l_fin_tab   list_of_object_ids_type := list_of_object_ids_type ();
    BEGIN
       BEGIN
          SELECT *
          BULK COLLECT INTO l_tab
            FROM ((SELECT     trREGEXP_SUBSTR (i_l_text, '[^,]+', 1, LEVEL)
                         FROM DUAL
                   CONNECT BY REGEXP_SUBSTR (i_l_text, '[^,]+', 1, LEVEL) IS NOT NULL));
       END;
       IF l_tab.COUNT > 0
       THEN
          FOR i IN objs_info
          LOOP
             FOR j IN l_tab.FIRST .. l_tab.LAST
             LOOP
                SELECT o.object_id
                BULK COLLECT INTO l_fin_tab
                  FROM objects o JOIN ATTRIBUTES att ON o.object_id =
                                                                     att.object_id
                 WHERE
                                att.VALUE = l_tab (j) and o.object_id =objs_info(i);
             END LOOP;
          END LOOP;
       END IF;
       RETURN l_fin_tab;
    END f_get_objects_by_type_id;

    Why are you wanting to do this?
    It looks like you are trying to implement SQL joins in PL code.  Not only is that using up expensive PGA memory by storing the data in collections, but doing such retrieval of data to try and join it in PL loops, is never going to be as fast as just joining the SQL queries using SQL itself.
    Post some example data and your database version, with an example of what the output should look like from that example data.
    Re: 2. How do I ask a question on the forums?

  • Cursor for loop vs bind variable efficiency

    PL/SQL
    I am going to need to execute many sqls within a cursor for loop.
    Note: This is pseudo pl/sql code
    for csr_rec in cursor
    loop
    insert into tablea
    select [whateever] from tableb
    where column_name = csr_rec.field
    versus
    execute immediate
    'insert into table a select ... where column_name = :1' using csr_rec.field
    So the question is whether the first insert statement will be treated as a separate sql statement and need to be parsed each iteration? If so, then I'd likely be much better of using the bind variable approach. (2nd) insert statement.
    Thanks!

    The first statement (static) will be re-used - PL/SQL variables (csr_rec.field in this case) will be used as a bind variable.

  • Creating variables using for loop

    is there any way in java to create a variable called "xi" using a for loop say:
    for (int i =0; i < 1000000;i++){
      int xi;
    }so I want to create a million of different variable names based on the i... I know this may be a stupid question

    I don't think there is a way to do this. More importantly why do you want to do this? If you dynamically generate 1 million variables, then how will the rest of your program refer to them? Maybe what you need is some sort of collection.

  • Bulk collect usage in cursor for loop

    Hi Team,
    I have one cursor like below assuming cursor is having 3000 records,
    CURSOR csr_del_frm_stg(c_source_name VARCHAR2 , c_file_type VARCHAR2)
    IS
    SELECT stg.last_name,stg.employee_number,stg.email
    FROM akam_int.xxak_eb_contact_stg stg
    MINUS
    SELECT ss.last_name,ss.employee_number,ss.email
    FROM akam_int.xxak_eb_contact_stg_ss ss;
    I declared one record type variable as,
    TYPE emp_rec IS RECORD (LAST_NAME             VARCHAR2(40)
    *,EMPLOYEE_NUMBER VARCHAR2(50)*
    *,EMAIL VARCHAR2(80)*
    TYPE emp_rec_ss IS VARRAY(3000) OF emp_rec;
    Im updating the status of those cursor records to 'C' in the below for loop,
    FOR l_csr_del_frm_stg IN csr_del_frm_stg(p_source_name , p_file_type)
    LOOP
    FETCH csr_del_frm_stg BULK COLLECT INTO emp_rec_ss LIMIT 500;
    FORALL i IN emp_rec_ss.FIRST..emp_rec_ss.LAST
    UPDATE akam_int.xxak_eb_contact_stg stg
    SET akam_status_flag    = 'C'
    WHERE stg.employee_number = emp_rec_ss(i).employee_number;
    EXIT WHEN csr_del_frm_stg%NOTFOUND;
    END LOOP;
    Getting following errors if i compile the code,
    PLS-00321: expression 'EMP_REC_SS' is inappropriate as the left hand side of an assignment statement
    PLS-00302: component 'FIRST' must be declared

    Use cursor variables:
    declare
        v_where varchar2(100) := '&where_clause';
        v_cur sys_refcursor;
        v_ename varchar2(30);
    begin
        open v_cur for 'select ename from emp where ' || v_where;
        loop
          fetch v_cur into v_ename;
          exit when v_cur%notfound;
          dbms_output.put_line(v_ename);
        end loop;
        close v_cur;
    end;
    Enter value for where_clause: deptno = 10
    CLARK
    KING
    MILLER
    PL/SQL procedure successfully completed.
    SQL> /
    Enter value for where_clause: sal = 5000
    KING
    PL/SQL procedure successfully completed.
    SQL> /
    Enter value for where_clause: job = ''CLERK''
    SMITH
    ADAMS
    JAMES
    MILLER
    PL/SQL procedure successfully completed.
    SQL>  SY.

  • Multiplication Table with Two Nested For Loops

    I am trying to code a multiplication table in which the user enters the number of rows between 2 and 10 and enters the number of columns from 2 to 10. This must be in nested for loop format somewhat like this:
    rows has been assigned the input variable for rows and columns is the name for input value for columns
    for (int i = 1; i <=rows; i++)
    for (int j = 1; j <=columns; j++)
    i * j
    i can't figure out how to get it to print out in table format or if the calculation coding is correct. can anyone help me please?
    it should look like this for rows is 4 and columns is 7
    1 2 3 4 5 6 7
    2 4 6 8 10 12 14
    3 6 9 12 15 18 21
    4 8 12 16 20 24 28
    Edited by: hatecodingsomuch on Feb 22, 2009 8:15 PM

    hatecodingsomuch wrote:
    I refuse to ask for help from people who are acting like they are all-knowing and unwilling to help someone, considering I am asking for help...to learn. Obviously I am not understanding java very well and I don't need to be ridiculed like this from members who are supposed to help "NEW TO JAVA" individuals. Get off your high horse or get off the website. I will never use this again.Good luck with that.
    You do seem to be yet another "do my homework for me" type of flunkie. I predict you'll soon have an epiphany that software development really isn't for you.
    I hope you know how to say "Do you want fries with that, sir?" better than the next guy so you can edge him out.

  • FOR LOOP cursor that updates table A based on a value in table B

    Hi,
    I need a FOR LOOP cursor that scans and updates all pro-rata column in table EMPLOYEE(child) based on what pay classification all employees are on in the CLASSIFICATION(parent) table.
    DECLARE
    BEGIN
    IF employee.emp_type = 'FT' THEN
    UPDATE employee
    SET employee.pro_rata = ((classification.yearly_pay/52)*52)
    WHERE employee.empid = v_empid AND classification.class_id = employee.class_id;
    END IF;
    IF employee.emp_type = 'PT1' THEN
    UPDATE employee
    SET employee.pro_rata = ((classification.yearly_pay/39)*52)
    WHERE employee.empid = v_empid AND classification.class_id = employee.class_id;
    END IF;
    IF employee.emp_type = 'PT2' THEN
    UPDATE employee
    SET employee.pro_rata = ((classification.yearly_pay/21)*52)
    WHERE employee.empid = v_empid AND classification.class_id = employee.class_id;
    END IF;
    END;
    How do I create a cursor that cuts across these two table
    See tables and data
    CREATE TABLE CLASSIFICATION(
    CLASS_ID VARCHAR2(6) NOT NULL,
    CLASS_TYPE VARCHAR2(10),
    DESCRIPTION VARCHAR2(30) NOT NULL,
    YEARLY_PAY NUMBER(8),
    HOURLY_RATE NUMBER,
    WEEKDAY_OVER_TIME NUMBER,
    WEEKEND_OVER_TIME NUMBER,
    CONSTRAINT PK_CLASS_ID PRIMARY KEY (CLASS_ID));
    INSERT INTO CLASSIFICATION VALUES('PR1','PERMANENT','MANAGER',45000,'','',NULL);
    INSERT INTO CLASSIFICATION VALUES('PR2','PERMANENT','ADMIN ASSISTANT',22000,'',1.5,NULL);
    INSERT INTO CLASSIFICATION VALUES('PR3','PERMANENT','CONTROLLER',32000,'',1.5,NULL);
    INSERT INTO CLASSIFICATION VALUES('PR4','PERMANENT','CASH OFFICER',22000,'',1.5,NULL);
    INSERT INTO CLASSIFICATION VALUES('PR5','PERMANENT','CLEANERS',16000,'',1.5,NULL);
    INSERT INTO CLASSIFICATION VALUES('PR6','PERMANENT','ADMIN OFFICER',22000,'',1.5,NULL);
    INSERT INTO CLASSIFICATION VALUES('PR7','PERMANENT','WAREHOUSE ATTENDANT',20000,'',1.5,NULL);
    INSERT INTO CLASSIFICATION VALUES('PR8','PERMANENT','WINDOWS DRESSER',22000,'',1.5,NULL);
    INSERT INTO CLASSIFICATION VALUES('PR9','PERMANENT','DIRECTOR',60000,'','',NULL);
    INSERT INTO CLASSIFICATION VALUES('PR10','PERMANENT','DEPUTY DIRECTOR',52000,'','',NULL);
    INSERT INTO CLASSIFICATION VALUES('PR11','PERMANENT','SALES ASSISTANT',21000,'',1.5,NULL);
    INSERT INTO CLASSIFICATION VALUES('TEMP2','TEMP STAFF','ADMIN ASSISTANT','',16.50,'',NULL);
    INSERT INTO CLASSIFICATION VALUES('TEMP3','TEMP STAFF','CONTROLLER','',29.00,'',NULL);
    INSERT INTO CLASSIFICATION VALUES('TEMP4','TEMP STAFF','CASH OFFICER','',19.00,'',NULL);
    INSERT INTO CLASSIFICATION VALUES('TEMP5','TEMP STAFF','CLEANERS','',10.00,'',NULL);
    INSERT INTO CLASSIFICATION VALUES('TEMP6','TEMP STAFF','ADMIN OFFICER','',20.00,'',NULL);
    INSERT INTO CLASSIFICATION VALUES('TEMP7','TEMP STAFF','WAREHOUSE ATTENDANT','',18.00,'',NULL);
    INSERT INTO CLASSIFICATION VALUES('TEMP8','TEMP STAFF','WINDOWS DRESSER','',18.50,'',NULL);
    INSERT INTO CLASSIFICATION VALUES('TEMP11','TEMP STAFF','SALES ASSISTANT','',16.00,'',NULL);
    CREATE TABLE EMPLOYEE(
    EMPID NUMBER(5) NOT NULL,
    SURNAME VARCHAR2(30) NOT NULL,
    FNAME VARCHAR2(30) NOT NULL,
    GENDER CHAR(1) NOT NULL,
    DOB DATE NOT NULL,
    EMP_TYPE VARCHAR2(20) NOT NULL,
    ANNUAL_WEEKS_REQD NUMBER(2),
    PRO_RATA_WAGES NUMBER(7,2),
    HOLIDAY_ENTLMENT NUMBER(2),
    SICK_LEAVE_ENTLMENT NUMBER(2),
    HIRE_DATE DATE NOT NULL,
    END_DATE DATE,
    ACCNO NUMBER(8) NOT NULL,
    BANKNAME VARCHAR2(20) NOT NULL,
    BRANCH VARCHAR2(20) NOT NULL,
    ACCOUNTNAME VARCHAR2(20),
    CLASS_ID VARCHAR2(6),
    CONSTRAINT CK_HIRE_END CHECK (HIRE_DATE < END_DATE),
    CONSTRAINT CK_HIRE_DOB CHECK (HIRE_DATE >= ADD_MONTHS(DOB, 12 * 18)),
    CONSTRAINT CK_EMP_TYPE CHECK (EMP_TYPE IN ('FT','PT1','PT2','PT3','HOURLY')),
    CONSTRAINT CK_EMP_GENDER CHECK (GENDER IN ('M','F')),
    CONSTRAINT FK_EMP_CLASS FOREIGN KEY (CLASS_ID) REFERENCES CLASSIFICATION(CLASS_ID),
    CONSTRAINT PK_EMP PRIMARY KEY (EMPID));
    CREATE SEQUENCE SEQ_EMPID START WITH 1;
    INSERT INTO EMPLOYEE VALUES(
    SEQ_EMPID.NEXTVAL,'RICHARD','BRANDON','M','25-DEC-1966','FT',52,22000.00,28,14,'10-JAN-2005',NULL,90823227,'NATWEST','BROMLEY','DEPOSIT','PR2');
    INSERT INTO EMPLOYEE VALUES(
    SEQ_EMPID.NEXTVAL,'BOYCE','CODD','M','15-JAN-1972','PT1','','','','','12-JAN-2005',NULL,72444091,'LLOYDS','KENT','CURRENT','PR8');
    INSERT INTO EMPLOYEE VALUES(
    SEQ_EMPID.NEXTVAL,'ALHAJA','BROWN','F','20-MAY-1970','HOURLY','','','','','21-JUN-2000',NULL,09081900,'ABBEY','ESSEX','CURRENT','TEMP2');
    INSERT INTO EMPLOYEE VALUES(
    SEQ_EMPID.NEXTVAL,'RON','ATKINSON','M','10-AUG-1955','PT3','','','','','12-JAN-2005','26-MAR-2006',01009921,'HALIFAX','KENT','SAVINGS','PR6');
    INSERT INTO EMPLOYEE VALUES(
    SEQ_EMPID.NEXTVAL,'CHAMPI','KANE','F','01-JAN-1965','PT2','','','','','12-JAN-2004',NULL,98120989,'HSBC','ILFORD','CURRENT','PR4');
    INSERT INTO EMPLOYEE VALUES(
    SEQ_EMPID.NEXTVAL,'NED','VED','M','15-JAN-1980','HOURLY','','','','','29-DEC-2005',NULL,90812300,'WOOLWICH','LEWISHAM','CURRENT','TEMP6');
    INSERT INTO EMPLOYEE VALUES(
    SEQ_EMPID.NEXTVAL,'JILL','SANDER','F','22-MAR-1971','FT','','','','','30-NOV-2003',NULL,23230099,'BARCLAYS','PENGE','DEPOSIT','PR1');
    Any contribution would be appreciated
    many thanks
    Cube60

    Hi,
    I have triede this cursor procedure but I get an compilation error.
    See first post for tables and data..
    Can someone help me out please.
    SQL> CREATE OR REPLACE PROCEDURE update_employee(
    2 p_empid employee.empid%type,
    3 p_emp_type employee.emp_type%type)
    4 IS
    5 CURSOR c1 is
    6 select e.empid, e.emp_type, c.yearly_pay from employee e, classification c where
    7 c.class_id = e.class_id;
    8 BEGIN
    9 OPEN c1
    10 LOOP
    11 FETCH c1 INTO p_empid, p_emp_type;
    12 exit when c1%notfound;
    13
    14 IF v_emp_type ='PT1' THEN
    15 UPDATE employee SET annual_weeks_reqd = 39, pro_rata_wages = ((v_yearly_pay/52)*39), holiday_en
    tlment=21, sick_leave_entlment = 10.5 WHERE c.class_id = e.class_id;
    16 END IF;
    17 END;
    18 /
    Warning: Procedure created with compilation errors.
    SQL> SHOW ERR;
    Errors for PROCEDURE UPDATE_EMPLOYEE:
    LINE/COL ERROR
    10/1 PLS-00103: Encountered the symbol "LOOP" when expecting one of
    the following:
    . ( % ; for
    The symbol "; was inserted before "LOOP" to continue.
    Many thanks

Maybe you are looking for

  • How do I create auto run from one slideshow to another in idvd?

    Hi! It is my 1st time using iDVD. I've created 6 buttons with each button for 1 set of slideshow. Every time 1 slideshow finishes, it goes back to the main menu and I have to select the next button to play the next set of slideshow. How can I set it

  • How to add a Custom field in the Standard SAP Sales Order main screen

    Dear Experts, We have a requirement of adding a Custom field in the Sales Order screen. I know how to add the Customer field in the Additional data B tab of the Sales Order Header Screen as that is the screen user exit provided by SAP. Can someone te

  • FMS not working

    My partner and I are working on a FMS application since a month, and everything was fine. We tested the code juste before lunch, and when we went back... Tada!!! The server isn't working anymore... We tried install uninstall, the date trick (change t

  • Closing Open Items

    Forum, How would i go about closing an 'Open' AR / AP Invoice within 8.81? Right clicking on the header does not give me a 'close' option, nor is available for selection with the 'Data' menu? Regards, Juan

  • Database Structure For Articles and Categories

    Hi - This is a question about database structure - please help. Thanks For a website with many subjects or themes is it best to use 1 big table to hold or the articles or many small tables to hold articles for different subjects - I will explain what