Define variable a ROWTYPE based on a table name passed as a parameter

I am trying to write a procedure that processes rows for tables of differing structures. Table_name is passed as an IN parameter to the procedure. I define a cursor within the function that is defined by a SELECT * FROM table_name. I also need to define two variables, l_this_row and l_prev_row. I need to define them as table_name%ROWTYPE. Of course, table_name is a VARCHAR2 that contains the name of a table, whereas Oracle is expecting an actual table name in the declaration. How can I define these variables to make something like the code shown below compile and work properly? I am using Oracle 10gR2.
DEFINE PROCEDURE foo(table_name IN VARCHAR2) IS
l_this_row table_name%ROWTYPE;
l_prev_row table_name%ROWTYPE;
l_cursor SYSREFCURSOR;
BEGIN
OPEN l_cursor FOR
'SELECT * FROM '
|| table_name
|| ' ORDER BY '
|| get_pk_col_name_for_table(table_name)
|| ', version_num'; --version_num is guaranteed to be a valid column name in every table, although the other column names vary in name, quantity, and type per table.
LOOP
FETCH l_cursor INTO l_this_record;
EXIT WHEN l_cursor%NOTFOUND;
-- dynamic comparison of l_this_record and l_prev_record and conditional processing based on the comparison occurs here
l_prev_record := l_this_record;
END LOOP;
END;

Billy  Verreynne  wrote:
Well, one method is to keep the SQL projection consistent across the number of dynamic SQLs being dealt with. With the projection being consistent, your code does not need to guess what the row structure the column returns.Unfortunately, what I need to compare is almost everything except the primary keys. So one table might contain addresses and another might contain invoice headers. There's no way to get them into the same structure.
Billy  Verreynne  wrote:
This approach can also be done in a generic fashion - dealing with an arbitrary number of columns per row. This dynamic structure is more flexible, but also increases the complexity of the code that has to deal with this. For example:
create or replace type TStrings is table of varchar2(4000);Now SQLs can be created to pass any number of columns to the code to process:
select TStrings( empid, ename, jobid, date_employed, date_of_birth ) from emp order by empidThe code then uses the Count method of the TStrings type to determine the number of columns passed and processes that.Then the problem becomes having to specify all the column names. I need to figure them out dynamically, as in "SELECT column_name FROM user_tab_cols WHERE column_name NOT IN ('ID', 'PREV_ID', 'NEXT_ID')". It would, of course, be best if I didn't have to populate each array element with an individual SELECT in its own EXECUTE IMMEDIATE statement. That would certainly slow things down. If I were trying to write this using ADO.NET, I could reference something like table_name(row_index).columns(ix) without having to know any of the column names, and I could exclude columns by name using a reference like table_name.columns(column_index).name. (I don't recall the exact syntax, but it is something reasonably close to that.) But PL/SQL doesn't seem to have anything close to this.
Ideally, I want to get it to where I can do something like this in a private function:
FOR ix IN 1..TStrings.Count LOOP
   IF this_row(ix) <> last_row(ix) THEN
      RETURN FALSE;
   END IF;
END LOOP;
RETURN TRUE;
Billy  Verreynne  wrote:Last comment. I have to echo what the others said. This is not optimal. Dealing with variant/dynamic structures and processing rows using PL/SQL (in a slow-by-slow fashion) does not scale well. Scalability and performance comes from processing data sets using SQL.I completely understand. I'm a big fan of replacing a lot of code with one SQL statement, but that just won't work for this problem.

