View definition using Temporary table

I am trying to create a view using a global temporary table Odyssey.HMSg_ReportGeneral :
create or replace view Odyssey.av_hms_TmpTbl_rpt_ClsGndr4dtsSub1
as select nvl(p.Gender,'Either') gender, bldg.Building Bldg, bldg.Site_Name Parent1, bldg.Room_Name name,
bldg.Building_Name Parent2, bldg.facility_sk_fk facility_sk, nvl(pc.Class,'Unspecified') Class, p.patron_sk,
count(t1.Patron_SK_FK) NumOccupants, nvl(pc.listing_order,0) ListOrd
from Odyssey.HMSg_ReportGeneral g,Odyssey.av_hms_rpt_ThisAssignmentLevel fa3
join Odyssey.av_hms_rpt_FacilityStructure bldg on(bldg.facility_sk_fk = fa3.facility_sk_FK and
(bldg.effectivedate is null or(bldg.effectivedate <= g.Date2 and(bldg.enddate is null or
bldg.enddate >= g.Date2)))) left outer join Odyssey.av_hms_rpt_NumOccupantsNoCount t1
on(t1.Facility_SK = bldg.facility_sk_fk and
(t1.elementstart is null or(t1.elementstart <= g.date2 and(t1.elementend is null or
t1.elementend >= g.date2)))) left outer join Odyssey.csdp_patron p
on(p.patron_SK = t1.patron_SK_FK) left outer join Odyssey.av_hms_rpt_PatronClass pc
on(pc.Patron_SK_FK = t1.Patron_SK_FK and(pc.effectivedate is null or (pc.effectivedate <=
g.date2 and(pc.enddate is null or pc.enddate >= g.date2))))
where fa3.effectivedate is null or(fa3.effectivedate <= g.Date1 and(fa3.enddate is null or fa3.enddate >= g.Date1))
group by bldg.Site_Name, bldg.Building_Name,bldg.Building, pc.Class, pc.listing_order, p.patron_sk, p.Gender,
bldg.facility_sk_fk, bldg.Room_Name
I get an error :
ORA-00904: "G"."DATE2": invalid identifier
If I removed all references to the global temporary table,
the view compiles fine - references to any of the columns in the temporary table give the ORA-00904.
Any suggestions ?
(FYI we are converting a database from Sybase to Oracle and have almost 20 views like this)
Thanks for the help

Hi
After some test following I got following code to compile.
create or replace view Odyssey.hms_TmpTbl_rpt_ClsGndr4dtsSub1 as
select nvl(p.Gender,'Either') gender,
        bldg.Building Bldg,
        bldg.Site_Name Parent1,
        bldg.Room_Name name,
        bldg.Building_Name Parent2,
        bldg.facility_sk_fk facility_sk,
        nvl(pc.Class,'Unspecified') Class,
        p.patron_sk,
        count(t1.Patron_SK_FK) NumOccupants,
        nvl(pc.listing_order,0) ListOrd
