Create a view that limits a large table, but also allows an outer join ?

oracle 10.2.0.4
CREATE TABLE MY_PAY_ITEMS
( EMP     VARCHAR2(8) NOT NULL
, PAY_PRD VARCHAR2(8) NOT NULL
, KEY1    VARCHAR2(8) NOT NULL
, KEY2    VARCHAR2(8) NOT NULL
, LN_ITEM VARCHAR2(4) NOT NULL
, ITEM_AMT NUMBER(24,2) NOT NULL
, FILLER  VARCHAR2(100) NOT NULL)
INSERT INTO MY_PAY_ITEMS
SELECT A.EMP
, B.PAY_PRD
, C.KEY1
, D.KEY2
, E.LN_ITEM 
, F.ITEM_AMT
FROM (SELECT TO_CHAR(ROWNUM, '00000000') "EMP" FROM DUAL  CONNECT BY LEVEL <= 50 ) A
, (SELECT '2010-' || TO_CHAR(ROWNUM,'00') "PAY_PRD" FROM DUAL CONNECT BY LEVEL <= 52) B
, (SELECT TO_CHAR(ROWNUM, '000') "KEY1" FROM DUAL CONNECT BY LEVEL <= 8) C
, (SELECT TO_CHAR(ROWNUM, '000') "KEY2" FROM DUAL CONNECT BY LEVEL <= 5) D
, (SELECT TO_CHAR(ROWNUM,'000') "LN_ITEM" FROM DUAL CONNECT BY LEVEL <= 20) E
, (select round(DBMS_RANDOM.VALUE * 400,2)  "ITEM_AMT" from dual) F
CREATE UNIQUE INDEX MY_PAY_ITEMS ON MY_PAY_ITEMS (EMP, PAY_PRD, KEY1, KEY2, LN_ITEM)
CREATE TABLE MY_ITEM_DISPLAY
( DISPLAY_CODE VARCHAR2(4) NOT NULL
, SEQUENCE     NUMBER(2) NOT NULL
, COLUMN_ITEM1 VARCHAR2(4) not null
, COLUMN_ITEM2 VARCHAR2(4) not null
, COLUMN_ITEM3 VARCHAR2(4) not null
, COLUMN_ITEM4 VARCHAR2(4) not null)
INSERT INTO MY_ITEM_DISPLAY VALUES ('01',10,'001','003','004','005');
INSERT INTO MY_ITEM_DISPLAY VALUES ('01',20,'007','013','004','009');
INSERT INTO MY_ITEM_DISPLAY VALUES ('01',30,'001','004','009','011');
INSERT INTO MY_ITEM_DISPLAY VALUES ('01',40,'801','304','209','111');
INSERT INTO MY_ITEM_DISPLAY VALUES ('02',10,'001','003','004','005');
INSERT INTO MY_ITEM_DISPLAY VALUES ('02',20,'007','013','004','009');
INSERT INTO MY_ITEM_DISPLAY VALUES ('02',30,'001','004','009','011');
MY_PAY_ITEMS is a table that stores payslip line items.  It has a total size of 500,000,000 rows.
EMP is the unique employee id,  We have approx 200,000 employees (with approx 50,000 being active today).
PAY_PRD is a weekly pointer (2010-01, 2010-02 ... 2010-52), we have data from 2004 and are adding a new pay period every week.  2010-01 is defined as the first monday in 2010 to the first sunday in 2010 etc.
KEY1 is an internal key, it tracks the timeline within the pay period.
KEY2 is a child of KEY1, it tracks the sequence of events within KEY1.
LN_ITEM is the actual pay item that resulted from the event on average a person generates 20 rows per event.  Note that in this example everybody gets the same LN_ITEM values, but in practice it is 20 selected from 300
ITEM_AMT is the net pay for the line item.
FILLER is an assortment of fields that are irrelevant to this question, but do act as a drag on any row loads.
MY_ITEM_DISPLAY is a table that describes how certain screens should display items.  The screen itself is a 4 column grid, with the contents of the individual cells being defined as a lookup of LN_ITEMS to retrieve the relevant LN_AMT.
We have an application that receives a DISPLAY_CODE and an EMP.  It automatically creates a sql statement along the lines of
SELECT * FROM MY_VIEW WHERE DISPLAY_CODE = :1 AND EMP = :2
and renders the output for the user.
My challenge is that I need to rewrite MY_VIEW as follows:
1) Select the relevant rows from MY_ITEM_DISPLAY where DISPLAY_CODE = :1
2) Select the relevant all rows from MY_PAY_ITEMS that satisfy the criteria
   a) EMP = :2
   b) PAY_PRD = (most recent one for EMP as at sysdate, thus if they last got paid in 2010-04 , return 2010-04)
   c) KEY1 = (highest key1 within EMP and PAY_PRD)
   d) KEY2 = (highest key2 within EMP, PAY_PRD and KEY1)
