Dynamically Access a plsql table

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

I've moved this question to the correct forum.

Similar Messages

  • Dynamic Columns in PLSQL Table

    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.

    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 ?

    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
    pre work :
    create table PERSON_DB_TABLE
    insert into PERSON_DB_TABLE values
    insert into PERSON_DB_TABLE values
    insert into PERSON_DB_TABLE values
    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
       for v_counter in (select SURNAME, LASTNAME into v_PERSON_OBJECT.SURNAME,
                                  from PERSON_DB_TABLE)
         end loop;
       for v_counter in (select SURNAME, LASTNAME into v_PERSON_OBJECT_2.SURNAME,
                                  from TABLE (v_PERSON_NESTED_TABLE))
         end loop; 

    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.

    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
    INSERT INTO …....
    END IF;
    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..
    CURSOR cur_emp IS
    SELECT *
    FROM emp
    WHERE job = 'MANAGER';
    v_pl_old typ1;
    v_pl_new typ1;
    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';
    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');
    DBMS_OUTPUT.PUT_LINE('Latest comm Updated');
    END IF;
    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.
    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
    vt1_games(vt1_count).team1_num := ......
    vt2_games(vt2(count).team1_num := ......
    How can I use a variable for the plsql table name and pointer?

    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;
    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;
    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

  • How to get the plsql table data into output cursor

    Could anybody please help me.
    Below is an example of the scenario..
    PROCEDURE getdata(dept_no IN VARCHAR2,oc_result_cursor OUT sys_REFCURSOR);
    TYPE get_rec is record (ename varchar2(20),
    eno number(12));
    emp_tab t_recs;
    END chck;
    PROCEDURE getdata(dept_no IN VARCHAR2,oc_result_cursor OUT sys_REFCURSOR)
    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 chck;
    the above package is giving me an error:
    10/29 PL/SQL: SQL Statement ignored
    10/43 PL/SQL: ORA-22905: cannot access rows from a non-nested table
    let me know what needs to be changed

    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
    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 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 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.
    When you post provide your 4 digit Oracle version.

  • Dynamic security using Security table in SSAS Tabular model

    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
    User1 should see all countries but Only 2,4 Customers
    User2 should see all customers but Only 2,3 countries
    User3 should see all Customers and Countries
    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.

    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:
    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?

    try to google something about ORACLE TABLE CAST
    SELECT ot.yourcolumn
       TABLE(CAST(yourplsqltablevariable AS userdefinedoracletype)) otE.g.

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

    Hi All,
    my procedure is like this
    cursor c1 is select ----------------------
    assigning to variables
    validations on that variables
    --50 validations are here --
    insert into a table
    we have created indexes on primary keys,
    i want to use
    CURSOR a_cur IS
    SELECT program_id
    FROM airplanes;
    TYPE myarray IS TABLE OF a_cur%ROWTYPE;
    cur_array myarray;
    OPEN a_cur;
    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---***
    nsert into a table
    CLOSE a_cur;
    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.
      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));
    ...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....

    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">
    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?

    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.

  • 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

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

Maybe you are looking for

  • How to remove apps in iOS 5?

    How to remove apps in iOS 5? I press and hold an Icon like would in iOS4 it starts shaking but x mark does not appear to delete.

  • Boot Camp and Windows 7

    I know this has probably been asked, but the search results are all about some newer systems and compatibility issues... My XP Boot Camp is now officially screwed up beyond any reasonable hope of recovery. I was going to wipe BC and go with Windows 7

  • Lion 10.7 Battery Problem?

    Hello, I have a June 2010 MBP and am now using the Lion OS. Since installing the OS I get - AT BEST - two hours of battery time. The indexing is long done and my settings are at less than 50% brightness, no backlit keyboard, wifi on, and running 3 pr

  • Admin Order Template gets displayed on sorting in genericsearch.jsp page

    Dear All, Standard Order template is customized and this template is available to all the customers who login to webshop. Admin creates this template and it is visible to all the customers who click on the New Order Template link and can transfer the

  • Lightroom 5 sizing issue

    Grrrr, up until about a week ago, lightroom 5 was exporting 23mb raw files as 18/19 mb jpeps. Then all of a sudden the same 18mb jpeg is now exporting as a 6.4mb jpeg! I cant work out what has happened. File settings remain unchanged at quality 100,