PL/SQL...Unsure how to loop thru multiple questions and display output?

This is my first pl/sql program, I've written psudocode on paper, but not sure what to do for two parts.
What I'm trying to do is write pl/sql that will check a row based on an employee id #.
declare
cursor cur is
select *
from employee
where employee_id = foo;What we are checking are the results the employee answered. They have answered 180 questions and I want to find when the answer a 0, 7, and 9.
Basically the pl/sql has to loop thru the 180 questions
loop
v_count := vcount + 1
select *
from employee
where q1 thru q180 in (0, 7, 9);
end loop;
dbms_output.put_line ('Employee ID' || employee_id);
dbms_output.put_line ('Q1 - Q180' || q1 - q180); I'm not sure how to write the pl/sql to loop thur all 180 questions.
I'm not sure how to display the output to show what question they scored a 0, 7, and/or a 9 on.
thanks
Message was edited by:
cmmiller

536 columns in one table? Yowsa. Without a normalized table, you are going to need dynamic pl/sql and a messy solution.
I would rethink your design, and come up with something more like so:
employee
questions
employee_responses
So that would you could easily do something like this:
declare
  cursor c1 is
    select ers.question_id,
           que.question_name,
           ers.rating
      from employee emp,
           questions que,
           employee_responses ers
     where emp.employee_id = ers.employee_id and
           que.question_id = ers.question_id and
           emp.employee_id = v_employee_id and
           ers.rating in (0, 7, 9) and
           que.enabled_flag = 'Y';
begin
  for r1 in c1 loop
    dbms_output.put_line('Question: '||r1.question_name);
    dbms_output.put_line('Employee Rated this: '||r1.rating);
  end loop;
end;Thats how I would do it - I think you are going down the wrong path. What happens if you need to create a new question or delete one? You constantly have to modify the table. Hope this helps