3) I then need to cross reference these to create a tabular output
4) Finally I have to return a line of 0's where no LN_ITEMs exist ( DISPLAY_CODE 01, sequence 40 contains impossible values for this scenario)
The below query does part of it (but not the PAY_PRD, KEY1, KEy2 )
select * from (
SELECT A.DISPLAY_CODE
, B.EMP
, A.SEQUENCE
, MAX(DECODE(B.LN_ITEM, A.COLUMN_ITEM1, B.ITEM_AMT, 0)) "COL1"
, MAX(DECODE(B.LN_ITEM, A.COLUMN_ITEM2, B.ITEM_AMT, 0)) "COL2"
, MAX(DECODE(B.LN_ITEM, A.COLUMN_ITEM3, B.ITEM_AMT, 0)) "COL3"
, MAX(DECODE(B.LN_ITEM, A.COLUMN_ITEM4, B.ITEM_AMT, 0)) "COL4"
FROM MY_ITEM_DISPLAY A, MY_PAY_ITEMS B
WHERE B.PAY_PRD = '2010-03'
GROUP BY A.DISPLAY_CODE, B.EMP, A.SEQUENCE)
WHERE DISPLAY_CODE = '01'
AND EMP = '0000011'
ORDER BY SEQUENCE
My questions
1) How do I do the PAY_PRD, KEY1, KEY2 constraint, can I use some form of ROW_NUMBER() OVER function ?
2) How do I handle the fact that none of the 4 column LN_ITEMS may exist  (see sequence 40, none of those line items can exist)...  Ideally the above SQL should return
01, 0000011, 10, <some number>, <some number>, <some number>, <some number>
01, 0000011, 20, <some number>, <some number>, <some number>, <some number>
01, 0000011, 30, <some number>, <some number>, <some number>, <some number>
01, 0000011, 40, 0            , 0            , 0            , 0           
I tried a UNION, but his prevented the view from eliminating the bulk of the MY_PAY_ITEMS rows, as it resolve ALL of MY_PAY_ITEMS instead of just retrieving rows for the one EMP passed to the view.  The same seems to be true for any outer joins.

Hi, if i understood you properly, you need :
select nvl(q.display_code,lag(q.display_code) over (order by rownum)) display_code,
       nvl(q.emp,lag(q.emp) over (order by rownum)) emp,
       m.s,
       nvl(q.COL1,0) COL1,
       nvl(q.COL2,0) COL2,      
       nvl(q.COL3,0) COL3,
       nvl(q.COL4,0) COL4,
       nvl(PAY_PRD,lag(q.PAY_PRD) over (order by rownum)) PAY_PRD,
       nvl(KEY1,lag(q.KEY1) over (order by rownum)) KEY1,
       nvl(KEY2,lag(q.KEY2) over (order by rownum)) KEY2  
from(
select d.display_code,
       t.emp,
       d.sequence,
       max(DECODE(t.LN_ITEM, d.COLUMN_ITEM1, t.ITEM_AMT, 0)) keep (dense_rank first order by to_date(t.pay_prd,'yyyy-mm') desc ) "COL1",
       max(DECODE(t.LN_ITEM, d.COLUMN_ITEM2, t.ITEM_AMT, 0)) keep (dense_rank first order by to_date(t.pay_prd,'yyyy-mm') desc ) "COL2",
       max(DECODE(t.LN_ITEM, d.COLUMN_ITEM3, t.ITEM_AMT, 0)) keep (dense_rank first order by to_date(t.pay_prd,'yyyy-mm') desc ) "COL3",
       max(DECODE(t.LN_ITEM, d.COLUMN_ITEM4, t.ITEM_AMT, 0)) keep (dense_rank first order by to_date(t.pay_prd,'yyyy-mm') desc ) "COL4",
       max(t.PAY_PRD) PAY_PRD,
       max(t.key1) keep (dense_rank first order by to_date(t.pay_prd,'yyyy-mm') desc ) key1,
       max(t.key2) keep (dense_rank first order by to_date(t.pay_prd,'yyyy-mm') desc ) key2
  from MY_PAY_ITEMS t
  join MY_ITEM_DISPLAY d
    on d.display_code = '01'
where t.emp = '00000011'
group by d.display_code, t.emp, d.sequence
) q
full outer join (select level*10 s from dual connect by level <= 4) m
on m.s = q.sequence
DISPLAY_CODE
EMP
S
COL1
COL2
COL3
COL4
PAY_PRD
KEY1
KEY2
01
00000011
10
101.1
103.1
104.1
105.1
2010-03
008
005
01
00000011
20
107.1
113.1
104.1
109.1
2010-03
008
005
01
00000011
30
101.1
104.1
109.1
111.1
2010-03
008
005
01
00000011
40
0
0
0
0
2010-03
008
005
Ramin Hashimzade