Similar Messages

  • Problem with writing a procedure with table name as an input parameter

    Hi all,
    I am writing a procedure with table name as an input parameter:
    below is the code
    create or replace procedure prc(in_tbl in varchar2)
    as
    begin
    execute immediate ' truncate table tlb ';
    insert into tbl
    select a,b,c from in_tbl;
    end;

    user579585 wrote:
    Hi all,
    I am writing a procedure with table name as an input parameter:
    below is the code
    create or replace procedure prc(in_tbl in varchar2)
    as
    begin
    execute immediate ' truncate table tlb ';
    insert into tbl
    select a,b,c from in_tbl;
    end;You'll also need to use dynamic sql for the insert:
    execute immediate 'begin insert into tbl select a,b,c from '||in_tbl||'; end';

  • Retrieve data from oracle table, table name passed in runtime into JSP

    Hello All,
    I am new to JSP, i have a requirement,
    I need to retrieve data from oracle table, here table is passed at random. how to get the data displayed in JSP page.
    can any one help me in that
    thanks

    1) Learn SQL.
    2) Learn Java.
    3) Learn JDBC.
    4) Learn DAO.
    5) Learn HTTP.
    6) Learn HTML.
    7) Learn JSP/Servlet.
    8) Learn JSTL.
    9) Apply learned things and develop.
    Whenever you stucks, please come back and post the specific coding/technical problem here.

  • Defining a Recordset Set based on two tables

    I am having difficulty displaying records for a "membership"
    page. I have set up a simple database in PHPMyAdmin with two main
    tables: instructors and membership. Instructors are given a
    temporary username and password to enter a restricted area. If they
    decide to become a member, they go to a page with a
    Pre-registration
    form and fill that in. If their credentials check out, they are
    sent a registration form.
    The pre-registration form populates the instructors table.
    I set up three pages in the Admin area: Contact_info,
    Addresses, and Membership.
    The Contact_info has the instructors' email and phone
    numbers. This is based on some of the fields in the instructors
    table. This page works fine.
    The Addresses page also is populated fields from the
    Instructors table and also works well.
    The membership page is not working. I want this page to
    display fields from the Instructors and the Membership tables.
    Here's the SQL statement that I am using in the Recordset
    dialog box in DW:
    SELECT instructors.instructor_id, instructors.first_name,
    instructors.last_name, membership.instructor_id,
    membership.username, membership.pwd, membership.type
    FROM instructors INNER JOIN membership ON
    instructors.instructor_id = membership.instructor_id
    ORDER BY instructors.last_name
    It seems to me to be correct but its not displaying any
    records. I don't know if the sql statement is bad or I have my
    instructor_id field in my Membership table set up incorrectly in
    PHPMyAdmin. I don't know how to indicate that its a foreign field
    or how to relate it to the other table, other than indication the
    relationship with sql. By the way, did I mention that I am new to
    php and sql?
    I appreciate any help.

    Just and idea. 
    Try to create one dimension like this:
    Id
    type
    Category
    1
    juice
    drink
    2
    milk
    drink
    3
    alcohol
    drink
    4
    beer
    liquor
    5
    wine
    liquor
    Hope this helps.
    Reeves
    Denver, CO

  • Sql to tell report names based on view/table name

    Hello, we recently upgraded to release 12 and planning to implement sub ledger accounting and we are in the process of identifying our customizations written on top of distribution tables so that we can tweak them to go after SLA tables. Majority of our custom objects are discoverer reports. And most of these discoverer reports are based on custom folders which are based on custom views. By running a sql we were able to identify the names of all of our custom views which go after the distribution tables. Now we want to identify which of our discoverer reports are based on these views via custom folders of our custom business areas. Our custom folders might have been named exactly same as custom view or they may have different name and the folder may actually have a sql in which they are referring these custom views.
    Would it be possible for someone to provide a sql select statement which takes database table / view name and returns the name of discoverer workbooks referring this table/view? Thanks in advance for help.
    Regards,
    Anjan Avula.

    Nancy I claimed that problem is because of developing reports in plus based on some hits I found on internet. http://www.orafaq.com/forum/t/66265/0/
    And hits I found in metalink.
    Bug # 6665629
    However according to engineer with Oracle support it is a bug. The problem with updating that table is more related to workbooks that were created in older versions or upgraded to 10.1.2.2 but have not been opened and resaved. Bug 4901641 is present in 10.1.2.2 admin and it can result in Discoverer Admin not updating the EUL5_ELEM_XREFS. Admin version 10.1.2.3 is expected to resolve this with an easy workaround is to export the older workbooks and re-import them into your eul. The import process will update the EUL5_ELEM_XREFS table and will save customer from saving and opening every workbook.
    So, may be you have 10.1.2.3 in your environment and never experienced this issue or may be your reports were never upgraded from previous versions to 10.1.2.2. In our environment we have upgraded our reports to this version from previous versions and may be what oracle engineer told is true. I need to work with our admin to get this looked at and get it fixed.

  • Assign internal table name passed through routines

    Dear experts,
    How can i pass the name of P_TAB in from fieldcat_init ?.
    i call the method of an object(ob) of class .
    If i call debugger on p_tab in form fieldcat_init ,i can see the data.
    But how to assign it
      wa_fieldcat-tabname      =  P_TAB.
    I tried this but gives me dump.
    CALL METHOD OB->printalv( exporting alv_data = t_excel ).
    method printalv.
    perform printing tables alv_data.
    endmethod.
    form printing tables p_tab like t_excel.
    #  PERFORM fieldcat_init tables p_tab USING gt_fieldcat .
      PERFORM eventtab_build USING gt_events[].
      PERFORM comment_build  USING gt_list_top_of_page[].
      PERFORM disp_rep tables p_tab.
    endform.
    FORM fieldcat_init tables p_tab USING  p_gt_fieldcat .
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname    = 'MATNR'.
      wa_fieldcat-tabname      =  P_TAB.
      wa_fieldcat-seltext_m    = text-001  .
      wa_fieldcat-outputlen = 18.
      wa_fieldcat-emphasize    = 'C410'.
      APPEND wa_fieldcat TO it_fieldcat.
    ENDFORM.
    Line with # needs clarification.
    Edited by: aditya  sharma on Jul 22, 2010 9:49 AM

    Hi Aditya,
    You described your "p_tab" in TABLES section
    describe your form like that :
    FORM fieldcat_init  USING  p_tab  p_gt_fieldcat .
    ENDFORM.
    and give the name of your table to this subroutine
    not the table itself :
    PERFORM fieldcat_init USING 'ITAB' p_gt_fieldcat.
    wrong :  PERFORM fieldcat_init USING ITAB p_gt_fieldcat.
    I hope it helps.

  • Table name passed in as a parameter

    Is it possible to determine a tablename for a query dynamically?
    For instance:
    Select *
    From :parameter

    Yes. How you construct the statement depends on where you are using the statement. Is this a sql script, procedure, What?
    Is it possible to determine a tablename for a query dynamically?
    For instance:
    Select *
    From :parameter

  • Field symbols as Table name and in where condition in a select statement

    Hello All,
    I have a scenario where I need to get user input on table name and old field value and new field value. Then based on user input, I need to select the record from the database. The column name for all the tables in question is different in the database, however there data type is the same and have same values.
    I am not able to use a field symbol for comparing the old field value to fetch the relevant record in my where clause.
    I cannnot loop through the entire table as it has 10 millilon records, please advice on how to add the where clause as field symbol as the table name is also dynamically assigned.
    Here is my code:
    DATA: TAB       LIKE SY-TNAME,
          TAB_COMP1 LIKE X031L-FIELDNAME,
          TAB_COMP2 LIKE X031L-FIELDNAME,
          NO_OF_FLD TYPE N.
    DATA: BEGIN OF BUFFER,
            ALIGNMENT TYPE F,
            C(8000)   TYPE C,
          END OF BUFFER.
    FIELD-SYMBOLS: <WA>   TYPE ANY,
                  <COMP1> TYPE ANY,
                  <COMP2> TYPE ANY.
    GET TABLE NAME GIVEN BY USER IN LOCAL VARIABLE
      TAB = TAB_NAME.
    CREATE FIELD NAME BASED ON THE TABLE NAME ENTERED.
      CASE TAB_NAME.
      WHEN 'OIUH_RV_GL'.
          KEY FIELD
            TAB_COMP1  = 'GL_GL_SYS_NO'.
            NO_OF_FLD  = 1.
      WHEN 'OIUH_RV_OPSL'.
          KEY FIELD
            TAB_COMP1  = 'OPSL_GL_SYS_NO'.
            NO_OF_FLD  = 1.
      WHEN 'OIUH_RV_OTAX'.
          NOT THE ONLY KEY FIELD
            TAB_COMP1  = 'OTAX_GL_SYS_NO'.
            TAB_COMP2  = 'OTAX_TAX_POS_NO'.
            NO_OF_FLD  = 2.
      WHEN 'OIUH_RV_GTAX'.
          NOT THE ONLY KEY FIELD
            TAB_COMP1  = 'GTAX_GL_SYS_NO'.
            TAB_COMP2  = 'GTAX_TAX_POS_NO'.
            NO_OF_FLD  = 2.
      WHEN OTHERS.
            EXIT.
      ENDCASE.
    SET FIELD SYMBOL WITH APPROPRIATE TYPE TO BUFFER AREA.
    ASSIGN BUFFER TO <WA> CASTING TYPE (TAB).
    How to add where clause and remove the if condition in the select -- endselect
    SELECT * FROM (TAB) INTO <WA>. 
      ASSIGN COMPONENT TAB_COMP1 OF STRUCTURE <WA> TO <COMP1>.
      IF NO_OF_FLD = 2.
        ASSIGN COMPONENT TAB_COMP2 OF STRUCTURE <WA> TO <COMP2>.
      ENDIF.
      IF <COMP1> = OLD_SYS_NO.
        code for updating table would come here
          WRITE: 'MATCH FOUND'.
          EXIT.
      ENDIF.
    ENDSELECT.
    Please advice. Thanks much.
    Edited by: Shipra Jhunjhunwala on Jul 22, 2009 1:33 PM
    Edited by: Shipra Jhunjhunwala on Jul 22, 2009 1:34 PM
    Edited by: Shipra Jhunjhunwala on Jul 22, 2009 1:35 PM

    1. Create single column table for holding field name depending on the table entered.
    2. Take input from user: for e.g. table_name
    3. Using case load single column table with required fields
       for e.g.
      CASE TAB_NAME.
       WHEN 'OIUH_RV_GL'.
             Append 'GL_GL_SYS_NO' to KEY_FIELD --> KEY_FIELD is the single line internal table as mentioned in step 1.
       WHEN 'OIUH_RV_OPSL'.
             Append 'OPSL_GL_SYS_NO'.
       WHEN 'OIUH_RV_OTAX'.
             Append 'OTAX_GL_SYS_NO' to KEY_FIELD.
               APPEND 'OTAX_TAX_POS_NO' to KEY_FIELD.
       WHEN 'OIUH_RV_GTAX'.
             Append 'GTAX_GL_SYS_NO' to KEY_FIELD.
               APPEND 'OTAX_TAX_POS_NO' to KEY_FIELD.
       WHEN OTHERS.
          EXIT.
       ENDCASE.
       Now depending on the table name you have required column ready
    4. Create dynamic internal table using following sudo code
       Fill the fieldcatlog using the single column field table and DD03L table, See what all columns from DD03L you want to fill in field catlog table
       loop at internal table with all the fields.
        move it to field catalog.
        append field catalog.
       endloop.
    5. Pass this field catalog table to static method create_dynamic_table method
       DATA table TYPE REF TO DATA. --> data object for holding handle to dynamic internal table.
       call method cl_alv_table_create=>create_dynamic_table
       exporting
          it_fieldcatalog = fieldcatalog_tab
       importing
          ep_table = table.
    6. Now assign table reference to field symbol of type table.
       ASSIGN table->* to <field-tab>.
    7. Also create work area <field-wa> using refrence of table.
       create data object wa LIKE LINE OF <field-tab>.
       ASSIGN wa->* to <field-wa>.
    8. Also define field symbol for field name.
       for e.g. <field_name>
    4. Dynamic internal table is ready
    5. Now execute the select statement as follows:
       SELECT (KEY_FIELD)
         INTO <ITAB> --> created dynamically above
          FROM (TABLE_NAME)
         WHERE (WHERE).  --> WHERE is single line internal table having line type of CHAR72. So for every old value there will be one line
         Where condition is same as like we give in static way only difference in this case it will stored in internal table line wise.
        In this case you need to append all your where condition line by line in to WHERE.     
    5. To fill this dynamic internal table using ASSIGN COMPONENT <Comp_number> OF STRUCTURE <field-wa> TO <field-name>
       So in this case if first field of structure STRUCT1 is user_id then sudo-code will be
       loop at internal table containing list of fields into field_wa --> single column field table
           ASSIGN COMPONENT field_wa OF STRUCTURE <field-wa> TO <field>. "Here field_wa is wa area for single column internal table holding all the fieldnames.
           Now <field-name> points to user_id field. Move some value into it as nornally we do with variables.
           Move <your_new_value> to <field-name>. --> Assign new value
            or
            <field-name> = <your_new_value>.
       Endloop.
    6. After completing all the fields one row will be ready in <field_wa>.
       APPEND <field_wa> to <field_tab>.
    Hope this helps you.
    Thanks,
    Augustin.

  • Parametrization of Tables Name before retrieveing the Rows.

    Hi all,
    I have more then one tables with same number and types of attributes,
    I want to create a single form to view only as per the parameter table name.
    further more I want the same in Reports. i.e
    Table Name : Test1, Test2.
    Application ask the table name and retrieve thre rows as per parameteized name
    Thanks, if any one could help

    Abdul,
    I don't think that you can change the table for a block in Forms at runtime. You may want to experiment with basing a block on a stored procedure so that the datasource for Forms doesn't change.
    In reports you can use ref cursors to build a query on. In a before Report trigger you can determine the table name by a custom parameter.
    Don't ask for example codes as I don't have some. Refer to teh Forms and Reporst documentation on how to use the techniques mentioned.
    Frank

  • Create Unique Index On Flow does not work for table names 23 characters

    I have a "create unique index on flow table" step that is dynamically generated by the IKM.
    The index name that is generated by the IKM is based on the table name except that the created index name is prefixed with "I$_" and ends with "_idx". Obviously, since Oracle table names can not exceed 30 characters in length, the index creation step will fail if the base table name exceeds 23 characters.
    I have tried to substring the index name generation step in the IKM so that it only uses the first 23 characters of the table name, but have not had any luck with using the "substring" command together with snpRef.getTable call.
    This is the section of the IKM that I desire to change:
    - <Field name="Txt" type="java.lang.String">
    - <![CDATA[
    create unique index      <%=snpRef.getTable("L","INT_NAME","W")%>_idx
    on          <%=snpRef.getTable("L","INT_NAME","W")%> (<%=snpRef.getColList("", "[COL_NAME]", ", ", "", "UK")%>)
    <%=snpRef.getUserExit("FLOW_TABLE_OPTIONS")%>
    ]]>
    </Field>
    I would like to change the above to something similar to the following (note the only change is the addition of substring(1,23))
    - <Field name="Txt" type="java.lang.String">
    - <![CDATA[
    create unique index <%=snpRef.getTable("L","INT_NAME","W")*.substring(1,23)*%_idx
    on          <%=snpRef.getTable("L","INT_NAME","W")%> (<%=snpRef.getColList("", "[COL_NAME]", ", ", "", "UK")%>)
    <%=snpRef.getUserExit("FLOW_TABLE_OPTIONS")%>
    ]]>
    </Field>
    Any help greatly appreciated. Thanks.

    As the index is temporary, just like the I$ talbel, the easiest way is to replace the table name with some unique identifier like the session is:
    bq. I$_&lt;%=odiRef.getSession("SESS_NO")%&gt;_idx
    If for some reason that is not unique enough, add the NNO:
    bq. I$_&lt;%=odiRef.getSession("SESS_NO")%&gt;&lt;%=odiRef.getSession("NNO")%&gt; \\ _idx                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to pass table name as argument to cursor

    please help me how to solve this.
    SQL> select c1 from test ;
    C1
    1
    7
    18
    4
    10
    28
    30
    I'm able to execute this.
    SQL> get b
    1 set serveroutput on size 2000
    2 declare
    3 cursor c1 is
    4 select c1 from test ;
    5 begin
    6 for rec in c1
    7 loop
    8 dbms_output.put_line(rec.c1);
    9 end loop;
    10* end;
    SQL> sta b
    1
    7
    18
    4
    10
    28
    30
    When I change the above cursor to accept the parameter it is not working.
    SQL> get c
    1 set serveroutput on size 2000
    2 declare
    3 cursor c1(p_table varchar2) is
    4 select c1 from p_table ;
    5 begin
    6 for rec in c1('test')
    7 loop
    8 dbms_output.put_line(rec.c1);
    9 end loop;
    10* end;
    ERROR at line 3:
    ORA-06550: line 3, column 18:
    PL/SQL: ORA-00942: table or view does not exist
    ORA-06550: line 3, column 3:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 7, column 25:
    PLS-00364: loop index variable 'REC' use is invalid
    ORA-06550: line 7, column 4:
    PL/SQL: Statement ignored

    You cannot use a (bind) variable in SQL for an object name (i.e. a table name, column name, etc).
    Why?
    The SQL engine needs to parse the SQL. Part of the parse is to resolve the scope to determine what objects are being reference. It needs to check that the column names referred to is indeed in that object. Etc.
    Then these objects are used to determine the best execution path to run the SQL. What indexes do the objects have? Is the object a partitioned table and the partition criteria used in the predicate? Etc.
    How can the SQL engine perform any of these when you pass it a table name that is a parameter?
    The name of an object (such as the table being selected from) must be explicitly stated in a SQL statement. It cannot be variable.

  • Error Messages in NW Log: Unable to run query / Enter table name

    Hi all,
    I am always wondering about the tons of error messages in the NW log.
    Today I opened the workbench and a query (SQL-Query, Mode Fixed Query) and viewed the Fixed Query Details. Then I looked into the NW Log (SAP Logs), and it contained the following errors from my query opening inside the workbench:
    com.sap.xmii.Illuminator.logging.LHException:
    com.sap.xmii.Illuminator.logging.LHException:
    com.sap.xmii.Illuminator.logging.LHException:
    Enter a table name
    Unable to run the query
    All in all 15 error entries have been generated. Unfortunately no more details are contained in the log.
    Has anyone an idea why this happens when only opening a query inside the workbench without starting it?
    Michael

    Do you get similar errors when running a ColumnList query without providing a Table name (with the Group parameter)?
    /XMII/Illuminator?Server=XXXXX&Mode=ColumnList
    /XMII/Illuminator?Server=XXXXX&Mode=ColumnList&Group=TABLENAME
    Just a guess, but perhaps the WB is trying to fill the lower left listbox of available columns without the benefit of a table name being selected from the upper left listbox of available tables.
    Regards,
    Jeremy

  • Add column to user defined type based on existing table

    Hello guys,
    I am trying to compile my function which returns a user defined type based on existing table. Throughout the initializing process though my query returns one additional column - SCORE(1). Here is my package:
    create or replace
    PACKAGE STAFF_AGENCY_PKG AS
    TYPE TYPE_SEEKER_TABLE IS TABLE OF TOSS.SEEKER%ROWTYPE;
    FUNCTION GET_SEEKERS(IN_KEYWORD IN VARCHAR2)
    RETURN TYPE_SEEKER_TABLE PIPELINED;
    END STAFF_AGENCY_PKG;
    create or replace
    PACKAGE BODY STAFF_AGENCY_PKG
    AS
    FUNCTION GET_SEEKERS(IN_KEYWORD IN VARCHAR2)
    RETURN TYPE_SEEKER_TABLE PIPELINED
    IS
    R_TBL TYPE_SEEKER_TABLE; -- to be returned
    BEGIN
    FOR R IN(
    SELECT Seeker.SEEKER_ID,
    Seeker.FIRSTNAME,
    Seeker.LASTNAME,
    Seeker.NATIONALITY,
    Seeker.ISELIGIBLE,
    Seeker.BIRTHDATE,
    Seeker.ISRECIEVEEMAILS,
    Seeker.HIGHESTDEGREE,
    Seeker.ETHNICITY,
    Seeker.GENDER,
    Seeker.ISDISABILITY,
    Seeker.DISABILITY,
    Seeker.CV,
    Seeker.PASSWORD,
    Seeker.PREFFERED_CITY,
    SEEKER.EMAIL,
    SEEKER.JOB_PREFERENCES_ID,
    SCORE(1)
    FROM SEEKER Seeker
    WHERE CONTAINS(CV, '<query>
    <textquery lang="ENGLISH" grammar="context">' ||
    GET_RELATED_CATEGORIES(IN_KEYWORD) ||
    '</textquery>
    <score datatype="INTEGER"/>
    </query>', 1) > 0
    LOOP
    PIPE ROW(R); --Error(38,10): PLS-00382: expression is of wrong type
    END LOOP;
    RETURN;
    END GET_SEEKERS;
    END STAFF_AGENCY_PKG;
    How do I need to amend my user type in order to suffice?
    Oracle Release 11.2.0.1.0
    Many thanks in advance!

    >
    How do I need to amend my user type in order to suffice?
    >
    You will need to create two new TYPEs. One that has all of the columns of the TOSS.SEEKER table and the new SCORE column and then a TYPE that is a table of the first type.
    See the Example 12-22 Using a Pipelined Table Function For a Transformation in the PL/SQl language reference
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/tuning.htm#i53120
    Here is the first part
    -- Define the ref cursor types and function
    CREATE OR REPLACE PACKAGE refcur_pkg IS
      TYPE refcur_t IS REF CURSOR RETURN employees%ROWTYPE;
      TYPE outrec_typ IS RECORD (
        var_num    NUMBER(6),
        var_char1  VARCHAR2(30),
        var_char2  VARCHAR2(30));
      TYPE outrecset IS TABLE OF outrec_typ;
    FUNCTION f_trans(p refcur_t)
          RETURN outrecset PIPELINED;
    END refcur_pkg;
    CREATE OR REPLACE PACKAGE BODY refcur_pkg IS
      FUNCTION f_trans(p refcur_t)
       RETURN outrecset PIPELINED IS
        out_rec outrec_typ;
        in_rec  p%ROWTYPE;
      BEGINModify
      TYPE outrec_typ IS RECORD (
        var_num    NUMBER(6),
        var_char1  VARCHAR2(30),
        var_char2  VARCHAR2(30));
      TYPE outrecset IS TABLE OF outrec_typ;to include all of the columns you need. Unfortunately you will have to manually list all of the columns of the TOSS.SEEKER table. If you expect to need this same structure in other places you should create them as SQL types instead of PL/SQL types.
    This example should be enough to show you how to change your code to do something similar.

  • Using a Variable for Table Name  with a cursor

    Hello All
    Is it possible to use a Parameter passed to a procedure as the table name
    in a cursor selection statment. I thought the below would work but I get
    a error. Does anyone have any ideas?? The Error is listed below to.
    Here's the code I just complied
    CREATE OR REPLACE PROCEDURE Dup_Add(NEWQATABLE IN VARCHAR2) IS
    CURSOR c1 IS SELECT MUNI,PROV FROM NEWQATABLE GROUP BY MUNI, PROV;
    c1rec c1%ROWTYPE;
    BEGIN
    OPEN c1;
    LOOP
    FETCH c1 INTO c1rec;
    EXIT WHEN c1%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(c1rec.MUNI);
    END LOOP;
    CLOSE c1;
    END;
    Here is the errors
    LINE/COL ERROR
    3/8 PLS-00341: declaration of cursor 'C1' is incomplete or malformed
    3/15 PL/SQL: SQL Statement ignored
    3/38 PLS-00201: identifier 'NEWQATABLE' must be declared
    5/7 PL/SQL: Item ignored
    10/3 PL/SQL: SQL Statement ignored
    10/17 PLS-00320: the declaration of the type of this expression is
    incomplete or malformed
    12/3 PL/SQL: Statement ignored
    12/24 PLS-00320: the declaration of the type of this expression is
    incomplete or malformed
    LINE/COL ERROR
    Thanks
    Peter

    If you are going to have a table name or a column name as a parameter, then you have to open the cursor dynamically. The following example uses Native Dynamic SQL (NDS) to open a ref cursor dynamically. I also eliminated the group by clause, since it is intended for use with aggregate functions and you weren't using an aggregate function. Also notice that there are some other differences in terms of defining variables and fetching and so forth.
    SQL> CREATE TABLE test_table
      2  AS
      3  SELECT deptno AS muni,
      4         dname  AS prov
      5  FROM   dept
      6  /
    Table created.
    SQL> CREATE OR REPLACE PROCEDURE Dup_Add
      2    (newqatable IN VARCHAR2)
      3  IS
      4    TYPE cursor_type IS REF CURSOR;
      5    c1 cursor_type;
      6    c1muni NUMBER;
      7    c1prov VARCHAR2 (20);
      8  BEGIN
      9    OPEN c1 FOR 'SELECT muni, prov FROM ' || newqatable;
    10    LOOP
    11      FETCH c1 INTO c1muni, c1prov;
    12      EXIT WHEN c1%NOTFOUND;
    13      DBMS_OUTPUT.PUT_LINE (c1muni || ' ' || c1prov);
    14    END LOOP;
    15    CLOSE c1;
    16  END;
    17  /
    Procedure created.
    SQL> SHOW ERRORS
    No errors.
    SQL> SET SERVEROUTPUT ON
    SQL> EXECUTE dup_add ('test_table')
    10 ACCOUNTING
    20 RESEARCH
    30 SALES
    40 OPERATIONS
    PL/SQL procedure successfully completed.

  • Table name to find a variable used in which queries

    Hello,
    what is table name to find a particular variable used in which queries.

      write 'Variable Name:'.
      write vname.
      write /.
      write 'Variable Type:'.
      write variabletype.
      write /.
      write 'Based on Infoobject:'.
      write variobj.
      write /.
      write 'Variable Processing Type:'.
      write varprocesstyp.
      write /.
      write 'Variable Select Parameters:'.
      write varselectiontyp.
      write /.
      write 'Variable Ready for Input:'.
      write varinputtyp.
      write /.
      write 'Variable Entry criteria:'.
      write varentrytyp.
      write /.
      write 'Variable can be changed during navigation:'.
      write varchangeable.
      write /.
    *  write
    Select single varuniid from rszglobv into varid where vnam = p_varnm.
    select single TXTLG from RSZELTTXT into variabledescription where ELTUID = varid and OBJVERS = 'A'.
    write 'Variable Description:'.
    write variabledescription.
    write /.
    write /.
    querydet-querytechname = 'Query Technical Name'.
    querydet-querydesc = 'Query Description'.
    write querydet-querytechname.
    write querydet-querydesc.
    write /.
    Select SELTUID from RSZELTXREF into table queryuid where TELTUID = varid and laytp = 'VAR' and OBJVERS = 'A'.
    loop at queryuid into querydets.
    select single compID from rszcompdir into querydet-querytechname where COMPUID = querydets-queryid and OBJVERS = 'A'.
    select single txtlg from RSZELTTXT into querydet-querydesc where ELTUID = querydets-queryid and objvers = 'A'.
      write querydet-querytechname.
      write querydet-querydesc.
      write /.
    *update querydet from querydetail.
    endloop.
    write 'Query View Details for affected queries'.
    write /.
    viewtab-viewtechname = 'View Technical Name'.
    viewdesc = 'View Description'.
    write viewtab-viewtechname.
    write viewdesc.
    write /.
    clear viewtab.
    clear viewdesc.
    loop at queryuid into querydets.
    select single compID from rszcompdir into querydet-querytechname where COMPUID = querydets-queryid and OBJVERS = 'A'.
    select viewid from rszwview into table viewtab where compid = querydet-querytechname and objvers = 'A'.
    loop at viewtab into viewdetails.
      select single TXTLG from RSZWOBJTXT into viewdesc where objid = viewdetails-viewtechname.
        write viewdetails-viewtechname.
        write viewdesc.
        write /.
       endloop.
      endloop.

Maybe you are looking for