Dynamically Access a plsql table

If I have 2 plsql tables :
vt1_games and vt2_games that I usuallly update with the
following:
vt1_games(vt1_count) := ......
or
vt2_games(vt2(count) := ......
How can I use a variable for the plsql table name and pointer?
Thanks,
Paul

I've moved this question to the correct forum.

Similar Messages

  • Dynamic Columns in PLSQL Table

    All,
    Is it possible to build the columns of a PLSQL table dynamically at run time? I got a requirement wherein the number of columns are known only during the program execution.
    Thanks,

    Offhand, I cannot see how it can be done - or even if hacked somehow, of how it can be of any use.
    One need to use the right tool for the job - and PL/SQL "tables" is always the wrong tool as Oracle tables (fixed or temp) is better.
    Now if you need to use associative array (and not a so-called PL/SQL "table"), then that is something very different than a so-called table.
    To explain - an associative array is nothing like an Oracle table. Thus calling such an array a "table" in PL/SQL leads the developer to make gross design mistakes as the developer attempts to treat that array as he/she would an Oracle table. Even use the SQL engine on a PL/SQL data structure in the PGA.
    The best place for data is in Oracle. That is why we buy and use Oracle. As soon as you want to do that in PL/SQL instead, using an array, you need to ensure that you reasons are valid. (e.g. bulk collect, etc)

  • Internal PLSQL Tables Access via SQL. But how ?

    Hello,
    I want to write the result of a database query in an internal PLSQL Table. After that i would like work with this internal PLSQL Table
    in a Package/Procedure/Function.
    Important for me is to access the internal Table via SQL because i have to refactor a package wich is working with 46 Database Tables an plain SQL. I
    would like to change these DB Tables into internal PLSQL Tables.
    I have written a short example wich will explain my approach to solving this problem.
    The syntax will be accepted by the Database but my 'dbms_output.put_line' statement at the end is empty or blank.
    What do i wrong ? Would be nice if anyone can help me out.
    With best regards
    Jens
    pre work :
    create table PERSON_DB_TABLE
    (SURNAME  VARCHAR2(50),
    LASTNAME VARCHAR2(50));
    insert into PERSON_DB_TABLE values
    ('JENS','FOERSTER');
    insert into PERSON_DB_TABLE values
    ('MAX','MEIER');
    insert into PERSON_DB_TABLE values
    ('MARTHA','MUSTERMANN');
    create type PERSON_OBJECT as object (
        SURNAME  VARCHAR2(50),
        LASTNAME VARCHAR2(50));
    create type PERSON_NESTED_TABLE as table of PERSON_OBJECT;
    now my anonymous block
    declare
       v_PERSON_OBJECT        PERSON_OBJECT;
       v_PERSON_NESTED_TABLE  PERSON_NESTED_TABLE;
       v_PERSON_OBJECT_2      PERSON_OBJECT;
    begin
       for v_counter in (select SURNAME, LASTNAME into v_PERSON_OBJECT.SURNAME,
                                                                                            v_PERSON_OBJECT.LASTNAME
                                  from PERSON_DB_TABLE)
         loop
            v_PERSON_NESTED_TABLE := PERSON_NESTED_TABLE(v_PERSON_OBJECT);
         end loop;
       for v_counter in (select SURNAME, LASTNAME into v_PERSON_OBJECT_2.SURNAME,
                                                                                            v_PERSON_OBJECT_2.LASTNAME
                                  from TABLE (v_PERSON_NESTED_TABLE))
         loop
            dbms_output.put_line(v_PERSON_OBJECT_2.LASTNAME);
         end loop; 
    end;

    1386a7b8-e834-43bf-a0d4-922b548bb70b wrote:
    I need this, because my customer didn't like the idea to use Database Tables instead of Variables in the RAM. So he wants this procedure redesigned.
    As Mike says, keep this person away from your database.
    Customers should not be dictating how to implement technical solutions, they should be providing business and logical requirements.
    PL/SQL arrays/collections use expensive PGA memory, taking up valuable server resources.
    Copying data from the database to PGA memory to try and process it using PL/SQL is bad design.  SQL is designed specifically for data manipulation using database tables, so it's the ideal way to do process data... directly on database tables.

  • How to compare two PLSQL tables dynamically.

    Hi,
    Can you any body help for the following scenario,
    I have two PLSQLtables with same structure ,Each PLSQL table contains more than 100 columns.
    Now I want to compare content of the two PLSQL tables column wise.
    I Knew allready one method like below
    FOR I IN 1..100
    LOOP
    IF PLSQL_1_TAB(I).ACCT_NO = PLSQL_2_TAB(I).ACCT_NO THEN
    INSERT INTO …....
    END IF;
    END LOOP;
    is there any method to compare two PLSQL tables dynamically
    Edited by: RAVI KUMAR.T.V. on May 5, 2011 11:51 PM

    Hi Saubhik,
    Thanks for your reply..
    See the below code..
    DECLARE
    CURSOR cur_emp IS
    SELECT *
    FROM emp
    WHERE job = 'MANAGER';
    TYPE typ1 IS TABLE OF emp%ROWTYPE INDEX BY BINARY_INTEGER;
    v_pl_old typ1;
    v_pl_new typ1;
    BEGIN
    OPEN cur_emp;
    FETCH cur_emp INTO v_pl_old(1);
    CLOSE cur_emp;
    UPDATE emp SET comm = comm+1000 WHERE hiredate < '01-MAY-1981' AND job = 'MANAGER';
    COMMIT;
    OPEN cur_emp;
    FETCH cur_emp INTO v_pl_new(1);
    CLOSE cur_emp;
    IF v_pl_old(1) = v_pl_new(1) THEN
    DBMS_OUTPUT.PUT_LINE('Latest comm not yet Updated');
    ELSE
    DBMS_OUTPUT.PUT_LINE('Latest comm Updated');
    END IF;
    END;
    When the above code is executed iam getting the following error :
    ORA-06550: line 19, column 19: PLS-00306: wrong number or types of arguments in call to '='
    ORA-06550: line 19, column 4: PL/SQL: Statement ignored
    Here in the example I have taken the standard EMP table, but
    actually, Iam having a bigger table with 90 columns of different datatypes,
    in which some of the columns gets updated after some UPDATE statements executed based on some conditions.
    Now, my requirement is to compare the values of each and every column in the table before and after the execution of the UPDATE statements,
    and to insert the modified values only along with the primary key column value into in a new table of similar structure.
    If I write the code (to compare the values of each and every column in the table, and if the value is modified then insert that value along with the primary key value into a different talbe) then as the table is having many columns (90), the code becomes lengthy..
    Is there any alternative method which does the same with shorter code.
    Can you please give me an idea/sol. to meet my requirement.
    Thanks..
    Edited by: RAVI KUMAR.T.V. on May 9, 2011 2:43 AM

  • Dynamically Accessing a PL/SQL Table

    If I have 2 plsql tables :
    vt1_games and vt2_games that I usuallly update with the
    following:
    vt1_games(vt1_count).team1_num := ......
    or
    vt2_games(vt2(count).team1_num := ......
    How can I use a variable for the plsql table name and pointer?
    Thanks,
    Paul

    In full agreement with Guido's suggestion, i think too, there are not so many choices, one possible solution could be
    SQL> create table dept_sal(deptno number,sal number);
    Table created.
    SQL> declare
      2    type emp_r is record(
      3      deptno emp.deptno%type,
      4      sal    emp.sal%type);
      5    type emp_t is table of emp_r index by binary_integer;
      6    l_emp    emp_t;
      7          l_dept    emp_t;
      8  begin
      9    -- populate initial collection
    10    select deptno, sal bulk collect into l_emp from emp;
    11
    12    for i in l_emp.first .. l_emp.last loop
    13          l_dept(l_emp(i).deptno).deptno :=l_emp(i).deptno;
    14          l_dept(l_emp(i).deptno).sal := nvl(l_dept(l_emp(i).deptno).sal,0) + l_emp(i).sal;
    15    end loop;
    16
    17    forall i in indices of l_dept
    18      insert into dept_sal values l_dept(i);
    19  end;
    20  /
    PL/SQL procedure successfully completed.
    SQL> select * from dept_sal;
        DEPTNO        SAL
            10       8750
            20      10875
            30       9400In other words, about 20 lines of code to implement
    insert into dept_sal select deptno,sum(sal) from emp group by deptno;Best regards
    Maxim

  • How to get the plsql table data into output cursor

    Hi,
    Could anybody please help me.
    Below is an example of the scenario..
    CREATE OR REPLACE PACKAGE chck IS
    PROCEDURE getdata(dept_no IN VARCHAR2,oc_result_cursor OUT sys_REFCURSOR);
    TYPE get_rec is record (ename varchar2(20),
    eno number(12));
    TYPE t_recs IS TABLE OF get_rec INDEX BY BINARY_INTEGER;
    emp_tab t_recs;
    END chck;
    CREATE OR REPLACE PACKAGE BODY chck AS
    PROCEDURE getdata(dept_no IN VARCHAR2,oc_result_cursor OUT sys_REFCURSOR)
    is
    BEGIN
    select ename, eno
    bulk collect into emp_tab
    from emp;
    open oc_result_cursor for select * from table(emp_tab); -- I believe something is wrong here ....
    END;
    END chck;
    the above package is giving me an error:
    LINE/COL ERROR
    10/29 PL/SQL: SQL Statement ignored
    10/43 PL/SQL: ORA-22905: cannot access rows from a non-nested table
    item
    let me know what needs to be changed
    Thanks
    Manju

    manjukn wrote:
    once i get the data into a plsql table, how to get this plsql table data into the cursor?There is no such thing as a PL/SQL table - it is an array.
    It is nothing at all like a table. It cannot be indexed, partitioned, cluster, etc. It does not exist in the SQL engine as an object that can be referenced. It resides in expensive PGA memory and needs to be copied (lock, stock and barrel) to the SQL engine as a bind variable.
    It is an extremely primitive structure - and should never be confused as being just like a table.
    Its use in SQL statements is also an exception to the rule. Sound and valid technical reasons need to justify why one want to push a PL/SQL array to the SQL engine to run SELECT 's against it.

  • Open cursor for PLSQL table of records

    Is it possible to open a cursor for all data in a PLSQL table of records?
    something like
    cursor c (p1 number) is select * from <plsqltab>
    where <plsqltab>.col = p1

    There is no such thing as a PL/SQL table. Yes, I know that many calls this structure in PL/SQL a table. And that is exactly where all this confusion stems from.. and trying to treat such a "table" as an Oracle table using SQL.
    The correct terms are dynamic array (indexed by integer) or dynamic associative array (indexed by varchar). And an array is nothing like a table ito RDBMS processing.
    Yes, you can run SQLs against arrays. But it is "expensive". Why? Because the data sits inside PL/SQL Engine. Not in the SQL Engine. The data is in a PL/SQL defined structure. Not a SQL defined structure.
    So.. the data needs to be shipped from the PL/SQL Engine to the SQL Engine and converted into a format that the SQL Engine can understand and use.
    Also, once shipped and converted the SQL structure is not indexed. Which means that the only option is a full table scan of that structure.
    So you need to ask yourself why do you want to use SQL against a PL/SQL array? As soon as you do that, you are saying "Hey, this PL/SQL table ain't good enough and I need to process it using SQL".
    So why then does that data sit inside a PL/SQL array and not in a SQL table?
    Oracle provides you with the ability to create temporary session tables. These can be indexed. SQL can be run against them without all the "expenses" that are associated with running SQL against a PL/SQL array.
    PL/SQL arrays is a great tool. But only when it is the right tool to use. When someone says he/she needs SQL to use this tool, then I question the choice of the tool. Make sure you use the right tool for the job.

  • PLSQL table Count giving NO_DATA_FOUND Error

    Hi Everyone,
    I am having a Associative array define below :
    TYPE SchQryRecTyp IS RECORD (
    load_port port_call.lcn_code%type
    , load_call port_call.call%type
    , dsch_port port_call.lcn_code%type
    , dsch_call port_call.call%type
    , vsl_code port_call.vsl_code%type
    , vsl_name vsl.vsl_name%type
    , voy_code port_call.voy_code%type
    , line_code port_call.line_code%type
    , etd port_call.etd%type
    , eta port_call.eta%type
    , transit_tm number
    , load_area_uid area_master_rly.area_uid%type
    , load_port_qry port_call.lcn_code%type
    , dsch_area_uid area_master_rly.area_uid%type
    , dsch_port_qry port_call.lcn_code%type
    , flag varchar2(4)
    , inact_flg varchar2(1)
    , final_or_doc_lock varchar2(1)
    TYPE SchQry_Tab_Typ IS TABLE OF SchQryRecTyp
    INDEX BY BINARY_INTEGER;
    1 ) Now in my code I am polulating the the PLSQL table SchQry_Tab_Typ and
    2) based on that PLSQL table data I am again trying to Fetch some other data.
    But I came accross a problem which i am mentioning below :
    When i am trying to perform the task (2) I am running a Loop i.e.
    IF vroute2.COUNT > 0 THEN
    FOR a IN 1..vroute2.COUNT LOOP
    -- dbms_output.put_line(vroute2(a).vsl_code); **--(But while accessing the value it is giving ORA-01403 - No Data Found )*
    END LOOP;
    END IF;
    But when i changed the loop like this
    IF vroute2.COUNT > 0 THEN
    FOR a IN vroute2.FIRST..vroute2.LAST LOOP
    -- dbms_output.put_line(vroute2(a).vsl_code); **--(Program executed successfully)*
    END LOOP;
    END IF;
    Can anybody help me if they have experienced such problem and the reason for this ?

    Wrong forum!
    Please mark this question ANSWERED and repost it in the SQL and PL/SQL forum.
    PL/SQL
    When you post provide your 4 digit Oracle version.

  • Dynamic security using Security table in SSAS Tabular model

    Hi, 
    Platform : SSAS Tabular model (VS 2010)
    I need to apply Dynamic security using Security table(manually created) in Tabular model, Need to apply filter for 2 tables. I am able to
    create roles in Tabular model using USERNAME() and LOOKUP() function it worked fine. But the problem is when i am trying to give full access for a particular column and limit the access in other column, it is not working properly.
    Please find below table and guide me where i am falling short. In the Security table wherever you find ALL it means full access.
    Security table
    Login Name
    Dim_Country
    Dim_Customer
    DOMAIN\User1
    ALL
    2
    User1 should see all countries but Only 2,4 Customers
    DOMAIN\User1
    ALL
    4
    DOMAIN\User2
    2
    ALL
    User2 should see all customers but Only 2,3 countries
    DOMAIN\User2
    3
    ALL
    DOMAIN\User3
    ALL
    ALL
    User3 should see all Customers and Countries
    DOMAIN\User4
    1
    3
    User4 should see 1 Country and 3 Customer
    ALL - means NO restriction
    Numeric values indicate the Dimension IDs
    Do let me know if further explanations required.
    Thanks,
    Sundar

    Hi Sundar,
    According to your description, you want to implement dynamic security using Security table in SQL Server Analysis Services Tabular model, right?
    It is very common to have data security implementation in BI projects either at databases or Cubes and sometimes this security implementation and maintenance goes out of control due to the dynamic flow of business information. Here are some links which describe
    dynamic security implementation at SSAS tabular model using an external security table, please see:
    http://bipassion.wordpress.com/2012/10/01/ssas-tabular-dynamic-security/
    http://www.bidn.com/blogs/ChrisSchmidt/ssas/4332/dynamic-security-in-tabular
    Regards,
    Charlie Liao
    TechNet Community Support

  • How to create APEX report from data in PLSQL table

    Hi, I have a procedure that is creating/inserting records into multidimensional pslql table. I want to create a report and graph based on the data stored in plsql table. Can someone please advice how to can I select this data in apex OR point me to any sample code?
    Thanks
    Aali

    Hi,
    try to google something about ORACLE TABLE CAST
    SELECT ot.yourcolumn
    FROM
       TABLE(CAST(yourplsqltablevariable AS userdefinedoracletype)) otE.g.
    http://it.toolbox.com/blogs/oracle-guide/using-a-plsql-table-in-sql-11013
    Regards,
    R.

  • How to improve performance using bulk collects with plsql tables or arrays

    Hi All,
    my procedure is like this
    declare
    cursor c1 is select ----------------------
    begin
    assigning to variables
    validations on that variables
    --50 validations are here --
    insert into a table
    end;
    we have created indexes on primary keys,
    i want to use
    DECLARE
    CURSOR a_cur IS
    SELECT program_id
    FROM airplanes;
    TYPE myarray IS TABLE OF a_cur%ROWTYPE;
    cur_array myarray;
    BEGIN
    OPEN a_cur;
    LOOP
    FETCH a_cur BULK COLLECT INTO cur_array LIMIT 100;
    ***---------can i assign cursor data to the plsql table variables or array***
    ***validate on the pl sql variable as---***
    i
    nsert into a table
    EXIT WHEN a_cur%NOTFOUND;
    END LOOP;
    CLOSE a_cur;
    END;
    Edited by: Veekay on Oct 21, 2011 4:28 AM

    Fastest way often is this:
    insert /*+append */
    into aTable
    select * from airplanes;
    commit;The select and insert part can even be done in parallel if needed.
    However if the oparation is complex or the dataset is very very very very very large or the programmer is decent but not excellent then the bulk approach should be considered. It is often a pretty stable and linear scaling approach.
    The solution depends a little on the database version.
    LOOP
      FETCH a_cur BULK COLLECT INTO cur_array LIMIT 100;
      EXIT WHEN a_cur.count = 0;
      forall i in a_cur.first.. a_cur.last
      insert into aTable (id)
      values (a_cur(i));
    END LOOP;
    ...If you have more then one column then you might need a single collection for each column. Other possibilities depend on the db version.
    Also: do not exit using a_cur%NOTFOUND. This is wrong! You might loose records from the end of the data set.

  • How to retrieve data from plsql table in BI publisher Data template

    Hi All,
    I have created a data template for XML publisher report. In data template i m getting data from plsql table. for that i have created one package with pipelined function. I am able to run that sql from sql developer .But if i run the concurrent program then i got error like "java.sql.SQLSyntaxErrorException: ORA-00904: "XXXXX": invalid identifier".
    I have used the same parameters in Data template and concurrent program....
    please clarify me what needs to be done....
    thanks in advance....
    Regards,
    Doss

    Hi Alex ,
    i am using pipelined function and get the data from cursor and load it into plsql table (nested table). and i use the below in my data template to fetch the data:
    <sqlStatement name="Q1">
    <![CDATA[select * from  table(PO_SPEND_RPT_PKG.generate_report(P_ORG_ID,P_SOB_ID,P_ORG_NAME,P_PERIOD_NAME,P_CLOSE_STATUS,P_E_PCARD_NEED,P_REPORT_TYPE))]]>
    </sqlStatement>
    if i run the above in sql developer i can get the result....from apps if i run i got the error "java.sql.SQLSyntaxErrorException: ORA-00904: "P_ORG_ID": invalid identifier"
    Edited by: kalidoss on Sep 14, 2012 4:32 AM

  • Can I create a Stored Procedure That access data from tables of another servers?

    I'm developing a procedure and within it I'm trying to access another server and make a select into a table that belongs to this another server. When I compile this procedure I have this error message: " PLS-00904: insufficient privilege to access object BC.CADPAP", where BC.CADPAP is the problematic table.
    How can I use more than one connection into an Oracle Stored Procedure?
    How I can access tables of a server from a Stored Procedure since the moment I'm already connected with another server?
    Can I create a Stored Procedure That access data from tables of another servers?

    You need to have a Database Link between two servers. Then you could do execute that statement without any problem. Try to create a database link with the help of
    CREATE DATABASE LINK command. Refer Document for further details

  • How to load the data using a plsql table in ODI.

    Hi All ,
    Can anyone help me on this ?
    We have a PLSQL procedure which returns a plsql table as out parameter.
    We are supposed to load the data in to a file using this plsql table (Table type) in ODI.
    Can this be done using ODI?
    Regards,
    Karthik+

    Hi,
    We have one process with a ref cursor (Oracle) as a source and remote Oracle DB as a target. I ended up writing my own KM that populates a global temporary table from the cursor first and then transfers the data to target. If temporary table is an option for you, the rest is pretty easy.
    Regards.

  • How can I see which roles or users have access to a table?

    How can I see which roles or users have access to a table?
    For a given table, how can I see the grants, who and what?
    Many thanks

    dba_tab_privs.
    Grantee can be a role or an user, as roles are fake users.
    Sybrand Bakker
    Senior Oracle DBA

Maybe you are looking for

  • Can't Put Movie into my iTunes Libarary or iPod Video(5g)

    I recently converted a video to mp4 using ImTOO DVD to iPod Converter. It's in the mp4 format and should be perfect to be put into iTunes. Well when I try sticking it in there it says that it can't be played on my iPod or something like that. How can

  • FCP X hanging when loading an event

    After my external HD got disconnected while editing, I rebooted the program but FCP X is just hanging on the start up at 'loading "xxx" event' What can I do? Is the event corrupted?

  • Stablish conditions between a data field in a query

    Hello all, Firstly, I´ve got an infoCube "A" where every record has a field called "Init date" (date field) and another field called "finish date" In a query (that retrieves data for the infoCube A) there is a pop up with a date that  user must enter

  • Swprintf_s issue in vs 2015

    Hi, This code returns a strange value! It seems that the CRT function truncates the input strings to their first character. I get this result: "S V D" The code compiled as Unicode. Here is the very simple code which show this problem: #include "stdaf

  • MRP for Non-stock and mechanical items

    Hi all, How MRP takes care of Mechanical items which are not in BOM Regards, Sravan