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

Similar Messages

  • How to dynamically change the table name for a update statement

    Hi All,
    I need to update a coulumn xyz in either of tables abc and efg based on some condition.
    I wrote a cursor which has union of two queries(one querying abc and other efg)
    Now based on some inparameter only one will be executed at a time.
    And based on some condition a coulumn xyz needs to be updated which is in either of the table.
    As the update condition is same
    Update abc/efg set xyz=data where condition
    I am looking to initialize a variable like v_tname based on some condition and update like
    update v_tname .........
    (Exactly that may not be like so, But looking a technique like this)
    Please help

    If there is only two tables you'll need to update then you are better off using static SQL and implementing something like this instead:
    DECLARE
            update_condition        BOOLEAN;
    BEGIN
            -- initialize update_condition
            update_condition := <some_boolean_check>;
            IF update_condition
            THEN
                    UPDATE abc
                    SET    xyz = some_val
                    WHERE  some_col = some_other_val;
            ELSE
                    UPDATE fgh
                    SET    xyz = some_val
                    WHERE  some_col = some_other_val;   
            END IF;
    END;
    /Hope this helps!

  • Dynamically changing the flatfile name..

    Hi friends,
    I 'm Getting data from 30 Flat files...all are with same structure but different data.. .. all these files are now in Application server...
    now i want to upload data into with a single DataSource and to ODS with process chains..
    so, how can i dynamically change the file name in Data Source level.. i saw previous threads.. in that.. through Routines.. we can solve this problem.. but I dont know ABAP code... so, can any one plz give me the exact code.. what i have to write...exact coding..
    <b>
           I already post this question in forums.... but evry one gave different options.. some  one gave the function module..
    BAPI_IPACK_CHANGE    and BAPI_IPACK_START.
      and some one gave  other function module.. like .. EPS_GET_DIRECTORY_LISTING
    i tryd for All these options.. but i'm not getting the exact solution... even i'm unable to pass the parameters also.. beacuse.. in that function what parameters can i pass....</b>
    can u plz suggest me the solution..
    Thanks
    Babu

    Hi  Friends,
      for the above requirement i had write the bellow coding in the routine.. it is working.. but the problem is.. it was loading  only  the last file..(30 th file  data only..)
    data : z1(50) type c,
             z2 type c,
             z3(50) type c,
             z4(50) type c.
             Z2 = 1.
       Do 5 times.
              z1 = 'C:\Documents and Settings\e10035\Desktop\'.
              z3 = '.csv'.
              concatenate z1 z2 z3 into z4.
              p_filename = z4.
              z2 = z2 + 1.
        Enddo.
    SO, CAN YOU PLZ SUGGEST ME.. when ever the file name was changing in the loop.. that automatically should load into the  PSA ..
    plz... plz.... help regarding this..
    Bbau

  • How can I change the administrator name?

    I'm getting ready to sell my old I-mac. How do I change the administrator name or delete it?

    Follow these instructions step by step to prepare a Mac for sale:
    Step One - Back up your data:
           A. If you have any Virtual PCs shut them down. They cannot be in their "fast saved" state. They must be shut down from inside Windows.
           B. Clone to an external drive using using Carbon Copy Cloner.
              1. Open Carbon Copy Cloner.
              2. Select the Source volume from the Select a source drop down menu on the left side.
              3. Select the Destination volume from the Select a destination drop down menu on the right
                  side.
              4. Click on the Clone button. If you are prompted about creating a clone of the Recovery HD be
                  sure to opt for that.
                   Destination means a freshly erased external backup drive. Source means the internal
                   startup drive.
    Step Two - Prepare the machine for the new buyer:
              1. De-authorize the computer in iTunes! De-authorize both iTunes and Audible accounts.
              2, Remove any Open Firmware passwords or Firmware passwords.
              3. Turn the brightness full up and volume nearly so.
              4. Turn off File Vault, if enabled.
              5. Disable iCloud, if enabled: See.What to do with iCloud before selling your computer
    Step Three - Install a fresh OS:
         A. Snow Leopard and earlier versions of OS X
              1. Insert the original OS X install CD/DVD that came with your computer.
              2. Restart the computer while holding down the C key to boot from the CD/DVD.
              3. Select Disk Utility from the Utilities menu; repartition and reformat the internal hard drive.
                  Optionally, click on the Security button and set the Zero Data option to one-pass.
              4. Install OS X.
              5. Upon completion DO NOT restart the computer.
              6. Shutdown the computer.
         B. Lion and Mountain Lion (if pre-installed on the computer at purchase*)
             Note: You will need an active Internet connection. I suggest using Ethernet if possible because
                       it is three times faster than wireless.
              1. Restart the computer while holding down the COMMAND and R keys until the Mac OS X
                  Utilities window appears.
              2. Select Disk Utility from the Mac OS X Utilities window and click on the Continue button.
              3. After DU loads select your startup volume (usually Macintosh HD) from the left side list. Click
                  on the Erase tab in the DU main window.
              4. Set the format type to Mac OS Extended (Journaled.) Optionally, click on the Security button
                  and set the Zero Data option to one-pass.
              5. Click on the Erase button and wait until the process has completed.
              6. Quit DU and return to the Mac OS X Utilities window.
              7. Select Reinstall Lion/Mountain Lion and click on the Install button.
              8. Upon completion shutdown the computer.
    *If your computer came with Lion or Mountain Lion pre-installed then you are entitled to transfer your license once. If you If your computer came with Lion or Mountain Lion pre-installed then you are entitled to transfer your license once. If you purchased Lion or Mountain Lion from the App Store then you cannot transfer your license to another party. In the case of the latter you should install the original version of OS X that came with your computer. If this is not possible then simply erase the drive. You need to repartition the hard drive as well as reformat it; this will assure that the Recovery HD partition is removed. See Step Three above. You may verify these requirements by reviewing your OS X Software License.

  • How can I change the tag name in cursor statement?

    Hi
    I have two tables: TableA and TableB. I want generate a XML file using XSU12 from these two tables, the XML structure like:
    <ROWSETA>
    <ROWA num="1">
    <A1></A1>
    <A2></A2>
    <A3>
    <A3_ROW num="1">
    <B1></B1>
    <B2></B2>
    </A3_ROW>
    <A3_ROW num="2">
    <B1></B1>
    <B2></B2>
    </A3_ROW>
    </A3>
    </ROWA>
    </ROWSETA>
    How can I change the tag name and attribute for "A3_ROW"?
    Thanks in advance!
    null

    In short, you can't.
    You can use the column alias as you're already doing to change the name of the "A3" part of "A3_ROW" but you cannot change the "_ROW" part of "A3_ROW". This is added automatically.
    You can combine the results of XSU with an XSLT stylesheet (made very simple if you're using XSU by working with Oracle XSQL Pages) to change the name of any element or completely restructure the XML output into a target XML, HTML, or text format.

  • How to look for the Table Name

    Hi Friends,
    Sometimes we need to download the table for the desired information if the same is not available from a particular report. How to look for the table name? Is there a report or a particular feild, where we can find the name of the particular table?
    Thanks for the assistance.
    Regards

    Hi Friend,
    If you want to see the structures then go to SE11. Sometimes it happens that you cannot find the table names but only fields. In such case, if you want to find the Table names which is not available, then go to SE90.
    Abap Dictionary > Fields > Table Fields.
    Now Enter the Field name in Right Hand Side of the screen then Execute. You will see the all tables by which that Fields are used.
    Regards,
    Jigar

  • How can I change the account name in iCloud.  My email has changed and I want to change it on iCloud.

    How can I change the account name in iCloud.  My email has changed and I want to change it on iCloud.

    To change your iCloud ID, go to Settings>iCloud, tap Delete Account, then sign back in with the new ID.  This deletes the account and your iCloud data from your device, but not from iCloud.  Provided you are signing back into the same account, your iCloud data will reappear on your device when you sign back in.
    To avoid losing photo stream photos, save them to your camera roll (if not already there) before deleting the account.  To do this, open your my photo stream album, tap Edit, tap the photos, tap Share, then tap Save to Camera Roll.
    To change the ID on your Mac, go to System Preferences>iCloud, sign out, choose Delete for all the prompts (your data will still be in iCloud), then sign back in with the changed ID.

  • How to find out the table name

    hi,
    how to find out the table name in which the data from a particular structure in a particular screen is saved,
    please tell me the procedure to find out the table name for saving the structure data that is inputted at runtime.
    Thanks,
    chinnu

    Hi Chinnu,
    Below are the tables that are referred to find out the table names
    DD02L Table contains the SAP Tables.
    DD02T Table contains the SAP Table Texts.
    DD01L Table contains the Domains
    DD01T Table contains the Domain Texts.
    DD03L Table contains the Table Fields.
    DD03T Table contains the Table Field Texts. (Language Dependent)
    DD04L Table contains the Data Elements.
    DD04T Table contains the Data Element Texts.
    DD05s Table contains the Foreign Key Fields
    last words with L and T only. L->Database Fetch T-> Text
    And the procedure to retrive the table name is as follows
    1. Go to se11
    2. Enter table name DD03T and execute
    3. In the next screen you can find Tables, fields, test etc. there you can enter the field name in the fields 
      and execute.
    4. you can get all tables which contains the field.
    I hope this will solve your problem
    Regards,
    Chandru

  • Changing the table name while drill down at the dashboard query

    I have a DAY fact table that has about 1B rows.
    The purpose of this table is to store on hand quantity for each item per day.
    On the presentation layer I have a dashboard that will display average on hand qty per year and then user can drill down to quarter/month/week and then by day level to see the actual value at evey level.
    Its hard to run aggregation on fly as all my 3 TEMP tablespace 32gb each filled and then I get error can not extent TEMP file.
    So I thought I will do the aggregation at the database level and store the aggregated data in another table. So at first dashborad will read this new aggregated table to display qty at yearly. As soon as user drill down to quarter the dashbord should query the actual DAY fact table by filtering for specific year and quarter.
    IS it possible? Can I change the table name while I drill down to lower level?
    Thanks in advance.

    Hi use,
    Yes. This is possible in OBIEE. You need to use Action Links to have navigation between reports. The main idea is to have 2 analysis. One with your aggregated data by year (using your aggregated table), and another one with the rest of the hierarchy and data (using normal fact table)
    You add an action link on this report, that can navigate to the second report. showing "the details" (in your case would be the rest of the time dimension).
    Please refer to http://www.rittmanmead.com/2010/07/obiee-11gr1-action-framework-and-conditions/ for actions links.
    Another way is to create 2 analysis, then go to the 2nd analysis, and filter the column year as "Is based on results of other analysis" and you select there the first analysis. In this case when you click on the year in the first analysis, this value will be passed to the second analysis so you can filter the rest of the hierarchy based on the year you clicked on the first analysis.
    If helpful, assign points.
    J.

  • When bates numbering a .pdf in XI, how can I change the file name to include the bates number AND its name?  I know under file output, there is an option for either/or.  I want both.  Thank you.

    when bates numbering a .pdf in XI, how can I change the file name to include the bates number and the file name?  I know under "file output: it's either/or.  I need both.  Thanks!

    Long ago I wrote a little demo using the touch command. Check out the following thread:
    http://forums.ni.com/ni/board/message?board.id=170&message.id=25128#M25128
    LabVIEW Champion . Do more with less code and in less time .

  • HT201240 I have a new macbook pro that did not have a disk, OS X was pre installed  so how can i change the administrators name and password, it did not migrate properly from my hard drive.., so how do i

    I have a new macbook pro that did not have a disk, OS X lion 7.3.4 was pre installed  so how can i change the administrators name and password, it did not migrate properly from my hard drive.., now there is some mysterious administrator name and or password??

    See #5
    Step by Step to fix your Mac

  • How do I change the table to start from right to left

    How do I change the table to start from right to left

    iWork apps have bugs that make them unsuitable for RTL scripts in various ways.  You might be better off using a different app if your work has a lot of RTL text.

  • How can i change the account name to our firm's name?

    how can i change the account name to our firm's name?

    The name that appears in Adobe Send is the name that you used when you created your Adobe ID.  You can update this by clicking on your name in the upper-right corner and selecting My Information ...
    Once the My Information dialog appears, you can change the First Name and Last Name on the account.  Note that you're updating your Adobe ID, so in many places where you use that Adobe ID, it will display with those names. (Some Adobe sites, such as this forum, use other screennames; those would not be affected.)

  • How can I change the location name my iPhone pulls up when I am home. The info that pulls is not correct?

    How can I change the location name my iPhone pulls up when I am home. The info that pulls is not correct?

    If the size of the iPhone backup is putting you over the edge you have bigger problems than just this backup. You really need to solve the fundamental problem of your C: partition being too small. Even if you could solve the iPhone problem something else will come up soon that will again challenge your disk space. New drives can be had for well under $100, and even a 500 GB drive is only a little more than $100. This would be a good time to upgrade. You can even clone your current drive AND increase the partition size in one step with disk imaging software such as Acronis True Image.

  • Dynamically pick the table names in data flow task SSIS

    Hi All,
    I want to create a SSIS package which loads the data to a table on the other server every day. I have around 250 tables to load everyday and source and destination table names are available in a metadata table, table names have to read from the metadata
    table and data should be loaded. Is there a way that we can configure the source and destination table names dynamically in Data flow task?
    I am newbie to SSIS can any help with the solution for this problem.

    You can do that, not a big deal. The underlying problem is say suppose you constructed a ETL based on some x source and y destination and have put x(3 columns) as source and y destination(3 columns).. As you said if we have choice of dynamically pick the
    table names.. ETL might fail when you face below situation
    source x(3 columns)   destination y (4 columns) and there will be no mapping as it is dynamic. Sometimes mapping also fails even if the source and destination have same number of columns. If you still want to do... follow below steps:
    Create two variables:
    1.variable1 , datatype string
    2.variable datatype string  
    take one execute sql task, pick your source table names dynamically as you desired from metadata table \
    "SELECT sourcetblname as Res FROM @metadata WHERE ID=1" in sql statement and then go to name the result name as Res (I meant same as table alias) and map it to variablename1
    And in variable2 go to expression and write "Select * from "+@[User::variable].. and this will be your constructed dynamic command for oledb destination.
    And connect that execute sql task to (Data flow task)oledb source and choose data access mode as sql command with variable,and choose variable2. below is the diagram.
    - please mark correct answers

Maybe you are looking for

  • Pictures won't load in Safari, or any other browser

    I have an intermittent problem where internet pictures won't load. This seems to happen mostly on social networking or picture intensive sites. I've particularly had trouble with myspace, livejournal, facebook, flickr, okcupid, etc., but it is not li

  • Error while using ADF map component

    I am facing problem while using ADF map component to display geographical addresses on the map. Steps I have followed are as follows : 1. I have created a simple table with structure. location_name varchar2(20), longitude number(10), latitude(10) Thi

  • Text are not coming to my iPhone

    Since my last update my messages are not coming to my phone just the iPad

  • BOXI R2 deployment on Solaris, data access to SQL Server and DB2

    <p>Have you deployed BusinessObjects XI Release 2 on Solaris and are accessing Microsoft SQL server 2000/2005? How about DB2? We had planned on using JDBC for SQL Server, and StarSQL 5.x  for DB2. We are having trouble with configuration planning.</p

  • Ms word tables borders and shading

    I'm using the "word tables borders and shading.vi" and trying to put a border around the first row including between columns and the "inside line style" active x function in the word_set_table_borders.vi is being ignored. The file is attached. Open t