Similar Messages

  • Creating a datasource that sits on a table

    Hello All,
    I have to create a datasource that sits on a table and reads certain fields. I have found the relevant table via the data browser "RSPCLOGCHAIN". I am now in transaction sbiw - please advise further.
    Thank you and kind regards,
    Keith

    Hi Keith,
    The steps would be as follows:
    1. Goto to RSO2.
    2. Create a datasource with a technical name and assign it to a Application Component.
    3. Choose the Extraction from view section and enter you table name.
    4. Save it.
    5. It would list all the fields of that table. You can hide the ones that you do not want. Save again.
    Bye
    Dinesh

  • Can we define a view that refers to 50 tables?

    Hi,
    I've a problem at hand and I'm not sure what the right solution I can adopt.
    There is an application which hits the DB (v11.2) for accessing a single view 'XVIEW'. This view has a simple sql & join which is based on two tables XTABLE1 and XTABLE2.
    Now, the new version of the schema that has got released has split XTABLE2 into 50 different tables each having a same structure. To the fix the issue, there are two solutions I could think of:
    1. Create 50 views on top of 50 tables, and fix the Application to refer to these 50 new views; note: the application has hundreds of references and this has a significant work involved.
    2. Rewrite XVIEW to refer to 50 tables. This will avoid changing the application, however I'm not sure if this is feasible and will have a decent performance.
    I would like to go for solution 2 as it involves significantly less effort, but not sure how best i should define the view, single the 50 table structure is the same can I just union all of them?
    Thanks for the help.

    Hi,
    Hozy wrote:
    Frank, thanks for helping me out.
    What you are suggesting is that I should recreate the view XVIEW which does union all (as the rows will be unique) of the 50 tables, however performance will be an issue unless I can create a materialized views.
    What I know of materialized views is that it's used for static, pre-computed type of data. A materialized view is pre-computed; that's what makes it faster. The time and effort spent in doing the UNION is shifted from the time when you do the queries to the time when you refresh the materialized view. Whether that is more or less total time depends on how often you query the view, and how often you refresh it. At any rate, the performance when you do the queries will be as good as possible.
    Materialized views ar often used in data wharehouses, where then data may only change once a month, but they are also often used in situations like yours, where the data changes every day, or even more frequently.
    In my case, the data in few of the 50 tables might change once every 24hrs and it all comes at one time. The queries that hit XVIEW should get the latest data. Is there a way I can define a materialized view which will pick up the new data in the base 50 tables?I see; you have some job that runs at, say, 2:00 am every morning, and changes some, or maybe all, of the 50 tables. You might refresh the materialized view at, say, 4:00 am every day, or at some time when you're sure that the changes to the base tables are complete. Any query that uses the materialized view between 2:00 and 4:00 am will get stale data.
    You could, alternatively, make the materilaized view refresh whenever any of the base tables change, but this uses more resources, including your time and effort setting it up.

  • Create opaque view in OBIEE with multiple tables

    Hi,
    I need some help with the opaque view since i have never created it in past. I want to create an opaque view which fetches data from multiple tables. Is it possible to do that ? Or is there any other alternate option available in OBIEE ? I read the following blog and other similar blogs on opaque views but could not find option to use it for query with multiple tables:
    Oracle Business Intelligence: Creating Opaque View in Physical Layer in OBIEE 10g
    Also can you please advice how to join two tables from different databases in OBIEE ?
    Kindly advice.
    Regards,
    Andy

    Hi Andy,
    As per my knowledge you can create Opaque View on one table at a time.Joining two tables from different databases yes we can create a report from multiple data sources.Check this
    Rittman Mead Consulting &amp;raquo; Blog Archive &amp;raquo; Reporting Against Multiple Datasources in OBIEE
    Mark if helps.
    Thanks,

  • Problems creating a view that's a union of two other views

    Hello all you Oracle folks,
    I'm pretty new to this Oracle thing, coming over from SQL Server where life was simple. Here's my issue;
    I am trying to create a view that is a union of two other views.
    I can run the top SELECT of this view (before the UNION) and it works no problem, and I can run the bottom SELECT (after the UNION) and it also works with no problem. I can run a DESC on both views involved, and those also work without any problem.
    When I try to run the SQL all together though, I get this;
    SQL> CREATE materialized view trkmaster.cmp_pmr_union refresh force ON demand AS SELECT 'CMR'
    2 "Ticket_System", "Id_col" "Ticket", "Submitter", "Submit_Date", "Submit_To",
    3 "Actual_Activity_Start_Date" "Start_Date", "Actual_Activity_Start_Time" "Start_Time",
    4 "Actual_Activity_End_Date" "End_Date", "Actual_Activity_End_Time" "End_Time",
    5 "Close_Date", "Risk_Level" "Level", "Activity_Type" "Type", "Activity_Category"
    6 "Category", "Hardware_Name" "Hardware", "Platform", "Application_Name" "Application",
    7 "Completion_Status" "Status", "Area_CMPO" "Owner", "Outage_Minutes" "Total_Outage_Mins",
    8 "Acorde_Downtime__in_minutes_" "Acorde", "Atlas", "Corporate_Email_Downtime"
    9 "Corporate_Email", "Data_Warehouse_Downtime__In_M6" "Data_Warehouse",
    10 "E__Commerce_Downtime__In_Mins_" "ECommerce", "FMDS__FIVR_" "FMDS_FIVR",
    11 "FMDS_Hotels_Downtime" "FMDS_Hotels", "FMDS_Internet_Downtime" "FMDS_Internet",
    12 "FMDS_Resv__Ctr_Downtime" "FMDS_Resv_Ctr", "GDS_Downtime__In_Mins_" "GDS",
    13 "HI_Online_Downtime__In_Mins_" "HI_Online", "Holidex__CRO____In_Mins_" "Holidex_CRO",
    14 "Holidex__Hotels____In_Mins_" "Holidex_Hotels", "Hyperion_Essbase",
    15 "IHGMail_Downtime__In_Mins_" "IHG_Mail", "Kofax_Downtime__in_minutes_" "Kofax",
    16 "PeopleSoft_Fin_Downtime_In_Mi1" "Peoplesoft", "PERFORM__HIRO____In_Mins_" "Perform_HIRO"
    17 FROM CMP.CHRQVCHANGE_MANAGEMENT_REQUEST UNION SELECT 'PMR' "Ticket_System", "Id_col"
    18 "Ticket", "Submitter", "Submit_Date", "Submit_To", "Problem_Start_Date" "Start_Date",
    19 "Problem_Start_Time" "Start_Time", "Problem_End_Date" "End_Date", "Problem_End_Time"
    20 "End_Time", "Close_Date", "Severity_Level" "Level", "Problem_Type" "Type",
    21 "Occurrence_Type" "Category", "Hardware_Name" "Hardware", "Platform", "Application_Name"
    22 "Application", "Close_Code" "Status", "Problem_Owner" "Owner",
    23 "TOTAL_Outage_Time__If_Any_" "Total_Outage_Time", "Acorde_Downtime__in_minutes_" "Acorde",
    24 "Atlas", "Corporate_Email_Downtime" "Corporate_Email", "Data_Warehouse_Downtime__In_M6"
    25 "Data_Warehouse", "E__Commerce_Outage_Time__Mins_" "ECommerce", "FMDS__FIVR_" "FMDS_FIVR",
    26 "FMDS_Hotels_Outage_Time__In_M5" "FMDS_Hotels", "FMDS_Internet_Outage_Time__Mi4"
    27 "FMDS_Internet", "FMDS_Resv__Ctr_Outage_Time__M3" "FMDS_Resv_Ctr",
    28 "GDS_Outage_Time__Mins_" "GDS", "HI_Online_Outage_Time__In_Min2" "HI_Online",
    29 "Holidex__CRO____In_Mins_" "Holidex_CRO", "Holidex__Hotels____In_Mins_" "Holidex_Hotels",
    30 "Hyperion_Essbase", "IHG_Mail_Outage_Time__In_Mins_" "IHG_Mail",
    31 "Kofax_Downtime__in_minutes_" "Kofax", "PeopleSoft_Fin_Downtime_In_Mi1" "Peoplesoft",
    32 "PERFORM__HIRO____In_Mins_" "Perform_HIRO" FROM PMR.CHRQVPROBLEM_MANAGEMENT;
    "PERFORM__HIRO____In_Mins_" "Perform_HIRO" FROM PMR.CHRQVPROBLEM_MANAGEMENT
    ERROR at line 32:
    ORA-00942: table or view does not exist
    The 'CMR' and 'PMR' as Ticket_System is me trying to assign a literal as a newly created column.
    All the data types match from one view to the other.
    If I switch around the SQL so the 'CMR' view is at the bottom and the 'PMR' view is at the top, it still errors out on the 'PMR' view as not existing, even though I can DESC it and run the SELECT using that view. A coworker thinks it could be some kind of view alias issue (?).
    I know the view exists, and I can access it no problem. Any ideas why this isn't working? It seems so simple, I could do this in a heartbeat in SQL Server. I have very few hairs left to rip out, so any help would be appreciated.

    SELECT 'CMR' "Ticket_System",
    "Id_col" "Ticket",
    ....you have wrapped up your columns with a double quotes and use an alias. i tried the same thing
    but using a different table and it does not work.
    SQL> desc emp;
    Name                                      Null?    Type
    EMPNO                                     NOT NULL NUMBER(4)
    ENAME                                              VARCHAR2(10)
    JOB                                                VARCHAR2(9)
    MGR                                                NUMBER(4)
    HIREDATE                                           DATE
    SAL                                                NUMBER(7,2)
    COMM                                               NUMBER(7,2)
    DEPTNO                                    NOT NULL NUMBER(2)
    SQL> select "empno" "employee_number"
      2    from emp;
    select "empno" "employee_number"
    ERROR at line 1:
    ORA-00904: "empno": invalid identifier
    SQL> how were you able to run the top level of your SQL before the UNION clause? did you run it thru some tools
    other than SQL*Plus?

  • Need help in creating a page that populates 3 related tables

    Hi All,
    I am pretty new to Oracle and have been trying to use the wizards in HTML_DB to create one page that will populate three tables. I have thus far have NOT been able to find my solutions. I do not know enough experience in SQL/PL_SQL to create the code on my own.
    Here is my dilemma. I have three tables:
    con (for contacts) - with regular contact info = l_name, f_name, phone...
    pro (for different programs) - with different program info = pro_name, priority..
    procon (Contact/program) - that joins the two together with initial, follow-up and close date fields.
    I created a composite primary key in the procon table that consists of the two pk's of the other two tables (using fk relationships).
    I want to be able to use one page in HTML_DB to enter in the data which will populate all three tables. Is there a way to do this in PL/SQL?
    * Also: Is there a book out there that you can recommend that really teaches SQL/PL_SQL?
    I would really, really, REALLY appreciate the help!!!!!
    Thanks,
    d.

    This isn't as bad as you think. I would create one procedure in a package and pass the parameters to the package via htmldb
    procedure insval(in_a in number, in_b in number, in_c in number)
      begin
       insert into tablea(cola)
        values(in_a);
      insert into tableb(colb)
       values(in_b);
      insert into tablec(colc)
       values(in_c);
      end;and then you call it from htmldb using a process
    schema.package.insval(:p1_a,:p1_b,:p1_c);That's ultra-simplified, but will get the job done.
    -Scott

  • Outgoing mail document that refuses to be sent but also refuses to be deleted.

    I've got an outgoing mail message that refuses to be sent but also refuses to be deleted. It's really frustrating! I've tried pressing return and then quickly delete- quitting mail- restarting the computer- but the message keeps popping up. HELP!

    Quit Mail, Trash this file...
    Safe Boot , (holding Shift key down at bootup), use Disk Utility from there to Repair Permissions, test if things work OK in Safe Mode.
    Then move these files to the Desktop for now...
    /Users/YourUserName/Library/Preferences/com.apple.finder.plist
    /Users/YourUserName/Library/Preferences/com.apple.systempreferences.plist
    /Users/YourUserName/Library/Preferences/com.apple.desktop.plist
    /Users/YourUserName/Library/Preferences/com.apple.recentitems.plist
    /Users/YourUserName/Library/Preferences/com.apple.mail.plist
    Reboot & test.
    PS. Safe boot may stay on the gray radian for a long time, let it go, it's trying to repair the Hard Drive.

  • HOW TO CREATE A CUSTOMER NO (sales view)THAT STOERS IN KNVV TABLE

    HI ,
      how to create a customer no(sales view) that stores in tabel knvv, i able to create in kna1 table but not storing in knvv table, please provide with tcode

    Hi,
    I believe while creating customer you must be maintaining sales area if you are not maintaing then only customer's genaral data will be created and only KNA1 table will be populating.
    Rgds
    San

  • 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 spatial index on a large table

    Hi all
    I think that I might be starting to push XE beyond what it is capable of, but I thought I would ask here to see if anyone has some ideas how to get around my problem.
    I have a table with around 8,000,000 record in it. It has position data in it (SDO_GEOMETRY) which I would like to index. The geometry is not complex, just a single point for each record. The SQL I use is
    CREATE INDEX "ANNOTATION_TEXT_SX" ON "ANNOTATION_TEXT" ("GEOLOC") INDEXTYPE IS "MDSYS"."SPATIAL_INDEX"
    The command fails, due to memory issues. The errors thrown are
    ORA-29855: error occurred in the execution of ODCIINDEXCREATE routine
    ORA-13249: internal error in Spatial index: [mdidxrbd]
    ORA-13249: Error in Spatial index: index build failed
    ORA-13236: internal error in R-tree processing: [failed to cluster in memory]
    ORA-13232: failed to allocate memory during R-tree creation
    ORA-13236: internal error in R-tree processing: [failed to allocate memory 7272216 (mdrtsalloc)]
    ORA-04031: unable to allocate ORA-04031: unable to allocate 7272264 bytes of shared memory ("lar
    I have done a bit of reading up, this type of error generally occurs when the tablespace runs out of memory. Since I am using the SYSTEM tablespace, I figure I am running it out to its capacity before the index is completed.
    I have not created any other tablespaces. Is this an option to allow the creation of the index? Storage and Memory are at about 60% capacity (due to this one table) so is it just too big to create a spatial index on in XE? Am I barking up the wrong tree?
    Cheers
    James

    Good to see you are not using the SYSTEM tablespace. (And no need to apologize too profusely for being new at this - we all were at one time.)
    It normally doesn't matter how many rows are involved. The issue is how much actual space those rows require. 8,000,000 rows is actually not a lot in the GIS world, esp. if all you have is simple point data. Using the sdo_point field instead of the arrays should be a lot more compact as well.
    Some steps I would take:
    - Identify the actual amount of space used, in total as well as by tablespace. (One of the web-based admin screens can show you this.)
    - Load it all up usnig the free 'developer license' Enterprise Edition insead of XE just to verify it'll work.
    - Try indexing a smaller data set and see whether that works. (Export the table first) Delete about 1/2 rows and try indexing.
    The ORA-04031 is really telling you something about the SGA is not big enough. One of the SGA pools is trying to extend by 7M. Post the info about your SGA, as well ass some details about your machine (disk/processor/total memory)
    Message was edited by:
    forbrich
    The actual error causing the problem is the last line. It ends with "la and the rest is cut off. Could it have said 'large pool'???

  • Help to create Materialized View that has timestamp conversion

    I need help creating materialized view with timestamp conversion between GMT to LocalTime.
    Feel free to make any comments.
    Thanks in advance.
    jon joaquino;)

    Here is one way.
    1. Alter the table hist_table and add a new column pdt_timestamp.
    2. Update the new column using the function 'new_time'
    For example,
    Update hist_table
    set pdt_timestamp = new_time(gmt_timestamp,'GMT','PDT');
    3. create a materialized view log on the table 'hist_table' using the syntax
    create materialized view log on hist_table
    with primary key, rowid, sequence;
    4. create a materialized view now using the syntax:
    (You have to specify your own storage numbers and tablespace name)
    create materialized view mview_hist_table
    pctfree 0 tablespace mymview
    storage (initial 16k next 16k pctincrease 0)
    build immediate
    refresh fast on commit
    as select uid,gmt_timestamp,pdt_timestamp
    from hist_table;
    Please test on your test instance before doing it on production. I have tested this on Oracle 10g for Windows 2000. I assumed that column 'uid' is the primary key on the table. I hope this helps.
    **********************************************************

  • How to create a view on a Non-Transparent Tables.

    Hi,
    i want to create a view on P0001 & P0002 tables.
    these two tables are non transparent.
    Can any body help me ,
    Thanks in Advance,
    Regards
    Vinay

    Hi Vinay
    It seems you program HR-ABAP. Generally it is not required to create views since we use LDB (Logical database) utilizations in our programs. Doesn't it satisfy your requirement? Or is it required at somewhere you do not use LDB?
    *--Serdar

  • Creating a user thats saved to a table? possible or not???

    Ok.....so my uni assignment is to make an SQL database and then a front end in access...for a shoe store...i can make test databases and get access to connect to the sql....yay
    now im never going to get a brilliant grade because im TERRIBLE at all sort of programming (im doing computer networks not programming yet i have to do lots :(..)..............BUT one thing in the assignment states is that the shoe store would like cutomers to 'sign up' as it were....if i could get it to work that would be like one 'trick' thing that might get me a couple more marks...
    SO can i create a user that is saved to the customer table easily? or...would it take lots of knowledge and years of experience or can someone point me to some sample code or a tutorial...????
    or can this not be done and im barking up the wrong tree here?
    thanks in advance to everyone who is better at this than me!!!

    You can create a simple form with two text item each to input userid (text1) and password (text2)
    You add a submit button and you create a WHEN_BUTTON_PRESSED trigger
    In that trigger you code something like this
    Insert into Customer_Table (UserId,Password)
    Values (text1.text,text2.text)
    commit;
    there you are... you can add many users as you want.
    and when you create log in page. you create also two text item each to input userid (text1) and password (text2)
    You add a submit button and you create a WHEN_BUTTON_PRESSED trigger
    In that trigger you code something like this
    Declare
    VarID Varchar2....
    VarPass Varchar2.....
    Begin
    select UserId,Password into VarID,VarPass where UserId = VarID
    exception
    when others then
    RAISE .... 'Wrong ID'
    End;
    If VarPass = text2.text then 'OK' else 'Wrong Password'

  • How do we create a CURSOR that consists of two TABLES

    I would like to access a cursor that has columns from two tables.

    How do we create a CURSOR that consists of two TABLESA cursor does not consist of data. A cursor is not a result set that is created in the memory of the database server and populated with "+results+".
    A cursor is source code (SQL or anonymous PL/SQL block) that has been compiled into an executable program. The execution plan (see the EXPLAIN PLAN SQL command) describes the structure of this program and how it will be executed.
    When you fetch data from a cursor, you are receiving the output of this executable program known as a cursor.
    So as the other respondents explained in this thread, you need to create SQL source code that joins tables. Then you send this SQL to the server, where it is parsed and compiled into a cursor in the database's Shared Pool (together with all other SQLs that the database received - all SQLs are compiled as cursors).
    Once this is done, you can open the cursor (execute the cursor program) and fetch data from it.

  • Create Materialized View  based on another database table using db link?

    SQL> SELECT sysdate
    2 FROM dual@CBRLINK ;
    SYSDATE
    21-NOV-12
    SQL> CREATE MATERIALIZED VIEW USERCBR.V_T24_COUNTRY1
    2 REFRESH COMPLETE
    3 START WITH SYSDATE NEXT SYSDATE + (5/24)
    4 AS
    5 SELECT sysdate
    6 FROM dual@CBRLINK ;
    CREATE MATERIALIZED VIEW USERCBR.V_T24_COUNTRY1
    ERROR at line 1:
    ORA-04052: error occurred when looking up remote object SYS.DUAL@CBRLINK
    ORA-00600: internal error code, arguments: [ORA-00600: internal error code,
    arguments: [qksfroFXTStatsLoc() - unknown KQFOPT type!], [0], [], [], [], [],
    ORA-02063: preceding line from CBRLINK

    It works for me:orcl>
    orcl> CREATE MATERIALIZED VIEW scott.V_T24_COUNTRY1
      2  REFRESH COMPLETE
      3  START WITH SYSDATE NEXT SYSDATE + (5/24)
      4  AS
      5  SELECT sysdate
      6  FROM dual@l1 ;
    Materialized view created.
    orcl> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0      Production
    TNS for 32-bit Windows: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    orcl>so there is no problem with the code. HTH.

Maybe you are looking for