Ain't getting it: insert into table by determing value from another table

I have a table (PERCENTILE_CHART) with percentiles and test scores for different tests:
Structure:
Percentile, Reading_Test, Writing_Test
Data:
30,400,520
31,450,560
97,630,750
98,630,780
99,640,800
The data is currently in ascending order by Percentile.
If a person took the Reading test and scored 630 he or she would be in the 98th (not 97th) percentile of the class taking that test.
I wrote a statement to return the percentile:
select Percentile
from ( select ROWNUM, PERCENTILE
from PERCENTILE_CHART
where READING_TEST <= '650'
order by READING_TEST desc)
where ROWNUM < 2 order by PERCENTILE desc;
This select works and is able to determine the highest percentile for a score.
Ok, now I want to process all the records in a STUDENT table which have
test scores and insert them in a new table along with the percents, normalizing the data in the process.
Have this:
STUDENT:
Student_Name,Student_ID,
John Smith,121,Reading,98,Writing,90
Maggie Smithe,122,Reading,95,Writing,96
And needs to be moved to into SCORES with the percentiles, so I get this:
SCORES:
Student_Name,Student_ID,Test_Name,Percentile
121,Reading,98
121,Writing,90
122,Reading,95
122,Writing,96
This is were I get confused. How do I insert the data into the SCORES table with the percentile? I think calling a function in package is the way to do it:
function oua_Test_Percentile_f (
p_Test_Name in char,
p_Test_Value in char)
return char as
-- Declare variables
c_Return_PTile char(2);
begin
select PERCENTILE into c_Return_PTile
from (select ROWNUM, PERCENTILE
from PERCENTILE_CHART
where p_Test_Name <= '&p_Value'
order by p_Test_Nmae desc)
where ROWNUM < 2 order by PERCENTILE desc;
return c_Return_PTile;
end;
But this function doesn't return the percentile even though it is based on my working select mentioned earlier. It returns a blank for all tests.
And even if it is working how do I then populate the SCORES table?

You may want to use analytical functions so that you can determine the percentile across all of the different scores:
SQL> with
2 PERCENTILE_CHART as
3 (
4 select 30 PERCENTILE, 400 READING_TEST, 520 WRITING_TEST from dual union all
5 select 31 PERCENTILE, 450 READING_TEST, 560 WRITING_TEST from dual union all
6 select 97 PERCENTILE, 630 READING_TEST, 750 WRITING_TEST from dual union all
7 select 98 PERCENTILE, 630 READING_TEST, 780 WRITING_TEST from dual union all
8 select 99 PERCENTILE, 640 READING_TEST, 800 WRITING_TEST from dual
9 )
10 select
11 max(percentile) over (partition by reading_test) HIGHEST_READING,
12 max(percentile) over (partition by writing_test) HIGHEST_WRITING,
13 percentile_chart.*
14 from
15 percentile_chart
16 /
HIGHEST_READING HIGHEST_WRITING PERCENTILE READING_TEST WRITING_TEST
30 30 30 400 520
31 31 31 450 560
98 97 97 630 750
98 98 98 630 780
99 99 99 640 800
SQL>
I wasn't exactly sure how you wantd to coorelate this to the student records though; the student table had only two column name headings but there were four rows listed as examples and had fewer rows than in the percentile_chart table...
If you join the student table to the able query it might be what you are looking for.
You can create another table based on the output of your query by doing:
create table scores
as select * from
(insert your query here)
/

