Create a View from tables of different schemas

hi all,
can u pls give solution to create a View from tables of different schemas.
i have to bring data from one DB Server A,
which contains different schemas and tables in the schemas...
i need to insert that data in another DBServer B.
i made a procedure for this...
but when the connection fails from A, then i could not get data...
please suggest some solution..
thanks,
neelima

I don't know what database system you use, but in the most I know it is done that way:
SELECT
A.COL1,A.COL2.....
FROM
SCHEMA_NAME.TABLENAME A,
SCHEMA_NAME.TABLE_NAME B
WHERE
A.COL1 = B.COL2
...

Similar Messages

  • Materialized view with tables in different schemas

    Hello,
    I want to create a materialized view with a table from a different schema in the SELECT statement. For materialized view I would like to apply the "REFRESH COMPLETE ON COMMIT" option.
    Here the code:
    CREATE MATERIALIZED VIEW S1.MV_EXAMPLE
    TABLESPACE TS1
    PCTFREE 0
    BUILD IMMEDIATE
    REFRESH COMPLETE ON COMMIT
    AS
    SELECT T.COLUMN1 COLUMN
    FROM S2.TABLE1 T
    I can't execute this SQL because I get an "insufficient privileges" error to this table:
    FROM S2.TABLE1 T
    FEHLER in Zeile 9:
    ORA-01031: Insufficient privileges
    User S1 has the following privileges:
    CREATE SESSION
    CREATE SNAPSHOT
    CREATE TABLE
    CREATE QUERY REWRITE
    SELECT ANY TABLE
    User S2 has the following privileges:
    CREATE SESSION
    CREATE SNAPSHOT
    CREATE TABLE
    CREATE QUERY REWRITE
    ALTER ANY SNAPSHOT
    Which privileges are missing?
    Thanks, Mathias

    Thanks Kamal for your answer!
    S1 has the grant select directly. But I solveld the problem. The system privilege "ON COMMIT REFRESH" was missing for S1. This has to be set if any of the tables are outside the owner's schema of the materialized view (ORACLE documentation - Data Warehouse Guide).
    But one thing is not clear to me yet and the ORACLE documentation doesn't give me an answer. I can set the refresh-attribute ON COMMIT on a materialized view containing only joins when a group by clause is set. If the group by clause is missing I can't! Why?
    Regards, Mathias

  • How to create a view on tables with different keys?

    I have to create a View on:
    Z3PVR: Transparent Table
    BSEG: Cluster Table
    CKIS: Transparent Table
    BKPF: Transparent Table
    RV61A: Structure
    T001: Transparent Table
    All the tables have different "Key Fields" and the structure has no "Key Fields". When i create the view, what do I mention in the "JOIN FIELDS" tab. and how do i create the view with the structure?
    Please advise.

    How to create a view on a Non-Transparent Tables.
    how to create view?
    HELP.. How to create a view with the tables with ALV

  • HOW CAN I CREATE A VIEW FROM SAME TABLE WHERE I NEED COLUMNS DETAILS FROM DIFFERENT ROWS IN THE SAME TABLE

    i have a table1 on the top, but i want to create a view from table 1 as  view mentioned beneath the table 2. Could any of you please help me.
    table1
    ID
    office
    employee
    activity
    1
    246
    -9999
    698
    2
    ##-99
    21480
    698
    3
    104
    -9999
    7025
    4
    ##-99
    88908
    7025
    5
    108
    -9999
    2415
    6
    ##-99
    17135
    2415
    7
    246
    -9999
    698
    8
    ##-99
    21480
    698
    9
    104
    -9999
    7025
    10
    ##-99
    88908
    7025
    11
    108
    -9999
    2415
    12
    ##-99
    17135
    2415
    view
    ID
    office
    ID1
    employee
    activity
    1
    246
    2
    21480
    698
    3
    104
    4
    88908
    7025
    5
    108
    6
    17135
    2415
    7
    246
    8
    21480
    698
    9
    104
    10
    88908
    7025
    11
    108
    12
    17135
    2415

    declare @forumsTable table (ID int, officeID int, employeeID INT, activityID int)
    insert into @forumsTable (ID, officeID, employeeID, activityID)
    values
    (1 ,246, -9999, 698 ),
    (2 ,-99, 21480, 698 ),
    (3 ,104, -9999, 7025),
    (4 ,-99, 88908, 7025),
    (5 ,108, -9999, 2415),
    (6 ,-99, 17135, 2415),
    (7 ,246, -9999, 698 ),
    (8 ,-99, 21480, 698 ),
    (9 ,104, -9999, 7025),
    (10 ,-99, 88908, 7025),
    (11 ,108, -9999, 2415),
    (12 ,-99, 17135, 2415)
    select f1.ID, f1.officeID, f2.ID as ID1, f1.employeeID, f1.activityID
    from @forumsTable f1
    inner join @forumsTable f2
    on f1.activityID = f2.activityID
    and f1.officeID > 0
    and f2.employeeID > 0
    and f1.id - f2.id = -1
    You really need to improve the relationship here.
    Perhaps you could make office and activity an exclusive pair.

  • Is it possible to create a view where table in the From clause changes name

    is it possible to create a view from a from a table like this
    create view my_view as select id, col1, col2, result from <<my_latest_cacahe_table>>;
    the table in the from clause changes the name .
    I have another table which indicates the the latest name of my cache tables. Always there are two records there. The latest one and previous one.
    select * from cache_table_def
    table_name cache_table_name refresh_date
    my_table cache_table245 1/23/2012
    my_table cache_table235 1/22/2012
    create table cache_table_def (table_name varchar2(25), cache_table_name varchar2(25), refresh_date date);
    insert into cache_table_def values( 'my_table','cache_table245','23-jan-2012');
    insert into cache_table_def values ( 'my_table','cache_table546','22-jan-2012');
    create table cache_table245 (id number, col1 varchar2(50), col2 varchar2(20), result number);
    insert into cache_table245 values(1, 'test123', 'test345',12.12);
    insert into cache_table245 values (2, 'test223', 'test245',112.12);
    create table cache_table235 (id number, col1 varchar2(50), col2 varchar2(20), result number);
    insert into cache_table235 values (1, 'test123', 'test345',92.12);
    insert into cache_table235 values (2, 'test223', 'test245',222.12);
    what I need to do is find the latest cache_table name for my_table and use that in my view defintion
    When user select from the the view it always reurns the data from the latest cache_table
    is it possible to do something like this in oracle 11g?
    I have no control on the cache tables names. that is why I need to use the latest name from the table.
    Any ideas really appreciated.

    I've worked up an example that does what you ask. It uses the SCOTT schema EMP table. Make two copies of the EMP table, EMP1 and EMP2. I deleted dept 20 from emp1 and deleted dept 30 from emp2 so I could see that the result set really came from a different table.
    -- create a context to hold an environment variable - this will be the table name we want the view to query from
    create or replace context VIEW_CTX using SET_VIEW_FLAG;
    -- create the procedure specified for the context
    - we will pass in the name of the table to query from
    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;
    -- these are the three queries - one for each table - none of them will return data until you set the context variable.
    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' )
    -- this is how you set the context variable depending on the table you want the view to query
    exec set_view_flag( p_table_name => 'EMP' );
    exec set_view_flag( p_table_name => 'EMP1' );
    exec set_view_flag( p_table_name => 'EMP2');
    -- this will show you the current value of the context variable
    SELECT sys_context( 'VIEW_CTX', 'TABLE_NAME' ) FROM DUAL
    -- this is the view definition - it does a UNION ALL of the three queries but only one will actually return data
    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' )
    -- first time - no data since context variable hasn't been set yet
    SELECT * FROM THREE_TABLE_EMP_VIEW
    -- get data from the EMP table
    exec set_view_flag( p_table_name => 'EMP' );
    SELECT * FROM THREE_TABLE_EMP_VIEW
    -- get data from the EMP2 table
    exec set_view_flag( p_table_name => 'EMP2');
    SELECT * FROM THREE_TABLE_EMP_VIEW
    For your use case you just have to call the context procedure whenever you want to switch tables. You can union all as many queries as you want and can even put WHERE clause conditions based on other filtering criteria if you want. I have used this approach with report views so that one view can be used to roll up report data different ways or for different regions, report periods (weekly, quarterly, etc). I usually use this in a stored procedure that returns a REF CURSOR to the client. The client requests a weekly report and provides a date, the procedure calculates the START/END date based on the one date provided and sets context variables that the view uses in the WHERE clause for filtering.
    For reporting it works great!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Create a view from 10 tables

    Hi Experts,
    I want to create a view from 10 pricing tables rather than write 10 different select query in my application. Most of the columns of the pricing tables are same. I want all the data from these tables into the respective columns. Further I want an indicator as to which table does this record belong to. How can I achieve this?
    Ex:
    Table 1 columns: kappl kschl vkorg vtweg vkgrp
    Table 2 columns: kappl kschl vkorg vtweg matkl matnr
    if each table has two records, I want 4 records in my view in the respective columns along with the indicator that this record belongs to a specific column.
    Regards

    Hi,
    Placing 10 tables in one view will drastically affect performance. This is highly unrecommended.
    Anyhow if you insist on doing so you can create [database view|http://help.sap.com/saphelp_nw04/helpdata/en/36/74c0358373003ee10000009b38f839/frameset.htm] or use explicitly joins in your program.
    Keep in mind that althought it is possible to use projection (only selection of choosen column) it is not logically appropriate to locate which table this column belongs to (as far as we are talking about key fields) as both have the same field as key field.
    On the other hand when using projection for non-key columns it is you who define what is to be selected and how, therefore you know which column belongs to which table.
    i.e
    data: begin of st,
              lgart type t512w-lgart,
              molga type t512w-molga,
              lgtxt   type t512t-lgtxt,
            end of st.
    select w~molga w~lgart t~lgtxt   "<- here using aliases you know which column is taken from which table
      into st
      from T512W as W
      inner join T512T as T on
         W~LGART = T~LGART.
      write: / st-lgart, st-molga, st-lgtxt.
    endselect.
    In this example lgart (key field) can be taken from either t512w or t512t, but fields mogla and lgtxt are taken from t512w and t512t respectively.
    All in all this is correct as far as up to 3-4 tables are concerned. But 10 will be a disaster...
    Hope this helps you
    Marcin

  • Package Error!  join to tables in different schemas

    Hi
    I get an error whwn I want to put my query into package
    I have two tables in different schemas and I joined them and it works when I compile it
    but in the SP it doesn't works
    Is anbody help me? please
    Table1 in Schema1
    Table2 in Schema2
    TableID is the column which I join two tables (Table1.TableID=Table2.TableID)
    User1 has Select grant to both tables (it works when I run the query but in the sp which is in the package it doesn't work)
    Package1 in Schema1

    query is working
    but when I put that query in to package, Package is giving error like "table or view does not exist"
    Table1 in Schema1
    Table2 in Schema2
    TableID is the column which I join two tables (Table1.TableID=Table2.TableID)
    User1 has Select grant to both tables (it works when I run the query but in the sp which is in the package it doesn't work)
    Package1 in Schema1
    Select * from Schema1.Table1
    Inner join Schema2.Table2 on Table1.TableID=Table2.TableID
    is working in editor but
    CREATE OR REPLACE PACKAGE Schema1.PCKG_packagename AS
    PROCEDURE SP_procedurename
    Select * from Schema1.Table1
    Inner join Schema2.Table2 on Table1.TableID=Table2.TableID;
    END SP_procedurename;
    END PCKG_packagename ;
    is not working
    Must I give grant to Package?
    Edited by: 874779 on 25.Tem.2011 03:37
    Edited by: 874779 on 25.Tem.2011 03:51

  • Privilege to allow a user to create a view in another user's schema

    Hello,
    I need to allow a user to create a view in another user's schema.
    Say, to connect as USER_A and run statement: 'create view USER_B_SCHEMA.myview as select...'
    Is there any way to accomplish that without granting USER_A privilege to CREATE ANY VIEW? I want to keep USER_A at the lowest profile possible.
    Thanks!

    You have the option to create an stored procedure, here a test case (no optimized, no bug free):
    SYS@orcl > create user sp_owner identified by sp_owner;
    SYS@orcl > grant create any view to sp_owner;
    SYS@orcl> create procedure sp_owner.create_view (
      2  view_name varchar2, view_sql varchar2 ) is
      3  begin
      4    execute immediate 'create view '||view_name||' as '||view_sql;
      5  end;
      6  /
    Procedure created.
    SYS@orcl > create user test identified by test;
    SYS@orcl > grant create session to test;
    SYS@orcl > grant execute on sp_owner.create_view to test;
    TEST@orcl> execute sp_owner.create_view('scott.emp_vw','select * from scott.emp')
    PL/SQL procedure successfully completed.HTH
    Enrique
    PS. If your problem was solved, consider marking the question as answered.

  • Performance with having tables in different schema's

    Hi all,
    We have a requirement to segregate tables into different schema's based on the sources. But everything is going to be on the same instance and database.
    Is there a performance hit (querying between tables) by having tables in different schema as apposed to having them in the same schema?
    Thanks
    Narasimha

    Most likely there is bit of performance impact if your application refers the tables from different schemas. You need to use database link to access the other schemas. Even you schemas may in instance but when you use database link the network also comes into picture. even queries on same instance will routed through network connect and get the data. Distributed transaction also have issues some time. So as far as possible the distribution of objects should be avoided into diffrent schemas.

  • Privilege for creating a View from a Stored Procedure

    Hi,
                         I need to create a view from a procedure. I could do it from an anonymous block whereas I am unable to do that from a Stored Procedure. Should I need a specific privilege for performing this operation? If so what would be the reason behind it? Will that privilege be given in production databases?
    Code to replicate:
    CREATE TABLE t11 AS SELECT * FROM DUAL;
    CREATE OR REPLACE PROCEDURE p_etl_test_view
    AS
    BEGIN
       EXECUTE IMMEDIATE 'CREATE OR REPLACE VIEW v_t11 AS SELECT * FROM t11';
    END;
    PROCEDURE P_ETL_TEST_VIEW compiled
    Elapsed: 00:00:00.131
    BEGIN
       EXECUTE IMMEDIATE 'CREATE OR REPLACE VIEW v_t11 AS SELECT * FROM t11';
    END;
    anonymous block completed
    Elapsed: 00:00:00.069
    BEGIN
       p_etl_test_view;
    END;
    Error starting at line 13 in command:
    BEGIN
       p_etl_test_view;
    END;
    Error report:
    ORA-01031: insufficient privileges
    ORA-06512: at "OCCSS_ENTMT_HK_DEV_01.P_ETL_TEST_VIEW", line 4
    ORA-06512: at line 2
    01031. 00000 -  "insufficient privileges"
    *Cause:    An attempt was made to change the current username or password
               without the appropriate privilege. This error also occurs if
               attempting to install a database without the necessary operating
               system privileges.
               When Trusted Oracle is configure in DBMS MAC, this error may occur
               if the user was granted the necessary privilege at a higher label
               than the current login.
    *Action:   Ask the database administrator to perform the operation or grant
               the required privileges.
               For Trusted Oracle users getting this error although granted the
               the appropriate privilege at a higher label, ask the database
               administrator to regrant the privilege at the appropriate label.
    Elapsed: 00:00:00.100
    The privileges I am having:
    SELECT   *
        FROM dba_sys_privs
       WHERE grantee = 'OCCSS_ENTMT_HK_DEV_01'
          OR grantee IN (SELECT granted_role
                           FROM dba_role_privs
                          where grantee = 'OCCSS_ENTMT_HK_DEV_01')
    ORDER BY 1;
    GRANTEE
    PRIVILEGE
    ADMIN_OPTION
    EXP_FULL_DATABASE
    ADMINISTER RESOURCE MANAGER
    NO
    EXP_FULL_DATABASE
    ADMINISTER SQL MANAGEMENT OBJECT
    NO
    EXP_FULL_DATABASE
    BACKUP ANY TABLE
    NO
    EXP_FULL_DATABASE
    CREATE SESSION
    NO
    EXP_FULL_DATABASE
    CREATE TABLE
    NO
    EXP_FULL_DATABASE
    EXECUTE ANY PROCEDURE
    NO
    EXP_FULL_DATABASE
    EXECUTE ANY TYPE
    NO
    EXP_FULL_DATABASE
    READ ANY FILE GROUP
    NO
    EXP_FULL_DATABASE
    RESUMABLE
    NO
    EXP_FULL_DATABASE
    SELECT ANY SEQUENCE
    NO
    EXP_FULL_DATABASE
    SELECT ANY TABLE
    NO
    OCCSS_ENTMT_HK_DEV_01
    CREATE DATABASE LINK
    NO
    OCCSS_ENTMT_HK_DEV_01
    CREATE TABLE
    NO
    OCCSS_ENTMT_HK_DEV_01
    DEBUG CONNECT SESSION
    NO
    OCCSS_ENTMT_HK_DEV_01
    SELECT ANY DICTIONARY
    NO
    SCB_SCHEMA_ROLE
    ALTER SESSION
    NO
    SCB_SCHEMA_ROLE
    CREATE CLUSTER
    NO
    SCB_SCHEMA_ROLE
    CREATE DIMENSION
    NO
    SCB_SCHEMA_ROLE
    CREATE INDEXTYPE
    NO
    SCB_SCHEMA_ROLE
    CREATE JOB
    NO
    SCB_SCHEMA_ROLE
    CREATE MATERIALIZED VIEW
    NO
    SCB_SCHEMA_ROLE
    CREATE OPERATOR
    NO
    SCB_SCHEMA_ROLE
    CREATE PROCEDURE
    NO
    SCB_SCHEMA_ROLE
    CREATE SEQUENCE
    NO
    SCB_SCHEMA_ROLE
    CREATE SESSION
    NO
    SCB_SCHEMA_ROLE
    CREATE SYNONYM
    NO
    SCB_SCHEMA_ROLE
    CREATE TABLE
    NO
    SCB_SCHEMA_ROLE
    CREATE TRIGGER
    NO
    SCB_SCHEMA_ROLE
    CREATE TYPE
    NO
    SCB_SCHEMA_ROLE
    CREATE VIEW
    NO

    BoopathyVasagam wrote:
    Thank you for your answer. So should I issue the below statement? (Since I dont have dba privs i couldn't test this)
    GRANT CREATE VIEW to P_ETL_TEST_VIEW;
    I doubt that above will prevent the error from being thrown.
    prior to running anonymous block again; just do as below
    SET ROLE NONE;
    doing so should result in same error being thrown when invoking
    BEGIN 
       p_etl_test_view; 
    END; 

  • Query on Creating and Populating I$ table on different condition

    Hi,
    I have a query on creating and populating I$ table on different condition.In which condition the I$ table is created??And These condition are mentioned below:
    1)*source and staging area* are on same server(i.e target is on another server)
    2)*staging area and Target* are on same server(i.e source is on another server)
    3)*source,staging area and Target* are on *3 different* server
    4)source,staging area and Target are on same server
    Thanks

    I am not very much clear about your question. Still trying my best to clear it out.
    In your all above requirement I$ table will be created.
    If staging same as target ( One database,one user) then all temp tables will be created under this user
    If staging is different than target ( One database,two user (A,B)) then all temp tables will be created under this user A (lets consider) and data will be inserted to the target table that is present in user B
    If staging is different than target ( Two database,two user (A1,A2), not recommended architecture) then all temp tables will be created under this user A1 (database A1) and data will be inserted to the target table that is present in user A2 (database A2)
    If source,staging,target will under one database then No LKM is required,IKM is sufficient to load the data into target. Specifically for this you can see one example given by Craig.
    http://s3.amazonaws.com/Ora/ODI-Simple_SELECT_and_INSERT-interface.swf
    Thanks.

  • Can a procedure select data from tables on other schemas?

    Can a procedure select data from tables on other schemas?
    If it is posible, which syntax should I use to identify the tables and schemas on the SELECT query?

    Yes , it is possible..unless the current user has the right privileges on others' db objects schema.
    Now , as regards the syntax....
    1) The more descriptive way is to use the format ... <owner_schema>.<obj_name>.
    2) If you have declared public synonyms of other schema's objects then you can refer to them as just <obj.name>.... but the <owner_schema>.<obj_name> is not wrong.
    3) If the db objects reside on another database you must have declared a db link.... then the syntax is <owner_schema>.<obj_name>@<db_link_name>.
    Regards,
    Simon

  • How to create a view consisting of data from tables in2 different databases

    Using Oracle 10.2g
    I have 2 databases Gus and haggis on Comqdhb schema.
    glink indicates a databse link between Haggis and Gus
    In Gus there are tables student,subject,grade,school containing columns like upn...
    STUDENT
    upn
    academicYear
    SUBJECT
    subject
    GRADE
    examlevel
    grade
    SCHOOL
    sn
    In HAGGIS there are tables student,grade,teacher containing columns upn...desc below.
    STUDENT
    upn
    GRADE
    grade
    upn
    academicyear
    level
    Create view in your HAGGIS database which will join all of the exam grades together. You should have one view which will produce the following relation :
    examGrade(upn, subject, examlevel, sn, grade,academicYear)
    so I need to create a view which gets the data from both the tables in both the databases.
    create view as examGrade(upn, subject, examlevel, sn, grade,academicYear) as select s.upn
    But i am not getting how to select a column from 2 tables in different databases
    I mean if i said
    select upn from comqdhb.student@glink,comqdhb.student;
    select upn from comqdhb.student@glink,comqdhb.student
    ERROR at line 1:
    ORA-00918: column ambiguously defined
    help me out,Thank you.

    Thank you for the reply will follow up the code format
    Create views in your HAGGIS schema database which will join all of the exam grades together. You should have one view which will produce the following relation :
    examGrade(upn, subject, examlevel, sn, grade,academicYear)
    I understand that there wont be duplication when we use conditions
    If i query
    select count(upn)
    from   comqdhb.student@glink I get 9000
    but after the union
    create view examGrade(upn, subject, examlevel, sn, grade,academicYear)
    as
    select distinct s.upn as upn
    ,                  g.subject as subject
    ,                  g."LEVEL" as examlevel
    ,                  g.grade as grades
    ,                  '9364097'
    ,                  to_number(g.academicyear) as academicyear
    from             comqdhb.student s
    ,                   comqdhb.grade g
    where           s.upn=g.upn
    union
    select            s.upn
    ,                   sb.subject
    ,                   g.elevel
    ,                   g.grade
    ,                   s.acyr
    ,                   sc.sn
    from              comqdhb.subject@glink sb
    ,                   comqdhb.student@glink s
    ,                    comqdhb.gradevalues@glink g
    ,                    comqdhb.school@glink sc,
    ,                    comqdhb.studentingroup@glink sg
    ,                    comqdhb.teachinggroup@glink tg
    where            sb.sid=tg.sid
    and                tg.gid=sg.gid
    and                sg.upn=s.upn
    and                g."LEVEL"=tg.elevel
    and                s.school=sc.id
    and                sc.id=tg.id; returns
    count(upn) from exam gradeIt gets stuck actually sometimes it returns
    932002 some results.
    2:
    Another problem i am having which i am trying to solve and written up my ideas but haven't been getting the expected results.Hope you can help.Thank you.
    Information:
    =======
    All children take exams at the age of 16 called a General Certificate of SecondaryEducation (GCSE).
    They have to study and take exams in Mathematics, English and Science, and can take other subjects such as History, French, Art etc. Most students will study between 5 and 10 different subjects before taking their GCSEs.
    For each exam, a student is awarded a grade from A*, A, B,C,D,E,F,G,U,X An A* grade is the best grade achievable and an X is the worst grade.
    In order to analyze how students have performed, each grade is mapped to a numeric value as follows:
    Grade Numerical score
    A* 8
    A 7
    B 6
    C 5
    D 4
    E 3
    F 2
    G 1
    U 0
    X 0
    Now why i need this avgGCSE is because i have to create a view containing avgGCSE of the students it is used in the next question where a condition is avgGCSE is between 6.5 and 7
    In order to calculate the avgGCSE the idea is to calculate the grades of the students and map the grades to their corresponding scores/values
    add them all up and div by the total no of grades to get the avg.
    desc comqdhb.STUDENT@glink;
    STUDENT
    =======
    UPN
    FNAME
    CNAME
    DOB
    GENDER
    PREVIOUSSCHOOL
    XGCSE
    SCHOOL
    ACYR
    STUDENTINGROUP
    =============
    UPN
    GID
    STARTDATE
    ENDDATE
    GRADE
    GRADEVALUES
    ===========
    GRADE
    LEVEL
    VALUE
    I have a opinion that xgcse in STUDENT table refers to the avgGCSE which i want to calculate as when i asked my professor as to what xgcse he said that he forgot to take it out of the table and it is not necessary while creating avggcse.
    select *
    from comqdhb.student@glink
    where xgcse<6.5; Displaying a result
    returns:
    UPN FAMILYNAME COMMONNAME DATEOFBIR GENDER PREVIOUSSCHOOL XGCSE SCHOOL ACYR
    ===========================================================================
    1011 KIMBERLY ABBOT 07-JUL-79 f none 3.93500948 2 2
    select *
    from comqdhb.student@glink
    where xgcse between 6.5 and 7 and upn = 1386; Displaying a result
    returns:
    UPN FAMILYNAME COMMONNAME DATEOFBIR GENDER PREVIOUSSCHOOL XGCSE SCHOOL ACYR
    ===========================================================================
    1386 STEPHANIE AANNESSON 15-JAN-79 f none 6.88873 2 2 so if xgcse is the avgGCSE then upn 1011 has avggcse<6.5 and 1386 has avggcse >6.5
    my idea was backward strategy like so now if we find out upn 1368 has suppose xgcse(avggcse)>6.5 how to extract the avggcse for the particular upn We need to map grades from GRADEVALUES to grade in STUDENTINGROUP and map upn from studentingroup to upn in student to output the values for the corresponding grades from GRADEVALUES
    select grade
    from comqdhb.studentingroup@glink
    where upn = 1011;
    Result:
    GRADE
    =====
    D
    F
    B
    E
    C
    E
    E
    B
    8 rows selected. Mapping each grade to the corresponding value and calculating we get
    32/8=4 total(values to corresponding grades)/no of grades.
    But the xgcse for upn 1011 is 3.935 and i am getting 4!! maybe xgcse isn't avggrade but ? is the procedure by me correct for calculating avggcse
    select grade
    from comqdhb.studentingroup@glink
    where upn = 1386;
    Result:
    GRADE
    ======
    A*
    A*
    A*
    A*
    B
    A*
    A*
    A
    B
    B
    B
    11 rows selected. grade to the corresponding value and calculating we get
    79/11=7.12 total(values to corresponding grades)/no of grades.
    But the xgcse for upn 1011 is 6.88... and i am getting 7.12!!
    But another problem
    when i say
    select   g.value,g.grade
    from     comqdhb.gradevalues@glink g
    ,        comqdhb.studentingroup@glink sg
    where    g.grade=sg.grade
    and      sg.upn=1011;
    result:
    ======
    VALUE GRADE
    ===========
      100 B
      100 B
       80 C
       60 D
       40 E
       40 E
       40 E
       20 F
        6 B
        6 B
        5 C
    VALUE GRADE
    =============
        4 D
        3 E
        3 E
        3 E
        2 F
    16 rows selected.
    select   distinct g.value,g.grade
    from     comqdhb.gradevalues@glink g
    ,        comqdhb.studentingroup@glink sg
    where    g.grade=sg.grade
    and      sg.upn=1011;
    result:
    ======
    VALUE GRADE
    ============
         2 F
       100 B
         6 B
         3 E
        60 D
         5 C
         4 D
        80 C
        40 E
        20 F
    10 rows selected. I am getting only 8 for the query
    select grade
    from comqdhb.studentingroup@glink
    where upn = 1386; here its becomming 10 and also its displaying values as 100 and ...
    select distinct *
    from   comqdhb.gradevalues@glink;
    GRADEVALUES
    ===========
    LEVEL      GRADE           VALUE
    ================================
    a          A                 120
    a          B                 100
    a          C                  80
    a          D                  60
    a          E                  40
    a          F                  20
    a          U                   0
    a          X                   0
    g          A                   7
    g          A*                  8
    g          B                   6
    LEVEL      GRADE           VALUE
    ================================
    g          C                   5
    g          D                   4
    g          E                   3
    g          F                   2
    g          G                   1
    g          U                   0
    g          X                   0
    18 rows selected. I was hoping if i could map the grades and get the values and calculate avggrade by total(values)/count(values)that would be it but here there are values like 100...
    select  sum(g.value)/count(g.grade) as avggrade
    from    comqdhb.gradevalues@glink g
    ,         comqdhb.studentingroup@glink sg
    where  g.grade=sg.grade
    and     sg.upn=1386;
    avggrade
    ========
    37.4375 the avggrade cant be this big and when i map each grade i obtained for 1368 like a to 7+b to 6 so on i get avggrade 7.12
    kindly help.
    Edited by: Trooper on Dec 15, 2008 4:49 AM

  • Create a view from multiple tables

    Hi all,
    I am a newbie, so sorry if this is a "basic" question.
    I had 3 tables TAB1, TAB2 and TAB3
    TAB1 has
    STU_ID(pk), NAME, GRADE, ADDRESS
    TAB2 has
    COURSE_ID(pk), STU_ID(fk), COURSE_NAME, ROOM_NUM, TIME, DAY
    TAB3 has
    MENTOR_NAME, TITLE, AVAILABLE_DAYS
    Now I want to create a view(or query) that returns STU_ID, COURSE_NAME, NAME, GRADE, MENTOR_NAME and TITLE.
    When I tried writing a query like
    SELECT a.STU_ID, b.COURSE_NAME, a.NAME, a.GRADE, c.MENTOR_NAME, a.TITLE
    FROM TAB1 a, TAB2 b, TAB3 c
    WHERE a.STU_ID=b.STU_ID
    I am getting multiple results..like I'm getting Mentor name 4 times, name 4 times like that.
    So can anybody help me in writing the query for this....a "VIEW" would be appreciated.
    Thanks In Advance
    Srra

    You query should return all the columns in the select list once for each and every row that meets the specified join condition, how does this differ from what you are getting?
    So if tableA is the student table with only one row per student you would expect to see the student data duplicated once for every matching course row found in tableB, and so on when tableC is added in.
    If you need help please post partial results and then explain what results you want.
    HTH -- Mark D Powell --
    PS as sb mention you forgot your join condition to tableC which would multiply tableC by the other tables.
    Edited by: Mark D Powell on Feb 3, 2010 9:18 AM

  • How to create XMLTYPE View from the XMLType table

    Hi:
    I have a large XML file and inserted to the XMLTYPE table
    For the XQUERY purpose I would like to create XMLView of the table.
    The examples I got from Oracle to create XML view are for small files.
    Can some one help me how to create XMLType VIEW for large XML Files ( 20,000 lines )?
    Ali_2

    Have a look at the examples given on XMLType Views (based on relational tables) or standard views (based on XMLType storage) in the FAQ url located on the main page of this forum site regarding XMLDB.

Maybe you are looking for

  • Facebook notifications in email on handheld PROBLEM

    Hi all, Been searching here and cannot find the answer...I apologize if I missed something, but been going back and forth through the forums and online... Updated the Facebook app to latest version (1.8....) when I updated other apps/OS on my phone (

  • Projecting still images using final cut express

    Maybe someone can answer this tricky question. We need to project a FCE movie that has photoshop still images imported into it, but these photoshop images (which appear normal on the computer screen), are distorted in the projection. They look squash

  • Problem displaying output

    Hi, Below is my JSP code fragment: <% StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(new BufferedWriter(sw)); XMLDocument doc = domparser.getDocument("/html/jsp/SubMarket.xml"); InputStream styleSource = getClass().getResource

  • Albums cover size

    Hi, I downloaded itunes 11.0 for Windows 7. In Album mode, the covers are huge.  I don't see any way to make them smaller so more appear in each line. Any one know how I can fix this issue? Thanks, idavycrockett

  • Query Filter Pane

    Post Author: rbirney CA Forum: General I am trying to create a custom query filter for my Crystal Report.  I however can't find the Query Panel that it keeps referring to.  I look at the instructions in the manual but it says to open a Universe and i