Similar Messages

  • How to loop through Multiple Excel sheets and load them into a SQL Table?

    Hi ,
    I am having 1 excel sheet with 3 worksheet.
    I have configured using For each loop container and ADO.net rowset enumerator.
    Every thing is fine, but after running my package I am getting below error
    [Excel Source [1]] Error: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER.  The AcquireConnection method call to the connection manager "Excel Connection Manager" failed with error code 0xC0202009.  There may
    be error messages posted before this with more information on why the AcquireConnection method call failed.
    Warning: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED.  The Execution method succeeded, but the number of errors raised (5) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified
    in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.
    [Connection manager "Excel Connection Manager"] Error: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005.
    An OLE DB record is available.  Source: "Microsoft Access Database Engine"  Hresult: 0x80004005  Description: "The Microsoft Access database engine cannot open or write to the file ''. It is already opened exclusively by
    another user, or you need permission to view and write its data.".
    Pleas suggest me the correct way of solving above issues.
    Thanks in advance :)
    regards,
    Vipin jha
    Thankx & regards, Vipin jha MCP

    Hi ,
    Please refer the below link for Looping multiple worksheet in a single SQL Table.
    http://www.singhvikash.in/2012/11/ssis-how-to-loop-through-multiple-excel.html
    Note:-If you using excel 2010 then you have to use EXCEL 12.0 .
    Above link explaining  step by step of Looping multiple worksheet in a single SQL Table.
    regards,
    Vipin jha
    Thankx & regards, Vipin jha MCP

  • PL/SQL how to loop thru SQL statement?

    Hey guys. I have this bit of a complicated problem.
    I have a cursor that selects a DISTINCT field called Term and a StudentID.
    I am looping thru that cursor.
    Inside that loop I have another SQL statement that is pulling all rows from the DB where the Term = the Term and the StudentID= the StudentID from the crusor loop.
    My problem is how do I get all the information/rows returned from that SQL statement? I need to loop thru it somehow, but I am not sure how to do it.
    If there is a better way to get this done feel free to chime in.
    Here is my code.
    /* CURSOR*/
    CURSOR c_GPAPerTerm IS
            SELECT DISTINCT Term, Student_ID FROM course_grades
            WHERE STUDENT_ID = p_StudentID;
                 /* OPEN AND LOOP THRU CURSOR*/
        OPEN c_GPAPerTerm;
        LOOP
        FETCH c_GPAPerTerm INTO v_Terms,v_StudentID;
                /* SQL STATEMENT NEED TO LOOP THRU AND GET VALUES FOR EACH ROW*/
                SELECT Score
                INTO v_Scores
                FROM course_grades
                WHERE Term = v_Terms and StudentID = v_StudentID;
        EXIT WHEN c_GPAPerTerm%NOTFOUND;
        END LOOP;
        CLOSE c_GPAPerTerm;

    Ok here's my complete code....it's pretty big though...hope it's not too confusing.
    It compiles fine if I take the new cursor out, so the error is somewhere in that cursor.
    CREATE OR REPLACE PROCEDURE get_Student_GPA(p_StudentID IN NUMBER) AS
         /*VARIABLES*/
         v_Terms VARCHAR2(6);
         v_Courses VARCHAR2(6);
         v_Scores NUMBER;
         v_Grade CHAR;
         v_GPA NUMBER;
         v_ScoresTotal NUMBER :=0;
         v_StudentID NUMBER;
         /*CURSORS*/
         CURSOR c_GetTerms IS
              SELECT Term
              FROM course_grades
              WHERE STUDENT_ID = p_StudentID;
         CURSOR c_GetCourseAndGrade IS
              SELECT Course_ID, Score FROM course_grades
              WHERE STUDENT_ID = p_StudentID;
         CURSOR c_GPAPerTerm IS
              SELECT DISTINCT Term, Student_ID
              FROM course_grades
              WHERE STUDENT_ID = p_StudentID;
         CURSOR c_GetScores (p_Term VARCHAR2, p_StudentID NUMBER) IS          
                   SELECT Score
                   FROM course_grades
                   WHERE Term = p_Term AND StudentID = p_StudentID;
         /*FUNCTIONS*/
         FUNCTION convert_grade(p_GradeNumber IN NUMBER)
              RETURN CHAR IS
         BEGIN
              /* GET NUMERIC GRADE AND CONVERT TO LETTER */
              CASE
                   WHEN p_GradeNumber < 60 THEN RETURN 'F';
                   WHEN (p_GradeNumber > 59  AND p_GradeNumber < 70) THEN  RETURN 'D';
                   WHEN (p_GradeNumber > 69  AND p_GradeNumber < 80) THEN  RETURN 'C';
                   WHEN (p_GradeNumber > 79  AND p_GradeNumber < 90) THEN  RETURN 'B';
                   WHEN (p_GradeNumber > 89  AND p_GradeNumber < 101) THEN RETURN 'A';
              ELSE    RETURN 'Z';
              END CASE;
         END convert_grade;
         FUNCTION calculate_gpa(p_TotalHourPoints IN NUMBER, p_TotalHours IN NUMBER)
              RETURN NUMBER IS
              /*CREATE VARIABLE TO HOLD GPA*/
              v_GPA NUMBER;
         BEGIN
              /*CALCULATE AND OUTPUT GPA*/
              v_GPA := p_TotalHourPoints/p_TotalHours;
              RETURN v_GPA;
         END calculate_gpa;
         FUNCTION calculate_point (p_Grade IN CHAR)
              RETURN NUMBER IS
         BEGIN
              /* GET LETTER GRADE AND CONVERT TO NUMBER */
              CASE
                   WHEN p_Grade = 'A' THEN RETURN 4;
                   WHEN p_Grade = 'B' THEN RETURN 3;
                   WHEN p_Grade = 'C' THEN RETURN 2;
                   WHEN p_Grade = 'D' THEN RETURN 1;
                   WHEN p_Grade = 'F' THEN RETURN 0;
              ELSE    RETURN 0;
              END CASE;
         END calculate_point ;
    /****BEGIN MAIN BLOCK********/
    BEGIN
         DBMS_OUTPUT.PUT_LINE('**********TERMS**********');
         OPEN c_GetTerms;
         LOOP
         FETCH c_GetTerms INTO v_Terms;
         DBMS_OUTPUT.PUT_LINE('Term: ' || v_Terms);
         EXIT WHEN c_GetTerms%NOTFOUND;
         END LOOP;
         CLOSE c_GetTerms;
         DBMS_OUTPUT.PUT_LINE('**********COURSES AND GRADES**********');
         OPEN c_GetCourseAndGrade;
         LOOP
         FETCH c_GetCourseAndGrade INTO v_Courses, v_Scores;
            v_Grade := convert_grade(v_Scores);
         DBMS_OUTPUT.PUT_LINE('Course: ' || v_Courses || '   Grade: ' || v_Grade);
         EXIT WHEN c_GetCourseAndGrade%NOTFOUND;
         END LOOP;
         CLOSE c_GetCourseAndGrade;
         DBMS_OUTPUT.PUT_LINE('**********GPA PER TERM**********');
         OPEN c_GPAPerTerm;
         LOOP
         FETCH c_GPAPerTerm INTO v_Terms,v_StudentID;
                      /*NEW CURSOR LOOP WILL GO HERE*/
                   v_ScoresTotal := v_ScoresTotal + v_Scores;
                      v_GPA := calculate_gpa(v_ScoresTotal, 3);
                   v_ScoresTotal :=0;
                   DBMS_OUTPUT.PUT_LINE('Term: ' || v_Terms || '   GPA: ' || v_GPA);
         EXIT WHEN c_GPAPerTerm%NOTFOUND;
         END LOOP;
         CLOSE c_GPAPerTerm;
    END get_Student_GPA;
    /

  • How to Loop thru a Queue?

    I have a Queue that I can add and remove items from, but I need to display all the contents currently in the Queue.
    How would I loop thru the Queue and do this?
    Any simple example will do.
    Thanks!

    Thanks for the link. It showed me which methods an Iterator has, but not practical way to use it. So I did some googling and found this example.
    import java.util.Iterator;
    import java.util.NoSuchElementException;
    for ( Iterator iter = myList.iterator(); iter.hasNext(); )
       String key = (String) iter.next();
       System.out.println( key );
       }Which makes perfect sense. However, where it says Iterator iter = myList.iterator(); I am not sure what to put in the myList.iterator(); part.
    I would assume that my Queue object would be used there, however, my Queue object has no .iterator() method.
    Like I said, I am new to Java so this is not as easy to me as it seems it should be.
    But there is all of my code if it helps.....I'll leave out the unimportant parts.
    Queenode class........................................
    public class QueueNode {
    //fields
    Object info;
    QueueNode link;
        public QueueNode() {
        public QueueNode(Object item) {
        info=item;
        link=null;
        public QueueNode(Object item, QueueNode qn) {
            info=item;
            link=qn;
    }//end classQueue class..............................................
    public class Queue {
       //create a front and back node
       private QueueNode front;
       private QueueNode rear;
       private int size;
       //methods
       public void insert(Object item){
          //if queue is empty front and rear are same
          if(isEmpty()){
              rear=new QueueNode(item);
              front = rear;
          }//end if
          //otherwise queue not empty add top end
          else{
              rear.link= new QueueNode(item);
              rear=rear.link;
          }//end else
          ///either case incriment size
          size++;
       }//end insert
       public Object remove(){
           //create a temp node referencing the front
           QueueNode oldFront=front;
           //peek at front item
           Object item = peek();
           //make front to link with the next node
           front=front.link;
           //remove temp node
           oldFront=null;
           //decrement size
           size--;
           //return the item that was removed
           return item;
       }//remove
       public Object peek(){
           if(isEmpty()){
               throw new NullPointerException();
           }//end if
           else{
               return front.info;
           }//and else
       }//end peek
       public boolean isEmpty(){
           return(size==0);
       }//end isEmpty
       public int getSize(){
           return size;
       }//end getsize
    }//end classAnd finaly my class to test that the Queue is working....................
    import javax.swing.*;
    import javax.swing.border.BevelBorder;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Iterator;
    import java.util.NoSuchElementException;
    public class QueueTest extends JFrame implements ActionListener{
        //Create Queue object
        Queue q = new Queue();
       public QueueTest(){
            //Add title to window
            super("Testing Queue's");
         }//end constructor
        public void actionPerformed(ActionEvent event){
            if (event.getSource()==btnAddQueueItem){
                q.insert(txtAddQueueItem.getText());
                for(Iterator iter = q.?????; iter.hasNext();){
                    ///Output each queue item here........
                }//end for
            }//end if
             if (event.getSource()==btnRemoveQueueItem){
                 q.remove();
             }//end if
        }//end actionPerformed
        public static void main(String[] args) {
        QueueTest testQueue = new QueueTest();
        }//end main
    }//end class

  • How to Loop thru a RFC model

    how to Loop thru the RFC model
    for(int i=0;i<wdContext.nodeEx_Org_Units().size();i++){
    //how to get the attribute each and every columns
      //mgr.reportSuccess("id" +nodeEx_Org_Units().getId());
    Message was edited by:
            yzme yzme

    Hi,
    When there is a RFC Model with table ouptut....every row in the table can be correlated to elements in the model node...
    your model node : <i>nodeEx_Org_Units</i>
    Now if you have 5 rows as output after executing the model...there will be 5 elements created under the node. Loop through all the elements and use the get methods as given below:
    // assuming tht u have two columns(attributes) <i>col1 & col2</i>
    // access the node
    IPrivate<view>.IEx_Org_UnitsNode tableNode = wdContext.nodeEx_Org_Units();
    // access the element under the node, do not initalize this element
    IPrivate<view>.IwdContext.nodeEx_Org_UnitsElement tableElem;
    //loop thrugh the elements
    for(int i=0; i<tableNode.size(); i++)
       tableElem = tableNode.getEx_Org_UnitsElementAt(i);
       // access the attributes col1 & col2
       tableElem.getCol1();
       tableElem.getCol2();
    Regards
    Srikanth

  • How do i manage multiple users and devices with one apple id without everything showing up on every device?

    how do i manage multiple users and devices with one apple id without everything showing up on every device?

    How to use multiple iPhone, iPad, or iPod devices with one computer

  • How can I have multiple accounts and only one library

    How can I have multiple accounts and only one library that all the purchased items feed into?

    ask your wireless provider.

  • How do I process multiple files and turn them from raw to jpeg

    How do I process multiple files and turn them from raw to jpeg. Ive tried and it seems to go through the files but doesnt seem to process them or store them in the selected folder

    Yes that was the first thing I did. Then I used the process multiple files and selected a new folder to put them in and selected use open files and selected to turn them into jpeg. The images flash on the screen like they are being processed, but the folder never appears in library. Is it possible because there are a couple 16 bit files open that this corrupts the task. Do I need to create the folder first. Will elements not create the folder on its own.
    Thanks Vince

  • How Can I get Interview Questions and answers for Oracle9i DBA and PL/SQL

    How Can I get Interview Questions and answers for Oracle9i DBA and PL/SQL Programmer.

    Please check the following link.
    http://www.geekinterview.com/
    -aijaz

  • How to loop through report records and update the record

    I have a updateable report. And there is a select LOV in that report. How to loop though the report and save all the changes to the LOV.

    1. Please tell us your first name and put it in your handle and/or profile to help us.
    2. Explain your question in more detail, perhaps with an example and by showing code you already are using.
    Scott

  • Looping thru instance manager and checking radio button selected

    I need to loop thru my instances and toggle visible/hidden if a particular radio button in each instance is selected.
    My code right now does not work but I feel I am on the right track (minus the else statement it will need to toggle on/off).
    Can anyone help? thanks in advance!
    var rowCount = BugGroup_f.instanceManager.count;
    for (i=0; i<rowCount; i++) {
    var str = xfa.resolveNode("BugGroup_f.detail3.bugInfo.BugItem.status.RadioButtonList[" + i + "]").rawValue;
        if (str.indexOf("Fixed") > -1) {
        xfa.resolveNode("BugGroup_f["+rowCount+"]").presence = "hidden"

    So we've got a set of Rows, each with a subitem called RadioToggle, and you want to go through and set them all, then click a separate button and hide the ones with "on" radio buttons?
    function ToggleRows(reset){
         var Rows = Form.subform....BugGroup_f.all;
         var curRow;
         for (var i=0; i<Rows.length; i++){
              curRow = Rows.item(i);
              if ((curRow.RadioButton.rawValue == "WhatevermeansHidden") && !reset){
                   curRow.presense = "hidden";}
              else{
                   curRow.presense = "visible";}
    ^ in a script object, and put
    scriptObjectName.ToggleRows(reset);
    in the click event of your button, and you should be golden.
    If you do want them to hide the moment you click the toggle, you could put this, right?
    if (xfa.event.newText == "whatevermeansoff"){
         parent....presense = "hidden";}
    The .all method seems like a much easier way to handle collections of objects, and specificaly collections of instances. It also means you can do relative referencing, i.e. to create a function that will operate on all the rows of a table, without knowing which table it is operating on, so a button in each table can pass it's parent table to the function.
    var GroupVariable = Object.all
    for(var i=0; i < GroupVariable.length; i++)
    EDIT:
    add a reset value, and pass it in to your function like above (added).
    make a separate button, or control, that will call the function with reset = 1.

  • HT5312 how to reset my security question and answer i have try everything  but can't get it don

    how to reset my security question and answer i have try everything  but can't get it don?

    WHat have you tried ?
    If you have a rescue email address (which is not the same thing as an alternate email address) set up on your account then you can try going to https://appleid.apple.com/ and click 'Manage your Apple ID' on the right-hand side of that page and log into your account. Then click on 'Password and Security' on the left-hand side of that page and on the right-hand side you might see an option to send security question reset info to your rescue email address.
    If you don't have a rescue email address (you won't be able to add one until you can answer 2 of your questions) then see if this user tip helps : https://discussions.apple.com/docs/DOC-4551
    e.g. you can try contacting iTunes Support : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Account Management , and then try Apple ID Account Security
    or try ringing Apple in your country and ask to talk to the Accounts Security Team : http://support.apple.com/kb/HE57

  • How to send my security questions and answers to my e-mail?

    how to send my security questions and answers to my e-mail?

    call apple 1-800-694-7466 ask for account security.
    Peace, Clyde

  • How do I know the question and the answer to my account

    plz how do l know the question and the answer to my account

    Hello mubarakaljereeb,
    I found an article that has mre information about the security questions for your Apple ID.  You can find the article here:
    Apple ID: All about Apple ID security questions
    http://support.apple.com/kb/HT5665
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • I'm trying to download what's app chatting application and the massage given (need your secret answers for the below questions to proceed your purchase request ) but the problem is I forgot my answers :((( how can I reset the questions and the answer ????

    I'm trying to download what's app chatting application and the massage given (need your secret answers for the below questions to proceed your purchase request ) but the problem is I forgot my answers :((( how can I reset the questions and the answer ????

    Visit this site: http://support.apple.com/kb/HT5312

Maybe you are looking for

  • How to pull the Sale order number(sales document) to Accounting document

    Hi Gurus, How to pull the sale order number to the accounting document. Is any configuration needed to this. When i run the FBL5N Repoprt ,Sale order number (Sales document) is not getting updated to accounting document.It is diplaying as blank field

  • Loading one JComponet Window then closing and Loading a different Window

    Hello and how is everyone. I believe there is two ways I cam make this Java desktop application work, but I am not sure which is the best or doable. I have right now a Component tab window that pops up ask a user to select an option. Then they hit a

  • Sun Cluster 3.1 Failover Resource without Logical Hostname

    Maybe it could sound strange, but I'd need to create a failover service without any network resource in use (or at least with a dependency on a logical hostname created in a different resource-group). Does anybody know how to do that?

  • Udo matrix -save problem

    Hi, i am creating a form by using UDO form generator. in that documet and doucument rows are existed. if user select the combobox value from the form, by taking that value and i am generating a query, i am generating a recordset. by using Userdatasou

  • SOA composite deployment logging

    When a archive file is deployed the user logged into the EM Fusion Middleware Control is logged.  For example: [2013-09-10T17:01:00.377-04:00] [soa_server1] [NOTIFICATION] [SOA-21530] [oracle.integration.platform.blocks.deploy.servlet] [tid: [ACTIVE]