Similar Messages

  • Breakout table (fill table with matching data from another table)

    Hi
    I've been trying to study old discussions about breakout tables. I feel I'm close, but still no cigar :-)
    In plain english, I'm trying to autocreate rows with data on a table, based on matching values from another table. E.g. have a table to display all rows where type = AssetX
    I have attached a screenshot of my "master table" called Assets:
    I'm looking to prefill Asset name, Total from this table and populate a new table called e.g. Greenhouse
    Where I'd be adding more data (date, income, expense).
    Any help whould be greatly appreciated.
    Thanks!

    Hi,
    Here is a Sample Query.
    Update Emp A
    Set Sal = (Select Sal from emp b where
    a.empno = b.empno)
    where empno in (select empno from emp);
    Regards,
    Ganesh R
    null

  • Looping delete statement where table name is coming from another table

    Hi All,
    We have to write code to delete records from active tables of WDSO.We have 5 DSO  so inspite of writing delete statement for each table we want to put all table names into one table and then loop through it .but we are getting error when we are refering that table field which has active table name.error is :
    "dictionary structure or table is either not active or does not exist "
    As per my understanding in a delete /select /insert /update statement we need to put table name (whose field we are refering ) it can't be replaced by a variable .
    ex: v_table = 'EMPLOYEE' .
    DELETE FROMv_table WHERE EMP_NAME = 'ABDC' .
    is wrong and it must be like
    ex : DELETE FROM EMPLOYEE WHERE EMP_NAME = 'ABDC' .
    but we want to make our code dynamic .
    Can you please suggest a way so that we can read the table names from another table and delete data based on some selection fom those tables .
    I tried variants ,perform etc and even searched FM for the same but not found a solution .Your help will be greatly appreciated .
    Thanks in advance .
    Regards,
    Jaya

    Hi,
    You can change your statement as follows:
    DELETE FROM (v_table) WHERE EMP_NAME = 'ABDC' .
    However, I would not recommend this. There is a standard function module RSAN_ODS_DATA_DELETE which allows selective deletion - that should be a safer way to do this. You can

  • Deleting rows from table based on value from other table

    Hello Members,
    I am struck to solve the issue said below using query. Would appreciate any suggestions...
    I have two tables having same structures. I want to delete the rows from TableA ( master table ) with the values from TableB ( subset of TableA). The idea is to remove the duplicate values from tableA. The data to be removed are present in TableB. Catch here is TableB holds one row less than TableA, for example
    Table A
    Name Value
    Test 1
    Test 1
    Test 1
    Hello 2
    Good 3
    TableB
    Name Value
    Test 1
    Test 1
    The goal here is to remove the two entries from TableB ('Test') from TableA, finally leaving TableA as
    Table A
    Name Value
    Test 1
    Hello 2
    Good 3
    I tried below queries
    1. delete from TestA a where rowid = any (select rowid from TESTA b where b.Name = a.Name and a.Name in ( select Name from TestB ));
    Any suggestions..
    We need TableB. The problem I mentioned above is part of process. TableB contains the duplicate values which should be deleted from TableA. So that we know what all values we have deleted from TableA. On deleted TableA if I later insert the value from TableB I should be getting the original TableA...
    Thanks in advance

    drop table table_a;
    drop table table_b;
    create table  table_b as
    select 'Test' name, 1 value from dual union all
    select 'Test' ,1 from dual;
    create table table_a as
    select 'Test' name, 1 value from dual union all
    select 'Test' ,1 from dual union all
    select 'Test' ,1 from dual union all
    select 'Hello' ,2 from dual union all
    select 'Good', 3 from dual;
    /* Formatted on 11/23/2011 1:53:12 PM (QP5 v5.149.1003.31008) */
    DELETE FROM table_a
          WHERE ROWID IN (SELECT rid
                            FROM (SELECT ROWID rid,
                                         ROW_NUMBER ()
                                         OVER (PARTITION BY name, VALUE
                                               ORDER BY NULL)
                                            rn
                                    FROM table_a a
                                   WHERE EXISTS
                                            (SELECT 1
                                               FROM table_b b
                                              WHERE a.name = b.name
                                                    AND a.VALUE = b.VALUE))
                           WHERE rn > 1);
    select * from table_a
    NAME     VALUE
    Test     1
    Hello     2
    Good     3Edited by: pollywog on Nov 23, 2011 1:55 PM

  • Default value from another table in dummy field on a portal form ..

    A form based on a table :
    id
    name
    xx_id
    I created a dummyfield on the form in which i would like the
    name corresponding to xx_id -> I would like to fetch a value
    from another tabel into a dummy field.
    thanx
    Trine Hindsholm

    I could do this task by creating the form manually - is there anyway I can modify the insert for a form created by the wizard?

  • How to update this table with values from another table ?

    Hi
    I have a table "regies". I want to replace the values of the column "regies.agent" by the value of the column "regies_personnes.id"
    As you see the tables have a common values column. ie regies.agent = regies_personnes.nom
    Table "regies" :
    Insert into "regies" (AGENT) values ('Humberdot Alain');
    Insert into "regies" (AGENT) values ('Danard Patrick');
    Table "regies_personnes" :
    Insert into REGIES_PERSONNES (NOM,ID) values ('Humberdot Alain',1);
    Insert into REGIES_PERSONNES (NOM,ID) values ('Danard Patrick',2);
    Before we have this
    sql>select agent from regies ;
    Humberdot Alain
    Danard Patrick
    After the update, the result should be
    sql>select agent from regies ;
    1
    2
    Thank you for your kind answer.

    You will face error if you have duplicates
    ORA-01427 Single row subquery returns Multiple rows.Try this way
    create table regies(agent varchar2(30));
    create table regies_personnes( nom varchar2(30),id number);
    Insert into regies (AGENT) values ('Humberdot Alain');
    Insert into regies (AGENT) values ('Danard Patrick');
    Insert into REGIES_PERSONNES (NOM,ID) values ('Humberdot Alain',1);
    Insert into REGIES_PERSONNES (NOM,ID) values ('Danard Patrick',2);
    Insert into regies (AGENT) values ('Humberdot Alain');
    Insert into regies (AGENT) values ('Danard Patrick');
    Insert into REGIES_PERSONNES (NOM,ID) values ('Humberdot Alain',1);
    Insert into REGIES_PERSONNES (NOM,ID) values ('Danard Patrick',2);
    commit;
    update regies r set agent = (select id from regies_personnes p where r.agent = p.nom
    and rownum=1)
      where exists (select id from regies_personnes p where r.agent = p.nom
    commit

  • Table to store values from af:table

    hi ,
    i have a requirement where in a customer enters data row by row. it is desired that the data should get stored in the database not row by row but only after the client has finished filling all the rows. once the client has pressed the commit or save button, all the rows must get disabled.He or she should not be further able to modify the order details. Could you please suggest a way?
    and one more question
    can we create a temporary table(or either buffer) which holds the values of another table.so that once the table is committed, the values will go to this temporary table and then go to database.

    Hi,
    if you use ADF Business Components then this is handled for you automatically. The only remaining thing to do is
    once the client has pressed the commit or save button, all the rows must get disabled
    In this case set a EL expression on the readOnly property of the input text field and e.g. check if the primary key field is populated (in this case you return true). The EL can check e.g. #{row.pkAttr.inputValue != null}
    Frank

  • How to make validation in Bean and select value from another table

    I want to know how to select data from table in backing bean according to primary key i have
    the problem is that
    i have a table Employee_Salary contains Employee ids and their salary
    Empoloyee_Salary table
         Employee_ID      Number
         Employee_salary Number
    And Another table Called Employees
    Employees table
         Employee_ID     Number
         IsManager Varchar2 its value is [*Yes or NO*]
    and other columns that i don't care about this table
    i have on a jsff page an <af:table> this table is editable this is the Empoloyee_Salary table
    *i want to check before save or after insert if this employee is Manager [from Employees tabke(yes or no)] the salary*
    cannot be less that 100
    i want to know how to make this how to select the value from employees table according to the id i have in the employee_salary table how to make this and make this validation
    i have to select IsManager from Employees Table to see if this manager or no
    i want to know how to make this in a bean
    i use jdeveloper 11g
    and my project is ADF Fusion project
    and the page that have the Emplpyee_Salary table is JSFF
    thanks in advance

    You might want to write this code in a validator on the entity object if it should apply from every screen.
    If you want to access view objects from a backing bean the basics are here: http://download.oracle.com/docs/cd/E15523_01/web.1111/b31974/bcservices.htm#sthref918

  • UPDATING A TABLE WITH SAME INFO FROM ANOTHER TABLE ON THE SAME DB

    0down votefavorite
    I am trying to update a table with info from another table on the same db with same table name. I just want the info to be the same , no primary key or constraint involve just a straight replacement of records and I keep getting errors WITH THE TABLE not
    being recignize. below is my query:
    UPDATE
    VNDFIL
    SET EOBTYP
    =  VNDFIL.EOBTYP, 
    EDI_X12_835_VERSION =  VNDFIL.EDI_X12_835_VERSION
    FROM
    AGERECOVERY
    WHERE
    VNDFIL.EOBTYP
    = VNDFIL.EOBTYP
    AND
    VNDFIL
    .EDI_X12_835_VERSION
    = VNDFIL.EDI_X12_835_VERSION

    Hi rotary,
    If those two same named tables are in the same database then they have to be in different schemas. If you mean they are in the same server instance, then they may be in different databases, besides the "table not being recognized" error,
    anyway you should use the fully qualified table names, that is database.Schema.Table(If across instances, ServerName should be prefixed) to avoid the table unrecognized error.
    Using Identifiers As Object Names
    With the fully qualified names, your update statement can be like below.
    UPDATE
    db1.schema1.VNDFIL
    SET EOBTYP = srcTbl.EOBTYP, EDI_X12_835_VERSION = srcTbl.EDI_X12_835_VERSION
    FROM
    db1.schema2.VNDFIL srcTbl
    WHERE
    db1.schema1.VNDFIL.EOBTYP = srcTbl.VNDFIL.EOBTYP AND
    db1.schema1.VNDFIL.EDI_X12_835_VERSION = srcTbl.VNDFIL.EDI_X12_835_VERSION
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • Default value from another table - sql query

    I'm trying to make the default value of a text item as the result from an sql or pl/sql statement. I keep getting errors when I try to use a pl/sql statement to do this. Has anyone else done this?

    OK, here is what I tried to put in. I have a form and I wanted to add a text field that is derived from another table, such as:
    select question from qa_main where seq=:quest_num
    So, what I want is to have a form where questions on tests are answered, and I want the text of the question to be brought over from the question table. I'm not sure if I'm using the correct syntax, but the ":quest_num" would be a reference to a question number in the answer table that is linked to the sequence number (primary key) in the questions table.
    Of course if there are better ideas, please let me know. :)

  • Create a table which has columns from another table in other schema

    Hi All
    I need to create a table which is table driven i.e., the columns of that table need to be inserted from another table in a different schema...Can any one help me with this??

    create table newtab (--column spec here--) as
    Select --columns here-- from otherschema.tablename;max

  • Update table based on values from other table

    Hi,
    I am trying to update one table based on the values of another table. Since you can't use From in update statements, how do you execute this?
    For example i have to tables, Table A and Table B. I want to update a column or columns in Table A based on another value in Table B:
    So if the column in Table B was 1 then column in Table A would be Yes, if Table B was 2, then Table A would be Yes, if Table B was 3 then Table A would be N/A and so on...
    Any help would be appreciated.
    thanks,
    scott

    SQL> select * from t1;
    ID ST
    1
    2
    3
    SQL> select * from t2;
    NO
    1
    2
    3
    4
    SQL> update t1 set status=(select decode(no,1,'Y',2,'N','NA') from t2 where t1.id=t2.no);
    3 rows updated.
    SQL> select * from t1;
    ID ST
    1 Y
    2 N
    3 NA
    Daljit Singh

  • Procedure to insert data into table by selecting data from another table

    Hi all,
    I have to create a procedure where i have to select the data from one table and insert it into another table. Any help on this. And i have to update the 2nd table also when ever new records got inserted in the 1st table then.
    Regards

    Hi, you can try something like:
    CREATE [OR REPLACE] PROCEDURE procedure_name
    IS
    BEGIN
    INSERT INTO TABLE1
    VALUES (SELECT * FROM TABLE2);
    END;
    For the other part you may create a trigger on the first table AFTER INSERT to insert the values in the second table too.

  • Remove row from table when adding values to another table

    hi am adding value programticaly how can i remove the row i just  add from the table
    this is how am adding value
    public void addMember(javax.faces.event.ActionEvent actionEvent) {
    List<String> tempTable = new ArrayList<String>();
    //Code to get the bindings for TargetVO :
    RowKeySet selectedEmps = getEmpTable().getSelectedRowKeys(); 
    Iterator selectedEmpIter = selectedEmps.iterator();
    DCBindingContainer bindings =
    (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
    DCIteratorBinding empIter = bindings.findIteratorBinding("UserDetailsViewVO1Iterator");
    RowSetIterator empRSIter = empIter.getRowSetIterator();
    while(selectedEmpIter.hasNext()){
    Key key = (Key)((List)selectedEmpIter.next()).get(0);
    Row currentRow = empRSIter.getRow(key);
    onRowCreate(currentRow);
    boolean b = selectedEmps.remove(currentRow);
            i what to clear the row i just selected from the table
    AdfFacesContext.getCurrentInstance().addPartialTarget(empTable);
    // empTable
    public void onRowCreate( Row currentRow ) {
    BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
    //access the name of the iterator the table is bound to.
    DCIteratorBinding dciter = (DCIteratorBinding) bindings.get("addmemberBeanIterator");
    //access the underlying RowSetIterator
    RowSetIterator rsi = dciter.getRowSetIterator();
    //get handle to the last row
    Row lastRow = rsi.last();
    //obtain the index of the last row
    int lastRowIndex = rsi.getRangeIndexOf(lastRow);
    /*check if the user is added already*/
    /*OperationBinding oper2 = (OperationBinding) bindings.get("check if user exists method binding");
    oper2.getParamsMap().put("attributeName1", uniqueUserAttributeValue);
    Object ret = oper2.execute();*/
    //create a new row
    Row newRow = rsi.createRow();
    String f = (String)currentRow.getAttribute("Firstname");
    String s = (String)currentRow.getAttribute("Surname");
    String u = (String)currentRow.getAttribute("Username");
    String n = (String)currentRow.getAttribute("Emailaddress");
    // String orgid = (String)currentRow.getAttribute("Organisationid");
    newRow.setAttribute("firstname", f);
    newRow.setAttribute("surname", s);
    newRow.setAttribute("name", u);
    newRow.setAttribute("emailaddress", n);
    // newRow.setAttribute("Organisationid1",orgid);
    //initialize the row
    newRow.setNewRowState(Row.STATUS_INITIALIZED);
    //add row to last index + 1 so it becomes last in the range set
    rsi.insertRowAtRangeIndex(lastRowIndex +1,  newRow);
    //make row the current row so it is displayed correctly
    rsi.setCurrentRow(newRow); 
    System.out.println("Username " + u);
    System.out.println("firstname " + f);
    System.out.println("surname " + s);
    System.out.println("email " + n);
    // refereshpage();
    // return null;
    am in jdevloper 11.1.1.6.0
    my table is
    public void onRowCreate( Row currentRow ) {
    BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
    //access the name of the iterator the table is bound to.
    DCIteratorBinding dciter = (DCIteratorBinding) bindings.get("addmemberBeanIterator");
    //access the underlying RowSetIterator
    RowSetIterator rsi = dciter.getRowSetIterator();
    //get handle to the last row
    Row lastRow = rsi.last();
    //obtain the index of the last row
    int lastRowIndex = rsi.getRangeIndexOf(lastRow);
    /*check if the user is added already*/
    /*OperationBinding oper2 = (OperationBinding) bindings.get("check if user exists method binding");
    oper2.getParamsMap().put("attributeName1", uniqueUserAttributeValue);
    Object ret = oper2.execute();*/
    //create a new row
    Row newRow = rsi.createRow();
    String f = (String)currentRow.getAttribute("Firstname");
    String s = (String)currentRow.getAttribute("Surname");
    String u = (String)currentRow.getAttribute("Username");
    String n = (String)currentRow.getAttribute("Emailaddress");
    // String orgid = (String)currentRow.getAttribute("Organisationid");
    newRow.setAttribute("firstname", f);
    newRow.setAttribute("surname", s);
    newRow.setAttribute("name", u);
    newRow.setAttribute("emailaddress", n);
    // newRow.setAttribute("Organisationid1",orgid);
    //initialize the row
    newRow.setNewRowState(Row.STATUS_INITIALIZED);
    //add row to last index + 1 so it becomes last in the range set
    rsi.insertRowAtRangeIndex(lastRowIndex +1,  newRow);
    //make row the current row so it is displayed correctly
    rsi.setCurrentRow(newRow);  
    System.out.println("Username " + u);
    System.out.println("firstname " + f);
    System.out.println("surname " + s);
    System.out.println("email " + n);
    // refereshpage();
    // return null;

    hi,
    make the table selection single and use this links 4 ur task.
    http://www.baigzeeshan.com/2010/06/deleting-multi-selected-rows-from-adf.html
    http://deepakcs.blogspot.com/2013/01/ejb-dc-deleting-multi-selected-rows.html
    https://forums.oracle.com/thread/2534813
    https://blogs.oracle.com/jdevotnharvest/entry/iterating_selected_rows_in_an
    txs

  • Validating Tabular Form Column Against Value From Another Table

    Hi,
    I am brand new to this forum, so please bear with me a little!  I only have a small amount of experience writing PL/SQL, and I've never written Javascript or JQuery before.  I am an Oracle DBA, and I have coding experience in C and PERL, so I do have a solid technical background.  But, I need some advice on the best way to approach a problem.
    I have a database application in Oracle Apex (version 4.2) with a tabular form against a table: let's say Table #1 with cols 1A, 1B, and1C.  I need to ensure that the value entered into col B isn't greater than the value of a column in another table (let's say Table #2 col 2A).  Conceptually, the amount of money available is in Table #2, and the rows of my tabular form are an act of spending money (like orders or invoices), so I need to make sure we don't spend more than we have.  Does that make sense?
    Does anyone have any advice for the best way to do this?  I'm figuring the biggest issue here might be that we have to account for people entering mutliple rows in the tabular form at one time, right?  So, if a person entered 3 orders/invoices, I need a total to make sure they didn't spend more than we have in Table #2.
    I greatly appreciate your help! 
    Best Regards,
    Laurie Baublitz

    Hi!
    You need one process of type ajax callbacks like:
    DECLARE
       l_limit nubmer;
       l_number1 number := apex_application.g_x02;
       l_returnValue VARCHAR2(200);
    BEGIN
       select A2 into l_limit from table2;
       if l_number1 > l_limit then
          l_returnValue := 'LIMIT IS NOT SO BIG';
          if l_returnValue is not null then
             --this will write l_returnValue to the buffer, and the ajax callback will receive this
            htp.p(l_returnValue);
          end if;
      end if;
    END;
    Then you need one javascript on page, code is something like:
    $('input[name=your column in tabular which is change]').live('change', function(){
       //if value of changed field differs from an empty string
       if($(this).val()!=''){
          //put target element in a var to reference it in the ajax success callback
          var num  = $('input[name=your column in tabular with value]');
          $.post('wwv_flow.show',
                 {"p_request"      : "APPLICATION_PROCESS=your ajax callback function",
                  "p_flow_id"      : $v('pFlowId'),
                  "p_flow_step_id" : $v('pFlowStepId'),
                  "p_instance"     : $v('pInstance'),
                  "x01"            : $(this).val(),
                  "x02"            : $(num).val()
                  function(data){
                     if(data !=''){
                     alert(data);
    I can not guarante that code is 100% working, if not you need to do some changes or make an example on apex.oracle.com and provide credentials here.
    Regards,
    drama9346

Maybe you are looking for

  • Am not able to open time machine data due to 'insufficient privelages.'

    Try to explain easy. - Have an old mac system backed up with time machine on an external hard drive (from a mac tower i was using last year.) - Usually I can go into hard drive and take stuff off and put it on this one (laptop). - decided today that

  • Too small Time Machine Backups

    Hello everybody, at first excuse my bad english. I try my best to explain my problem as exactly in english words as I can. I have my Time Capsule 1TB for quite a while and Time Machine did it's backups on the TC well using the TC password to save the

  • I didn't know Macs behaved like this...

    Hey everyone, I never thought I'd come to a day where a PC would be more reliable than a Mac but I guess this is the reality. I purchased my unibody Macbook approx. 2 years ago. It's had the odd crashes, applications crashing one after another etc bu

  • HTML Formatter

    Hi does anyone know of a real good html kit which is a freeware and helps u in making screens that look same when designed and also when displayed in applications :) Thanks

  • Deployment Error in NWDS

    Hi All.. When i deploy my application on portal , i get following error:: Deployment exception : Server eppune did not accept login request as admin on port 50118. Details: ERROR: Could not establish connection to server eppune at port 50118: Connect