from
        Odyssey.HMSg_ReportGeneral g
        join
        Odyssey.av_hms_rpt_ThisAssignmentLevel fa3 on
                fa3.effectivedate is null
            or  (
                    fa3.effectivedate <= g.Date1
                and     (   fa3.enddate is null
                    or  fa3.enddate >= g.Date1
        join
        Odyssey.av_hms_rpt_FacilityStructure bldg on
            (   bldg.facility_sk_fk = fa3.facility_sk_FK
            and     (   bldg.effectivedate is null
                or     (   bldg.effectivedate <= g.Date2
                    and (   bldg.enddate is null
                        or  bldg.enddate >= g.Date2
        left outer join
        Odyssey.av_hms_rpt_NumOccupantsNoCount t1 on
            (   t1.Facility_SK = bldg.facility_sk_fk
            and (   t1.elementstart is null
                or  (   t1.elementstart <= g.date2
                    and (   t1.elementend is null
                        or  t1.elementend >= g.date2
        left outer join
        Odyssey.csdp_patron p on
            (   p.patron_SK = t1.patron_SK_FK
        left outer join
        Odyssey.av_hms_rpt_PatronClass pc on
            (   pc.Patron_SK_FK = t1.Patron_SK_FK
            and (   pc.effectivedate is null
                or  (   pc.effectivedate <= g.date2
                    and (   pc.enddate is null
                        or  pc.enddate >= g.date2
group by
        bldg.Site_Name,
        bldg.Building_Name,
        bldg.Building,
        pc.Class,
        pc.listing_order,
        p.patron_sk,
        p.Gender,
        bldg.facility_sk_fk,
        bldg.Room_NameI think you can't mix old and new type of writing
you have to do the join
between Odyssey.HMSg_ReportGeneral
and Odyssey.av_hms_rpt_ThisAssignmentLevel
to have Odyssey.HMSg_ReportGeneral in the join statement later on.

Similar Messages

  • How to use Temporary Table in PL-SQL

    In MySQL there is no Temporary table concept.
    So for intermediate calculation I have created a table as below
    create table SequenceTempTable
    SessionId VARCHAR(50),
    Sequence VARCHAR(500),
    CreatedDate DATE
    ) ENGINE=MEMORY;
    Whenever I invoke a SP, I load the data into SequenceTempTable using Session Id as below
    CREATE PROCEDURE `GetSequence`(
    IN Start_Date VARCHAR(25),
    IN End_Date VARCHAR(25)
    BEGIN
    SELECT UUID() INTO v_SessionId;
    INSERT INTO SequenceTempTable values (v_SessionId,'1,2,5,3',now());
    required code
    DELETE FROM SequenceTempTable WHERE SessionId = v_SessionId;
    COMMIT;
    END;
    i.e. I have created a table as temporary table (created once),
    and load the data using Session Id and once session specific intermediate computation done,
    I deleted the session specific data.
    Could you give me examples of How to use Temporary table in PL-SQL code with respect to my above example.
    Because I have gone through creating Temporary table but I stuck with use in PL-SQL. I mean to say Is there any need of creating table in advance before invoking SP.
    And one more thing as in MySQL temp table I created which is using MEMORY engine i.e. this table will always be in MEMORY so there is no need of writing data on disk.
    Regards
    Sanjeev

    Hi Sanjeev
    Read about GTT here
    http://www.oracle-base.com/articles/8i/TemporaryTables.php
    GTT always contains just session specific data. \
    In case you want to use the GTT in the same session again you can use option
    ON COMMIT PRESERVE ROWS;
    Or if it is used just once in the session use can use
    ON COMMIT DELETE ROWS;
    Do remember that for GTT the data of one session can not be accessed in other session.
    Also you can go away with Delete from GTT if not used again in same session.
    Regards
    Arun

  • Using temporary tables in stored procedures

    Suppose that I have created a temporary table in a stored procedure using an "EXECUTE IMMEDIATE" statement. When I compile the procedure, that table is not created yet, so the compiler says that the table does not exist.
    What is the way of using temporary tables in stored procedures?

    It's a good practice to avoid using DDL statements being executed from stored procedures. "Truncate Table" via dynamic SQL from stored procedure is a different story and is useful in DSS environments.
    But if you insist on "creating" tables using Dynamic SQL from Stored Procedures then you must also embed your DML statements in Dynamic SQL to avoid compilation errors.
    Example:
    Create or Replace Procedure Proc_TestDynamicSQL is
    Begin
    Execute Immediate 'Create table myTable as select * from user_tables' ;
    Execute Immediate 'Update myTable set table_name = ''Test'' ' ; --two single quotes before and after the string "Test"
    End;
    In this case, Oracle wouldn't care about the table references during compilation.

  • Using Temporary Table in SSIS

    I have a dataflow task which puts the result in a temporary table. I want to put the table result in a flat file but is not able to do that. Can anyone help?
    Here is the sql code
    use adventureworks2008r2
    declare @totalcount as float
    declare @addcount as float
    declare @citycount as float
    declare @addperct as float
    declare @cityperct as float
    declare @temp table (name varchar (40), percentage float)
    set @totalcount = (select count(*)from person.Address)
    set @addcount = (select COUNT (*)from person.Address where AddressLine2 = null)
    set @citycount = (select COUNT (*) from person.Address where City is not null )
    set @addperct = 100*(@addcount/@totalcount)
    set @cityperct = 100*(@citycount/@totalcount)
    insert into @temp
    select 'Addressline2',ROUND (@addperct,2)
    insert into @temp
    select 'City',ROUND (@CITYPERCT,2)
    SELECT * FROM @temp

    What you're using is table variable and not temporary table. It will be out of scope outside batch so you cant use it anywhere after code.
    I think if you want to use it in further tasks you should use temporary tables (# tables) after setting RetainSameConnection property to true.
    See
    http://consultingblogs.emc.com/jamiethomson/archive/2006/11/19/SSIS_3A00_-Using-temporary-tables.aspx
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Using Temporary table as a target

    when i used real target table the integration works fine but when i used temporary table i got "com.sunopsis.tools.core.exception.SnpsSimpleMessageException: CKM not selected."
    I don't know why inspite of being importing the CKM
    do any one has any idea about this?

    Hi
    I have the same problem, and uncheck the option of FLOW CONTROL = NO and still remains error "com.sunopsis.tools.core.exception.SnpsSimpleMessageException: CKM not selected" .. Do you have any idea because I still ticking wrong?
    Edited by: user2080320 on 06-oct-2008 11:44
    Edited by: user2080320 on 06-oct-2008 11:45

  • Getting different result while running Dashboard SP Using Temporary table?

    Hi Experts
    I am getting different result when I run my dashboard procedure I am using temporary table with "ON COMMIT PRESERVE ROWS", below is the information
    I am running my attendance dashboard procedure which will display the employee attendance status based IN and OUT punches the status like AA-full day absent, GG-Full day Present, AG-First half absent,GA-Second half absent. Now when I run the first time my procedure for first time I am getting status AA even though IN and OUT timings are correct and if run it again then it is displaying the status for same employee as GG
    I didn't understand the problem where it is effecting the status

    ChakravarthyDBA wrote:
    It is procedure which will display the employee status, back end I am storing the procedure result in Temporary table with "ON COMMIT PRESERVE ROWS", when I run the procedure first time it is showing wrong information when I run it again second time then it is showing correct information. I don't know why the status is changing.
    first time employee status is AA --Full day absent and Second time is GG--Full day present (in both cases IN and OUT timings are correct only)
    is it effecting due to temporary table?
    So, you have a GTT and you're doing "something" with it and that "something" isn't what you expect.
    I've about summed up what you've posted and given us to work with. If you have specific examples please do share. Without them we're going to be of very little use to you.
    If you aren't getting the results you expect, it stands to reason that
    1) you don't understand the outputs you are supposed to be getting
    2) you have a bug in the code developed
    Please stop and think about this, pretend you are the one trying to help out. You've been given little to no information about a system you've never seen before. You need to explain your situation as you would if you brought someone in to your shop to show them this problem you are having ... the rules don't change just because it's not face-face interaction.
    Cheers,

  • SQL for View Definition using outer join

    Hello everyone,
    I am creating a view using the statement below
    SELECT *
    FROM table_a A
    ,table_b B
    ,table_c C
    WHERE A.sg_code = B.sg_code and
    B.st_code = 'E' and
    A.sg_code = C.sg_code(+) and
    C.st_code = 'T'
    The structure of the view is as follows
    View
    sg_code| Name | start_date | end_date |
    1 | Test |13-03-2008 | NULL |
    Table_a
    sg_code,Name
    Table_b
    sg_code,st_code,actual_date
    the view can have a null for the column 'end_date'
    This means there will not be a record inserted in the Table_b for end_date=null, there will only be a record for actual_date=start_date
    In this scenario when I query the view I am not seeing the newly created record just because there is a condition "C.st_code = 'T'" with the outer join on the sg_code.
    When I look into the individual tables I see the records.
    Table A
    Pg_code,Name
    1 Test
    Table B
    Id pg_code As_of_date
    1 1 13-03-2008
    How should I modify my view definition so that I can query the view even if there is a null for 'end_date'
    Thanks
    fm

    the last line should be:
    C.st_code(+) = 'T'
    by failing to include the (+) on that line, you made it NOT an outer join. an outer joined table must be outer joined on every where criteria, including to constants.

  • How to Use Temporary table on report builder

    Hi community!
    Well, i'm trying to build a temporary table based report in Oracle Report Builder. in "After Parameter Form Trigger" I've placed a stored procedure that populate a temporary table and I've based my report on it. The problem is Report shows no data. When i execute this procedure directly on database and i perform a select on my temporary table, it show all inserted data.
    I hope somebody can to help me because I tried many ways to build this report with my temporary table and always looks blank.

    Temporary tables are session specific.
    If particular session is closed then no data will be found on your temporary table in an another session.
    My suggestion is, on "After parameter form" trigger you directly populate the GTT without using procedure.
    Hope this will help.

  • Using temporary tables with a ref. cursor

    I want to use a temporary table to populate certain data and then return a ref cursor fetching data from the temporary table.
    1. Will this approach work ?
    2. Do I need to drop the temporary table ? Can I drop the table as a last statement in the stored proc (remember a ref cursor based on this table is to be returned as a out parameter).
    Please help.

    1. Will this approach work ?Sort of, just like it is possible to dig a trench with a spoon. It can be done, but why can't you just write a select that returns the data without storing intermediate versions of your processing somewhere.
    2. Do I need to drop the temporary table ?No. and you shouldn't.
    Can I drop the table as a last statement in the stored proc
    (remember a ref cursor based on this table is to be returned as a out parameter).No.
    If you really need to use a temporary table, it should be created one time when the application is installed, and should never be created in code.

  • Create view for Global Temporary Table

    if view is create for global temporary table so exactly how it works which helps regarding application performance.
    Regaards,
    Sambit Ray

    A view is just a stored query. It can be on global temporary tables or regular one, makes no difference.

  • Using temporary tables

    Hi,
    i've created a temporary table(session specific)
    and inserting records into it during a form's runtime
    (working on Oracle 9i,Forms/Reports 9i) that are
    to be again fetched while generating a report which is
    being called from the form itself.but nothing is
    being fetched once i called the report.but it's sure
    that the records are being inserted into it.
    so i want to know if any specific syntax should be
    followed while calling the report using
    web.showdocument(....) or else any other alternative
    in this case(but temporary table a must)
    Thanks,
    Suresh.

    How did you create the temporary table? Is it possible that you did not specify "ON COMMIT PRESERVE ROWS" and that you're issuing a commit after inserting the data?
    CREATE GLOBAL TEMPORARY TABLE tempTable (
      col1 number
    ) ON COMMIT PRESERVE ROWS;will keep the session's data in tempTable after a commit is issued. Otherwise, the data will be deleted when a commit is issued.
    If this isn't the problem, how are you sure that the records are being correctly inserted in the table? Are you able to query the table successfully?
    Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com/askDDBC

  • When to use PGA_AGGREGATE_TARGET and when to use temporary table space?

    Hi, all.
    I am a little confused with regard to when to use pga work area, and
    when to use temporary tablespace?
    Is there any one who could give me an advice or a document?
    Thanks in advance.
    Best Regards.
    Message was edited by:
    user507290

    You are more than a little confused... What has one to do with the other, do you think?
    All Oracle documentation is at http://tahiti.oracle.com - I suggest you start with the Concepts manual of your version

  • Can oracle temporary tables be used with distributed transactions?

    Hello,
    Does anybody know if temporary tables are supported with distributed transactions?
    We use a temporary table to store query results and see no problems when the JDBC driver (Type 2 or Type 4) is used with local transactions. The temporary tables are set for transaction-level data persistence (delete rows on commit).
    When we switch to JDBC/XA driver we occasionally get ORA-14450 error (java.sql.SQLException: ORA-14450: attempt to access a transactional temp table already in use).
    Many thanks...

    I have been able to use temporary tables on remote databases, so I don't think that it is forbidden. Of course, I'm not using JDBC so that might be a problem.
    The other thing that occurs to me is that you are doing something other than DML with the table e.g. trying to drop it. If that is the case you should re-read the documentation and remind yourself of the purpose of temporary tables.
    Cheers, APC

  • Creating temporary table in pl/sql block problem

    hello
    i have a problem in creating and using temporary table in pl/sql block
    please verify below block
    begin
    execute immediate 'create global temporary table alitemp1 (co_t varchar2(10),color varchar2(10))';
    insert into alitemp1 (co_t,color) values ('001','red');
    execute immediate 'DROP TABLE alitemp1';
    end;
    when i execute that block i will receive this error
    insert into alitemp1 (co_t,color) values ('001','red');
    ERROR at line 3:
    ORA-06550: line 3, column 14:
    PL/SQL: ORA-00942: table or view does not exist
    ORA-06550: line 3, column 2:
    PL/SQL: SQL Statement ignored
    i think it because that alitemp1 table don't create
    but two below block run fine
    begin
    execute immediate 'create global temporary table alitemp1 (co_t varchar2(10),color varchar2(10))';
    execute immediate 'DROP TABLE alitemp1';
    end;
    begin
    execute immediate 'create global temporary table alitemp1 (co_t varchar2(10),color varchar2(10))';
    end;
    select table_name from user_tables where table_name='ALITEMP1';
    TABLE_NAME
    ALITEMP1
    it means that problem is when the below line exists in block
    insert into alitemp1 (co_t,color) values ('001','red');
    if may please guide me

    In addition to the comments by Justin and 3360, you cannot do what you want the way you are doing it.
    All objects referred to in a PL/SQL block must exist at the time the block is compiled. In your case, since it is an anonomous block, that is run time. Since you are dynamically creating the temporary table you need to refer to it dynamically as well. More like:
    BEGIN
    EXECUTE IMMEDIATE 'create global temporary table alitemp1 (co_t varchar2(10),
                                                               color varchar2(10))';
    EXECUTE IMMEDIATE 'insert into alitemp1 (co_t,color) values (:b1,:b2)' USING '001', 'red';
    EXECUTE IMMEDIATE 'DROP TABLE alitemp1';
    END;However, don't do that it is a really bad idea. Just create the temporary table, if you really need it, once and use it in your processing.
    In most cases, things that SQL Server needs temporary tables for can be done easily in Oracle with a single SQL statement,
    John

  • Temporary Tables in Stored Procedure

    Hi,
    I am writing a stored procedure that will get data from different sources and generates a spreadsheet finally. Initial select gets the basic data and following selects merges data.
    For this I have created a table in the database, I am populating data into that table using same procedure and finally selecting data from that table to generate spreadsheet.
    Now I am planning to use TEMPORARY table instead of creating table in database. Can anyone tell me where I can view samples for temp tables?
    Which one is the better option in performance wise?
    or
    can I handle the whole scenario with cursor? any examples?

    Hi,
    Why can't you use a regular table?
    Look up [Global Temporary|http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_7002.htm#sthref7247] in the diocumentation, including the SQL*Language manual, for an alternative.
    "Temporary" applies only to the data. A Global Temporary Table is created once, and stays until you DROP it, the same as any other table.
    The data in the table is temporary. If you create the table saying "ON COMMIT PRESERVE ROWS" (which sounds appropriate, based on your description) the the data will automatically be deleted when you end the database session.
    All data in Global Temporary Tables is session-specific. If two (or more) people are using the same table at the same time, each will only see the data they inserted themselves; they will never see rows inserted by the other session.
    Almost anything you can do with a regular table you can do with a Global Temporary Table. In particular, DML (such as MERGE) and cursors work exactly as they do on other tables.

Maybe you are looking for

  • Issues in CRM Quality

    Hi, We transported all our activated datasources to CRM Quality. Replicated the Data sources to BI Quality system and then transported the BI objects to BI Quality. All the objects are in active state in Quality systems. But when I am trying to check

  • New tabs are not blank they are displaying msn games tab, how to I get rid of this please

    I was on msn games today for my godson and I had to install one of the free games he wanted to play, I chose the option to not have msn games as my new tabs but now every time I open a new tab instead of it being blank it displays msn games in the ba

  • I want to see the composer

    How do you get the iPod nano 5th Gento show the composer whilst music is playing? I dont know the composer to be able to go in through the menu option but would like to be able to see it whilst I listen to a tune as I listen to a lot of classical mus

  • System.out and System.err  How to get to show up in log

    Does anyone know if there is anyway to get System.out and System.err messages to appear in the log? Trying to build and debug a JSP project is a complete nightmare when the remote developers cannot see System.out or System.err messages from helper cl

  • Workflow for Attendance IT2001

    My requirement .... I need a BOR object which triggers when employee submits is attendance using info-type 2001. Approval needs to be sent to his manager and manger should be given options to edit the attendance sheet if required. Event is not a prob