PLSQL table name substitution

I want to create a PLSQL process that deletes rows from a table I identified by an item.
This does not work....throws the Error:
ORA-06550: line 4, column 29: PL/SQL: ORA-00903: invalid table name ORA-06550: line 4, column 1: PL/SQL: SQL Statement ignored
declare
begin
delete from staging.:P110_TABLE_NAME;
end;
What am I doing wrong here in the P110_TABLE_NAME substitution?
Edited by: user581839 on Dec 23, 2008 4:32 PM

Try it this way
declare
begin
Execute immediate 'delete from staging.' || trim( :P110_TABLE_NAME);
end;Varad

Similar Messages

  • Table Name Substitution with a varaible

    I have the following procedure....
    LOOP
    FETCH table_cur INTO table_rec;
    EXIT WHEN NOT table_cur%FOUND;
    TableID := table_rec.TableName;
    Office := table_rec.OfficeNum;
    Client := table_rec.CliNum;
    IF Office = 'Y' AND Client = 'Y' Then
    UPDATE TableID
    SET OfficeNum = (SELECT OfficeNum
    FROM Comd02a
    WHERE Comd02a.CliNum = TableID.CliNum
    AND Comd02a.LoanNum = TableID.LoanNum);
    END IF;
    END LOOP;
    CLOSE table_cur;
    TableID is a vaiable and I keep coming back with an error... How
    do I make a reference to a table through a variable...
    Thanks in Advance
    Sally
    null

    Brian Lelek (guest) wrote:
    : Rashmi Rungta (guest) wrote:
    : : Hi,
    : : You cannot make a direct reference to a table name thru a
    : : variable. You have to use dynamic sql.
    : : Hope it helps. Let me know if you need further information on
    : how
    : : to use dynamic sql.
    : : Rashmi
    : : Sally (guest) wrote:
    : : : I have the following procedure....
    : : : LOOP
    : : : FETCH table_cur INTO table_rec;
    : : : EXIT WHEN NOT table_cur%FOUND;
    : : : TableID := table_rec.TableName;
    : : : Office := table_rec.OfficeNum;
    : : : Client := table_rec.CliNum;
    : : : IF Office = 'Y' AND Client = 'Y' Then
    : : : UPDATE TableID
    : : : SET OfficeNum = (SELECT OfficeNum
    : : : FROM
    : Comd02a
    : : : WHERE Comd02a.CliNum =
    : TableID.CliNum
    : : : AND Comd02a.LoanNum =
    : : TableID.LoanNum);
    : : : END IF;
    : : : END LOOP;
    : : : CLOSE table_cur;
    : : : TableID is a vaiable and I keep coming back with an
    error...
    : : How
    : : : do I make a reference to a table through a variable...
    : : : Thanks in Advance
    : : : Sally
    : The previous response is correct. You must use dynamic SQL.
    : With dynamic SQL, you create a string in a varchar field that
    : contains the SQL statement. Then you pass that string to
    Oracle
    : for execution. I think that orange and white book has a good
    : explanation of dynamic SQL. My copy of the book is not here,
    : but I can look it up in a few days if you are still having
    : trouble.
    : By the way, you may want to consider using a "cursor for
    loop".
    : This code is more simple because you don't need and OPEN,
    FETCH,
    : EXIT, or CLOSE. See below:
    : FOR table_rec IN table_cur
    : LOOP
    : END LOOP;
    : Brian
    Hello,
    Yes, you need to use dynamic SQL. If you are using oracle 7 or
    8.0.x, you can use the bundled package dbms_sql to do the dynamic
    SQL. If you are using 8i (8.1.5), the PL/SQL is improved to do
    the dynamic SQL directly. You can now do for example:
    begin
    execute immediate 'update '

  • Table Name Substitution with a variable

    I have the following procedure....
    LOOP
    FETCH table_cur INTO table_rec;
    EXIT WHEN NOT table_cur%FOUND;
    TableID := table_rec.TableName;
    Office := table_rec.OfficeNum;
    Client := table_rec.CliNum;
    IF Office = 'Y' AND Client = 'Y' Then
    UPDATE TableID
    SET OfficeNum = (SELECT OfficeNum
    FROM Comd02a
    WHERE Comd02a.CliNum = TableID.CliNum
    AND Comd02a.LoanNum = TableID.LoanNum);
    END IF;
    END LOOP;
    CLOSE table_cur;
    TableID is a vaiable and I keep coming back with an error... How
    do I make a reference to a table through a variable...
    Thanks in Advance
    Sally
    null

    Hi Sally,
    The way this is usually handled in Oracle is to use the DBMS_SQL
    package provided with the database to run Dynamic SQL, although
    I hear that Oracle 8.1.5 (8i) supports Dynamic SQL without the
    use of the DBMS_SQL package. I can only personally tell you
    that DBMS_SQL has worked like a charm for me on several
    occasions. You'll find reference to this package in several
    places, but the best place for explanation is the Oracle Press
    book: Oracle PL/SQL Programming.
    Hope that helps,
    Rob
    Sally (guest) wrote:
    : I have the following procedure....
    : LOOP
    : FETCH table_cur INTO table_rec;
    : EXIT WHEN NOT table_cur%FOUND;
    : TableID := table_rec.TableName;
    : Office := table_rec.OfficeNum;
    : Client := table_rec.CliNum;
    : IF Office = 'Y' AND Client = 'Y' Then
    : UPDATE TableID
    : SET OfficeNum = (SELECT OfficeNum
    : FROM
    Comd02a
    : WHERE Comd02a.CliNum = TableID.CliNum
    : AND Comd02a.LoanNum =
    TableID.LoanNum);
    : END IF;
    : END LOOP;
    : CLOSE table_cur;
    : TableID is a vaiable and I keep coming back with an error...
    How
    : do I make a reference to a table through a variable...
    : Thanks in Advance
    : Sally
    null

  • BRIDGE statement in a loop : dynamic destination and source table names ...

    Hello,
    I can't find the right syntax to do what I need, if it's possible :
    Context :
    I work actualy on a migration from MS Access applications to Oracle (datas only). So I copied all MS Access Tables into Oracle and created manualy all the relationnal constraints like primary and foreign keys ('cause constraints are not included in 'Copy to Oracle').
    I Have often to refresh my datas, because the MS access applications are still in use. Therefore I wrote PL/SQL scripts. They do the folowing, using dynamic SQL with 'Execute Immediate' statement :
    Script 1
    - disable all user's constraints
    - disable all user's triggers
    - truncate all user's tables
    (Here, I have to do a manual copy of all MS Access tables to Oracle, checking the Append check-box, because the BRIDGE statement doesn't support 'Execute Immediate', and wait...)
    Script 2
    - enable all user's constraints
    - enable all user's triggers
    Could someone let me know how Il could do the same as :
    For t in (select table_name from user_tables) loop
    -- Copy the datas from an Access table into the same Oracle table
    execute immediate ('BRIDGE ' || t.table_name || ' AS MyAccessConnName(select * from ' || t.table_name || ') APPEND') ;
    -- News flash ...
    dbms_output.put_line('Table ' || t.table_name || ' filled') ;
    end loop;
    -------------------------------------------------------------------------------------------------------------------------- ==> 00900. 00000 - "invalid SQL statement"
    If a dynamic table name substitution is applicable in the Bridge statement from a query, I take it with joice!
    Thank you for helping me...
    Daniel

    Hi Daniel,
    The BRIDGE statement is just an extra command I implemented in the SQL Developer worksheet script runner.
    It gets interpreted by SQL Developer and it dynamically creates (CREATE TABLE , INSERT INTO , SELECT ... ) statements and runs them against the connections specified.
    It was developed to improve certain migration features of SQL Developer. We haven't really spent any time developing it into a customer friendly statement to be used in custom scripts.
    Hence the lack of doc. But it is there and if you can make it work for yourself all the better.
    When I say "One way of doing what you want". I mean I haven't thought about your particular problem exhaustively and I wouldn't want you to take my solution as gospel :)
    If you are happy running a script in SQL Developer, but would rather not run 2 scripts , or cut and paste results around, you could SPOOL the results and execute them.
    --call your other scripts to disable constraints during the data move
    set echo off;
    set feedback off;
    set linesize 1000;
    set pagesize 0;
    set headsep off;
    set termout off;
    set verify off;
    set heading off;
    SET PAGES 0;
    SET HEAD OFF;
    spool c:\mydynamicscript.sql
    select 'BRIDGE ' || table_name || ' AS MyAccessConnName(select * from ' || table_name||');' from user_tables ;
    spool off
    @c:\mydynamicscript.sql
    --call another script to enable your constraints again
    Regards,
    Dermot.
    SQL Developer Team.

  • 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.

  • Can substitution strings be used for table name references?

    Hi,
    I was wondering if it's possible to use substituion strings for table names in SQL queries. This would allow for me to edit all references to a table at one location. For instance, if a table name or dblink changed, I could edit the substitution string or application item to ensure all the queries reference the new table.
    For example:
    select * from &table1.
    table1 would be the substitution string for the actual table name
    I know this is possible if I used a pl/sql function returning a query, but I would much rather use a substition string in a SQL query.
    Thanks in advance.
    Brian

    i think not
    because how create the fields of * in this case
    in the other because all is dynamic, i think that you obtain only an error

  • SQL/PLSQL Help - Table Name and Count on same line

    Hello,
    I need the following information returned:
    Table_Name, Current Table Count, Num_Rows.
    The table_name and num_rows are pulled from dba_tables where owner = 'XXXX'
    I can't figure out how to return this info.
    Sample of desired output and format
    Table_name Num_Rows Current Count
    AAAA 15 400
    ABBB 8000 8120
    Any help would be appreciated.
    Thanks - Chris

    May be this one helps you:
    declare
    cursor cur_cnt is
    select 'select ''' || table_name || ''', (select count(*) from ' || table_name || ') from dual' l_sql from user_tables;
    l_table_name varchar2(30);
    l_cnt number;
    begin
    dbms_output.put_line(rpad('Table Name',40)||rpad('RowCount',40));
    dbms_output.put_line('------------------------------------------------');
    for l_cur_cnt in cur_cnt
    loop
    execute immediate l_cur_cnt.l_sql into l_table_name, l_cnt;
    dbms_output.put_line(rpad(l_table_name,40)
    ||rpad(l_cnt,40));
    end loop;
    end;
    -Hari
    Hello,
    I need the following information returned:
    Table_Name, Current Table Count, Num_Rows.
    The table_name and num_rows are pulled from dba_tables where owner = 'XXXX'
    I can't figure out how to return this info.
    Sample of desired output and format
    Table_name Num_Rows Current Count
    AAAA 15 400
    ABBB 8000 8120
    Any help would be appreciated.
    Thanks - Chris

  • 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

  • How to dynamically change the table name inside a view

    Hi All,
    create table t_auto_feeds
    id number,
    table_name vachar2(100));
    insert into t_auto_feeds values(1,'T_FEED_POSITIONS');
    insert into t_auto_feeds values(2,'T_KAP_MTM');
    assume there are 100 records on id=1 in T_FEED_POSITIONS and 100 records of id=2 in T_KAP_MTM (id 1 is present only in t_feed_positions & id 2 is present only in t_kap_mtm)
    i need to create a view such that it needs to give the count of records based on the id
    create or replace view aa_view as
    select count(*), id from t_feed_position group by id
    union
    select count(*), id from t_kap_mtm group by id;
    I am getting a proper result when i query the view like select * from aa_view where id=1 but will the other union query seems to be a overhead?. I am having 10 such tables configured for different id in t_auto_feeds.so do i need to put 10 unions or is there a better way to handle this stuff.
    I know i can use a PLSQL block and dynamically build view structure, the problem is the view itself is configured in a table , so i cant write a proc for this.. can this aa_view be modified such that it queries only the table(using the t_auto_feeds ) which matches the id rather than the entire list.
    Kindly help me in this regard and let me know in case u need any further information from my side.

    >
    so do i need to put 10 unions or is there a better way to handle this stuff.
    >
    Yes - you need 10 unions
    Yes - there is a better way so that only one of the 10 queries does anything.
    You can use SYS_CONTEXT to control the query selection.
    Here is an example of using SYS_CONTEXT. Try this code in the SCOTT schema.
    create or replace context VIEW_CTX using SET_VIEW_FLAG;
    create or replace procedure SET_VIEW_FLAG ( p_table_name in varchar2 default 'EMP')
      as
      begin
          dbms_session.set_context( 'VIEW_CTX', 'TABLE_NAME', upper(p_table_name));
      end;
    select * from emp where 'EMP' = sys_context( 'VIEW_CTX', 'TABLE_NAME' );
    select * from emp1 where 'EMP1' = sys_context( 'VIEW_CTX', 'TABLE_NAME' );
    select * from emp2 where 'EMP2' =  sys_context( 'VIEW_CTX', 'TABLE_NAME' )
    exec set_view_flag( p_table_name => 'EMP' );
    exec set_view_flag( p_table_name => 'EMP1' );
    exec set_view_flag( p_table_name => 'EMP2');
    SELECT sys_context( 'VIEW_CTX', 'TABLE_NAME' ) FROM DUAL
    CREATE VIEW THREE_TABLE_EMP_VIEW AS
    select * from emp where 'EMP' = sys_context( 'VIEW_CTX', 'TABLE_NAME' )
    union all
    select * from emp1 where 'EMP1' = sys_context( 'VIEW_CTX', 'TABLE_NAME' )
    union all
    select * from emp2 where 'EMP2' =  sys_context( 'VIEW_CTX', 'TABLE_NAME' )
    SELECT * FROM THREE_TABLE_EMP_VIEWNote that you set the context for the table you want. This doesn't have to be a table name it could just be flag value
    -- use the emp table
    exec set_view_flag( p_table_name => 'EMP' );
    -- ue the emp1 table
    exec set_view_flag( p_table_name => 'EMP1' );
    -- use the emp2 table
    exec set_view_flag( p_table_name => 'EMP2');

  • Table(): invalid table name

    The following line is a part of a PLSQL procedure which takes object_reference as an argument.
    delete from table(deref(object_reference).nested_table) where column_value = 'something';
    Error: invalid table name. Why? How do I accomplish this correctly?

    Oracle 10.2 . Any table. It doesn't matter. Or does it?
    I'm trying to query against a nested table (also called collection) of an object to which I have a reference. This object may be in any (object) table. A more elaborate example:
    create type item_ty (
    code number
    create type items_ty as table of item_ty;
    create type box (
    items items_ty,
    member procedure put_item(code number),
    member function take_item(code number)
    create type body box is
    begin
    member procedure put_item(code number) is
    begin
    insert into table(deref(self).items) item_ty(code); -- ERROR: invalid table name
    end;
    member procedure take_item(code number) is
    begin
    delete from table(deref(self).items) where column_value = code; -- ERROR: invalid table name
    end;
    end;

  • Use table name in UPDATE statement as variable

    Hi All,
    I am using ORACLE 9i AIX base. I want to write following procedure:
    PROCEDURE update_header (
    p_care_msg_nbr IN NUMBER,
    p_care_msg_id IN NUMBER,
    p_care_msg_gkey IN NUMBER,
    p_old_status IN VARCHAR2,
    p_new_status IN VARCHAR2
    IS
    l_table varchar2(50);
    BEGIN
    l_table := 'CARE_EDI_MESSAGES';
    UPDATE '&l_table'
    SET status = p_new_status,
    changed = sysdate,
    changer = user
    WHERE care_msg_no = p_care_msg_nbr
    AND care_msg_id = p_care_msg_id
    AND gkey = p_care_msg_gkey
    AND status = p_old_status;
    END;
    I want to give the table name by passing value in a variable or parameter. Is it the write way or can I do this function in any other way.
    Pleae tell me in urgency.
    Thanks & Regards
    Hassan Raza

    This implies that you have several tables with identical or near identical structures, otherwise you will get errors if any of the mentioned columns do not exist in the table passed but ...
    You cannot use a substitution variable that way. Oracle will ask for a value when you try to create the procedure, and compile what ever value you supply into the procedure viz.
    SQL> CREATE PROCEDURE p AS
      2  l_id NUMBER;
      3  BEGIN
      4     SELECT id INTO l_id FROM &t;
      5  END;
      6  /
    Enter value for t: T
    old   4:    SELECT id INTO l_id FROM &t;
    new   4:    SELECT id INTO l_id FROM T;
    Procedure created.
    SQL> SELECT text FROM user_source WHERE name = 'P'
      2  ORDER BY line;
    TEXT
    PROCEDURE p AS
    l_id NUMBER;
    BEGIN
       SELECT id INTO l_id FROM T;
    END;Even if that is the effect you want, note that there are no quotes around the substitution variable in the CREATE statement.
    If you want to be able to pass the name of the table to the procedure, then you need to make the table name a parameter, then build the sql statement and execute it using EXECUTE IMMEDIATE. Something more like:
    PROCEDURE update_header (p_care_msg_nbr  IN NUMBER,
                             p_care_msg_id   IN NUMBER,
                             p_care_msg_gkey IN NUMBER,
                             p_old_status    IN VARCHAR2,
                             p_new_status    IN VARCHAR2,
                             p_table         IN VARCHAR2) IS
    l_sqlstr VARCHAR2(4000);
    BEGIN
       l_sqlstr := 'UPDATE '||p_table||' SET status = :b1 '||
                   'changed = sysdate, changer = user '||
                   'WHERE care_msg_no = :b1 and care_msg_id = :b3 and '||
                   'gkey = :b4 and status = :b5';
       EXECUTE IMMEDIATE l_sqlstr
          USING p_new_status, p_care_msg_nbr, p_care_msg_id, p_care_msg_gkey, p_old_status;
    END;HTH
    John

  • Table name issue accessing OATS schema using OBIEE

    We are attempting to integrate OATS 12.1 with OBIEE 11g for reporting purposes and encounter the following error when using the BI Administration tool to update a row count of a physical table or query using the Analysis tool against our target OATS schema. For example:
    There was an error while updating row count for
    "OTM.atg.com".."OTM"."View_Tests":
    [nQSError: 17011] SQL statement execution failed.
    [nQSError: 17001] Oracle Error code: 942, message: ORA-00942:
    table or view does not exist
    at OCI call OCIStmtExecute: select count(*) from
    OTM.View_Tests
    I tried this out with other tables such as "TO_TestCase"
    The reason for this error seems to be that our target schema contains tables that have quotes in the name when the table was created, which I understands enforces the preservation of letter case-- i.e. "Mixed_Case" names. Since this is not "our own" application, we don't really have any control over how the schema is created or the table/views named. Interestingly enough, the table appears in the BI Administration with the expected table columns, but the querying for row count and data fails.
    One way we've worked around this is to manually create a VIEW of the table of interest in the target schema using all capitals. This works, but seems unnecessarily messy, especially if we are interested in using a VIEW that is already created as part of the schema.
    I also found the following various discussions about setting the NQSConfig.ini file on line, but changing the value and restarting the OBIEE server doesn't seem to make a difference.
    # Case sensitivity should be set to match the remote
    # target database.
    CASE_SENSITIVE_CHARACTER_COMPARISON = ON;
    Are there other ways to get OBIEE to recognize mixed-case table names?
    Thanks!

    Bad day for good code. Have yet to spot any posted today... Sadly, yours is just another ugly hack.
    The appropriate method for using SQL*Plus substitution variables (in an automated fashion), is as command line parameters. Not as static/global variables defined by some other script ran prior.
    So if a script is, for example, to create a schema, it should look something as follows:
    -- usage: create-schema.sql <schema_name>
    set verify off
    set define on
    create user &1 identified by .. default tablespace .. quota ... ;
    grant ... to &1;
    --eof
    If script 1 wants to call it direct then:
    -- script 1
    @create-schema SCOTT
    If script 2 want to call it using an existing variable:
    -- script 2
    @create-schema &SCHEMA
    Please - when hacking in this fashion, make an attempt to understand why the hack is needed and how it works. (and yes, the majority of SQL*Plus scripts fall into the CLI hack category). There's nothing simple, beautiful, or elegant about SQL*Plus scripts and their mainframe roots.

  • Table name in from clause

    Hi Gurus,
    Each day I am creating a table dynamically and the table name is stored in log table.
    End of the day I want to see that tables data(want to create a report based on that table).
    select * from (
    select table_name from my_log
    where created_on=sysdate and table_name like '%sunil%');
    As we know, it will not work in sql, and I dont want to use plsql.
    Is there any way to get my requirements only using sql.
    Thanks,
    Sunil

    Sunil Jena wrote:
    Each day I am creating a table dynamically and the table name is stored in log table.Not the best of options. If you have purchased the Partitioning Option, use that instead. If not - give serious consideration to getting it as it is worth every cent.
    End of the day I want to see that tables data(want to create a report based on that table).
    select * from (
    select table_name from my_log
    where created_on=sysdate and table_name like '%sunil%');Not possible like that.
    It can be done using a pipeline table functions. Which would be the wrong choice IMO.
    A better option would be a partitioned view. This feature has been introduced with Oracle 7.3 I think it was. It supports partition-like pruning and enables you to have a view on several tables, but only the relevant table being hit for the actual query.
    Here's an example on 11.2.0.2. Note how the CBO uses the filter condition NULL is not NULL to remove no-relevant tables from the query.
    SQL> declare
      2          tabName         varchar2(30);
      3          nameList        TStrings;
      4          pviewSql        varchar2(32767);
      5 
      6          procedure W( line varchar2 ) is
      7          begin
      8                  DBMS_OUTPUT.put_line( nvl(line,chr(10) ) );
      9          end;
    10 
    11          procedure ExecSQL( sqlStmnt varchar2 ) is
    12          begin
    13                  W( 'SQL> '||sqlStmnt );
    14                  W( '' );
    15                  execute immediate sqlStmnt;
    16          exception when OTHERS then
    17                  W( SQLERRM(SQLCODE) );
    18          end;
    19  begin
    20          --// need to create some sample tables - will grab dictionary objects from
    21          --// the following schemas to populate the sample tables
    22          nameList := new TStrings( 'XDB','SYS','BILLY','APEX_040100','FLOWS_FILES' );
    23 
    24          --// format of the sampe table, e.g. TAB_1
    25          tabName := 'TAB_%n';
    26 
    27          --// drop the sample table if exists
    28          for i in 1..nameList.Count loop
    29                  ExecSQL( 'drop table '||replace(tabName,'%n',i)||' purge' );
    30          end loop;
    31 
    32          --// create the sample tables
    33          for i in 1..nameList.Count loop
    34                  ExecSQL(
    35  'create table '||replace(tabName,'%n',i)||'(
    36          object_id primary key,
    37          object_owner not null check(object_owner='''||nameList(i)||'''),
    38          object_type not null,
    39          object_name not null
    40  )
    41  nologging as
    42  select
    43          object_id,
    44          owner,
    45          object_type,
    46          object_name
    47  from       all_objects
    48  where      owner = '''||nameList(i)||''''
    49                  );
    50          end loop;
    51 
    52          --// create the partition view
    53          pviewSql := 'create or replace view PVIEW_TAB as ';
    54          for i in 1..nameList.Count loop
    55                  pviewSQL := pviewSQL || 'select * from '||replace(tabName,'%n',i);
    56                  if i < nameList.Count then
    57                          pviewSQL := pviewSQL || ' union all ';
    58                  end if;
    59          end loop;
    60 
    61          ExecSQL( pviewSQL );
    62  end;
    63  /
    SQL> drop table TAB_1 purge
    SQL> drop table TAB_2 purge
    SQL> drop table TAB_3 purge
    SQL> drop table TAB_4 purge
    SQL> drop table TAB_5 purge
    SQL> create table TAB_1(
            object_id primary key,
            object_owner not null check(object_owner='XDB'),
            object_type not null,
            object_name not null
    nologging
    as
    select
            object_id,
            owner,
            object_type,
            object_name
    from    all_objects
    where   owner = 'XDB'
    SQL> create table TAB_2(
            object_id primary key,
            object_owner not null check(object_owner='SYS'),
            object_type not null,
            object_name not null
    nologging
    as
    select
            object_id,
            owner,
            object_type,
            object_name
    from    all_objects
    where   owner = 'SYS'
    SQL> create table TAB_3(
            object_id primary key,
            object_owner not null check(object_owner='BILLY'),
            object_type not null,
            object_name not null
    nologging
    as
    select
            object_id,
            owner,
            object_type,
            object_name
    from    all_objects
    where   owner = 'BILLY'
    SQL> create table TAB_4(
            object_id primary key,
            object_owner not null check(object_owner='APEX_040100'),
            object_type not null,
            object_name not null
    nologging
    as
    select
            object_id,
            owner,
            object_type,
            object_name
    from    all_objects
    where   owner = 'APEX_040100'
    SQL> create table TAB_5(
            object_id primary key,
            object_owner not null check(object_owner='FLOWS_FILES'),
            object_type not null,
            object_name not null
    nologging
    as
    select
            object_id,
            owner,
            object_type,
            object_name
    from    all_objects
    where   owner = 'FLOWS_FILES'
    SQL> create or replace view PVIEW_TAB as select * from TAB_1 union all select * from TAB_2 union all select * from TAB_3 union all select * from TAB_4 union all select * from TAB_5
    PL/SQL procedure successfully completed.
    SQL>
    SQL> set autotrace on explain
    SQL> --// example of using the partition view, but querying only a single table in it
    SQL> select count(*) from pview_tab where object_owner = 'BILLY' and object_type = 'TABLE';
      COUNT(*)
            27
    Execution Plan
    Plan hash value: 3160219530
    | Id  | Operation             | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT      |           |     1 |    28 |     3   (0)| 00:00:01 |
    |   1 |  SORT AGGREGATE       |           |     1 |    28 |            |          |
    |   2 |   VIEW                | PVIEW_TAB |    31 |   868 |     3   (0)| 00:00:01 |
    |   3 |    UNION-ALL          |           |       |       |            |          |
    |*  4 |     FILTER            |           |       |       |            |          |
    |*  5 |      TABLE ACCESS FULL| TAB_1     |     1 |    28 |     3   (0)| 00:00:01 |
    |*  6 |     FILTER            |           |       |       |            |          |
    |*  7 |      TABLE ACCESS FULL| TAB_2     |     2 |    56 |    51   (2)| 00:00:01 |
    |*  8 |     TABLE ACCESS FULL | TAB_3     |    27 |   756 |     3   (0)| 00:00:01 |
    |*  9 |     FILTER            |           |       |       |            |          |
    |* 10 |      TABLE ACCESS FULL| TAB_4     |     1 |    28 |     3   (0)| 00:00:01 |
    |* 11 |     FILTER            |           |       |       |            |          |
    |* 12 |      TABLE ACCESS FULL| TAB_5     |     1 |    28 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       4 - filter(NULL IS NOT NULL)
       5 - filter("OBJECT_OWNER"='BILLY' AND "OBJECT_TYPE"='TABLE')
       6 - filter(NULL IS NOT NULL)
       7 - filter("OBJECT_OWNER"='BILLY' AND "OBJECT_TYPE"='TABLE')
       8 - filter("OBJECT_OWNER"='BILLY' AND "OBJECT_TYPE"='TABLE')
       9 - filter(NULL IS NOT NULL)
      10 - filter("OBJECT_OWNER"='BILLY' AND "OBJECT_TYPE"='TABLE')
      11 - filter(NULL IS NOT NULL)
      12 - filter("OBJECT_OWNER"='BILLY' AND "OBJECT_TYPE"='TABLE')
    Note
       - dynamic sampling used for this statement (level=2)
    SQL> select count(*) from pview_tab where object_owner = 'SYS' and object_type = 'TABLE';
      COUNT(*)
            33
    Execution Plan
    Plan hash value: 1404131350
    | Id  | Operation             | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT      |           |     1 |    28 |    51   (2)| 00:00:01 |
    |   1 |  SORT AGGREGATE       |           |     1 |    28 |            |          |
    |   2 |   VIEW                | PVIEW_TAB |    15 |   420 |    51   (2)| 00:00:01 |
    |   3 |    UNION-ALL          |           |       |       |            |          |
    |*  4 |     FILTER            |           |       |       |            |          |
    |*  5 |      TABLE ACCESS FULL| TAB_1     |     1 |    28 |     3   (0)| 00:00:01 |
    |*  6 |     TABLE ACCESS FULL | TAB_2     |    11 |   308 |    51   (2)| 00:00:01 |
    |*  7 |     FILTER            |           |       |       |            |          |
    |*  8 |      TABLE ACCESS FULL| TAB_3     |     1 |    28 |     3   (0)| 00:00:01 |
    |*  9 |     FILTER            |           |       |       |            |          |
    |* 10 |      TABLE ACCESS FULL| TAB_4     |     1 |    28 |     3   (0)| 00:00:01 |
    |* 11 |     FILTER            |           |       |       |            |          |
    |* 12 |      TABLE ACCESS FULL| TAB_5     |     1 |    28 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       4 - filter(NULL IS NOT NULL)
       5 - filter("OBJECT_OWNER"='SYS' AND "OBJECT_TYPE"='TABLE')
       6 - filter("OBJECT_OWNER"='SYS' AND "OBJECT_TYPE"='TABLE')
       7 - filter(NULL IS NOT NULL)
       8 - filter("OBJECT_OWNER"='SYS' AND "OBJECT_TYPE"='TABLE')
       9 - filter(NULL IS NOT NULL)
      10 - filter("OBJECT_OWNER"='SYS' AND "OBJECT_TYPE"='TABLE')
      11 - filter(NULL IS NOT NULL)
      12 - filter("OBJECT_OWNER"='SYS' AND "OBJECT_TYPE"='TABLE')
    Note
       - dynamic sampling used for this statement (level=2)
    SQL> select count(*) from pview_tab where object_type = 'TABLE';
      COUNT(*)
            78
    Execution Plan
    Plan hash value: 1006798202
    | Id  | Operation            | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT     |           |     1 |    11 |    62   (2)| 00:00:01 |
    |   1 |  SORT AGGREGATE      |           |     1 |    11 |            |          |
    |   2 |   VIEW               | PVIEW_TAB |    57 |   627 |    62   (2)| 00:00:01 |
    |   3 |    UNION-ALL         |           |       |       |            |          |
    |*  4 |     TABLE ACCESS FULL| TAB_1     |    17 |   187 |     3   (0)| 00:00:01 |
    |*  5 |     TABLE ACCESS FULL| TAB_2     |    11 |   121 |    51   (2)| 00:00:01 |
    |*  6 |     TABLE ACCESS FULL| TAB_3     |    27 |   297 |     3   (0)| 00:00:01 |
    |*  7 |     TABLE ACCESS FULL| TAB_4     |     1 |    11 |     3   (0)| 00:00:01 |
    |*  8 |     TABLE ACCESS FULL| TAB_5     |     1 |    11 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       4 - filter("OBJECT_TYPE"='TABLE')
       5 - filter("OBJECT_TYPE"='TABLE')
       6 - filter("OBJECT_TYPE"='TABLE')
       7 - filter("OBJECT_TYPE"='TABLE')
       8 - filter("OBJECT_TYPE"='TABLE')
    Note
       - dynamic sampling used for this statement (level=2)
    SQL> set autotrace offPartition views are no longer actively supported. It could be removed in future Oracle versions. However, it is a useful and existing feature, that is worth considering in some cases.

  • Table for Substitution rules for profit center

    Can anybody help me with the table name for Substitution rules for profit centers ?
    Thanks
    Sandeep

    Hi
    Check This tables
    CEPC - Profit Center
    CSKS - Cost Center
    Ranga

  • Bug Report: PLSQL variable names

    Hello,
    I am using Oracle 10g Release 2 and have come across an issue that I think maybe a bug.
    I don't seem to be able to declare a PL/SQL variable using the %TYPE attribute where the variable name is the same as the table name.
    For example:
    CREATE TABLE week_day
    ( week_day_id NUMBER NOT NULL
    , week_day VARCHAR2(3) NOT NULL );
    DECLARE
    week_day week_day.week_day_id%TYPE;
    BEGIN
    NULL;
    END;
    Executing this block of PL/SQL gives the following error:
    ERROR at line 2:
    ORA-06550: line 2, column 12:
    PLS-00320: the declaration of the type of this expression is incomplete or malformed
    ORA-06550: line 2, column 12:
    PL/SQL: Item ignored
    Normally I would prefix my variables in PL/SQL with l_ (or whatever depending on scope), but I discovered this "feature" when declaring a field in a PLSQL record.
    Is this a known restriction? I looked in the PL/SQL User Guide & Reference and could not find any reference to this restriction.
    Kind Regards
    Andy

    You shouldn't call variables the same as table names.Just to plus one BluShadow...
    SQL> CREATE TABLE week_day
      2  ( week_day_id NUMBER NOT NULL
      3  , week_day VARCHAR2(3) NOT NULL );
    Table created.
    SQL> DECLARE
      2  week_day week_day.week_day_id%TYPE;
      3  BEGIN
      4  NULL;
      5  END;
      6  /
    week_day week_day.week_day_id%TYPE;
    ERROR at line 2:
    ORA-06550: line 2, column 10:
    PLS-00320: the declaration of the type of this expression is incomplete or
    malformed
    ORA-06550: line 2, column 10:
    PL/SQL: Item ignored
    SQL> drop  TABLE week_day;
    Table dropped.
    SQL> CREATE TABLE week_day
      2  ( w_day_id NUMBER NOT NULL
      3  , w_day VARCHAR2(3) NOT NULL );
    Table created.
    SQL> DECLARE
      2  week_day week_day.w_day_id%TYPE;
      3  BEGIN
      4  NULL;
      5  END;
      6  /
    week_day week_day.w_day_id%TYPE;
    ERROR at line 2:
    ORA-06550: line 2, column 10:
    PLS-00320: the declaration of the type of this expression is incomplete or
    malformed
    ORA-06550: line 2, column 10:
    PL/SQL: Item ignored
    SQL> drop  TABLE week_day;
    Table dropped.
    SQL> CREATE TABLE week_days
      2  ( week_day_id NUMBER NOT NULL
      3  , week_day VARCHAR2(3) NOT NULL );
    Table created.
    SQL> DECLARE
      2  week_day week_days.week_day_id%TYPE;
      3  BEGIN
      4  NULL;
      5  END;
      6  /
    PL/SQL procedure successfully completed.
    SQL> Cheers, APC
    Blog : http://radiofreetooting.blogspot.com/

Maybe you are looking for

  • How to use the prompt value in the report column

    Hi I have a report prompt column which is 'Adj Type' which holds values 10,20,30 and when user selects Adj Type = 10 then this value should be passed to report column. For Eg. Column 1 value is 10 and this should multiple with prompt value and the ou

  • Pop up windows in Indesign to be used for definitions in PDF

    Does anyone know how I can create a popup window to open when hovering over a word when the file is exported into a pdf? We need "definitions" to appear over difficult words in the PDF book. Any help would be greatly appreciated. Pam

  • Roll back User deleted

    Hi, I have deleted a user in my database by accident. How do i restore it. My database is oracle Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production (RAC) working on solaris 5.0 Can any one help how to restore(i want the user

  • Rfc log on failed user SAPSYS

    Hi, We are getting below alerts RFC/CPIC logon failed Reason=24 Type=R client:000 user:SAPSYS Also RFC/CPIC logon failed Reason=1 Type=S client:000 user:SAPSYS what is the diff between these two alerts and what is the reason for getting this. Regards

  • Need a bit of guidance with ip helper-address on a L3 switch

    Hi All, Happy New Year! Could some one be kind enough to have a look at a PT file for me and tell me where I am going wrong please?. It's a practice one for a college assignment I am working on, for which I have to submit an original network, and the