Open Cursor using other function/procedure

Hi
I have a procedure that return a cursor to Java, but if it send a parameter or other I wanted to call a procedure or function and return cursor to java , Is possible it ?
Example
PROCEDURE  XYZ ( P_ORD    IN  NUMBER,
                 p_CURSOR OUT SYS_REFCURSOR)
IS
BEGIN
   IF P_ORD  =1 THEN
      -- here I want to open cursor from other procedure/function
      OPEN P_CURSOR 
   ELSIF P_ORD  = 2 THEN
   END IF;
END XYZ;Message was edited by:
muttleychess

Looking at your example code, you say you want to open a cursor from another procedure.
I would suggest taking a step back and looking into the basics of procedural programming, especially in the area of variable scopes.
The scope of the cursor declared in another procedure will be that it exists within that procedure only.
In order to use another procedure's cursor you would have to call that procedure and have it return a SYS_REFCURSOR to your first procedure in the same manner you are trying to return a sys_refcursor to your Java code.

Similar Messages

  • I am having touble opening email and other function

    I am having trouble opening email and other functions

    I believe i have reader x. trying get it out, so i can have control of cumpter

  • Cursors using a function pointer iterator

    I'm implementing an iterator to go over the records from a Berkeley DB. However, it seems I need to set the DB_DBT_USERMEM flag before the call to cursor->get with DB_NEXT.  Doing it that way would make my iterator less cohesive and will have to implement multiple iterators for each data type I want to retrieve.
    Is there a way to have a generic iterator that can traverse structures w/o pointers, and basic types? Here's what I'm trying to achieve.
    #include <stdio.h>
    #include <string.h>
    #include <db.h>
    // let this function handle integers and use DB_DBT_USERMEM for memory alignment
    void integer_items(DBT key, DBT data) {
            int number = 0;
            data.data = &number;
            data.flags = DB_DBT_USERMEM;
            data.ulen = sizeof(int);
            printf("key is: %s, data is: %d\n", (char *) key.data,number);
    // let this function handle pointer structs. No need for DB_DBT_USERMEM
    void ptr_struct_items(DBT key, DBT data) {
            // MY_STRUCT user;
            // marshall struct...
            // buffsize = sizeof(int) +(strlen(user.familiar_name) + strlen(user.surname) + 2);
            // databuff = malloc(buffsize);
            // memset(databuff, 0, buffsize);  
            // printf("key is: %s, data is: %d\n", (char *) key.data,number);
    int iterator(DB *database, void(*function)(DBT key, DBT data)) {
            DBT key, data;
            DBC *cursor;
            memset(&key, 0, sizeof(DBT));
            memset(&data, 0, sizeof(DBT));
            database->cursor(database, NULL, &cursor, 0);
            while(cursor->c_get(cursor, &key, &data, DB_NEXT) == 0){
                    (*function)(key, data);
            cursor->c_close(cursor);
            return 0;
    int main() {
            DB_ENV *myEnv;
            DB *dbp;
            DBT key, data;
            int r, v = 10;
            char *k = "Test";
            db_env_create(&myEnv, 0);
            myEnv->open(myEnv, "./", DB_CREATE | DB_INIT_MPOOL, 0);
            db_create(&dbp, myEnv, 0);
            dbp->open(dbp, NULL, "test.db", NULL, DB_HASH, DB_CREATE, 0664);
            memset(&key, 0, sizeof(key));
            memset(&data, 0, sizeof(data));
            key.data = k;
            key.size = strlen(k) +1;
            data.data = &v;
            data.size = sizeof(int);
            if((r=dbp->put(dbp, NULL, &key, &data, 0)!=0))
                    fprintf(stderr, "%s\n", db_strerror(r));
            iterator(dbp, integer_items);
            iterator(dbp, ptr_struct_items);
            return 0;

    Mike, Thanks for your response. From your sample struct, if I normalize my data by using a structure, then I assume I won't need DB_DBT_USERMEM? since all the data would be stored and packed into a single location in memory, i.e. databuff:
           buffsize = sizeof(int) + sizeof(int);
           char * databuff = malloc(buffsize);
            // copy everything to the buffer
            memcpy(databuff, &(user.data_type_indicator), sizeof(int));
            bufflen = sizeof(int);
            memcpy(databuff, &(user.data_size), sizeof(int));
            memcpy(databuff + bufflen, user.data_size, sizeof(int));
            bufflen += sizeof(int);
            data.data = databuff;
            data.size = bufflen;
    Is that what you are referring to?

  • OPEN CURSOR using a WITH clause in the select query

    Hi,
    I am using Oracle 9i. I have a requirement where I have a REFCURSOR as an OUT parameter for my procedure. I have declared the TYPE and created the procedure.
    In the procedure, I am using OPEN <cursor_name> FOR <query>;
    Ideally this works in most of the cases that I have tried earlier. However, in the current case I am using a WITH clause in my query to get the results.
    I need help in understanding if the above mentioned syntax would not allow me to use the WITH clause in the query.

    What error do you get , seems to work ok for me on 10g
    SQL> begin
      2  open :cv for 'with x as (select * from emp)  select * from x';
      3  end;
      4  /
    PL/SQL procedure successfully completed.
    SQL> print :cv
         EMPNO
    ENAME
    JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7521
    WARD
    SALESMAN        7698 22-FEB-81       1250        500         30
          7566
    JONES
    MANAGER         7839 02-APR-81       2975                    20
         EMPNO

  • Opening cursor on pipelined functions

    Hi forum,
    Is it possible to open a cursor /any iteration of rows possible in pipelined functions ?
    Pls see the example below :
    cursor c is select * from TABLE ( generate_pipelined_rows())
    and iterate through cusror variable of C?
    Thaks,
    Aneesh

    may be something like this
    FOR c IN (SELECT * from TABLE(generate_pipelined_rows()))
    Loop
    --process data
    END LOOP;

  • How to use SYS_CONTEXT Function/procedures

    Hello, I am not familiar with this function and am trying to get a better understanding of how it works and how to find WHERE the data is being stored.
    I understand that this is an Oracle Function as well as how its parameters are used, but I don't understand where the data is stored:
    Example (my client created this query - in part):
    SELECT
    COLUMN1,
    COLUMN 2
    from TABLEA A
    where a.company = sys_context('USER_CONTEXT','SL_OJSQ_COMP_CODE')
    and a.job_code = sys_context('USER_CONTEXT','SL_OJSQ_JOB_CODE')
    and a.phase = sys_context('USER_CONTEXT','SL_OJSQ_PHS_CODE')
    and a.category = nvl(sys_context('USER_CONTEXT','SL_OJSQ_CAT_CODE'), a.category)
    I am trying to figure out how the JOIN is being used. How can I find the table/data for sys_context('USER_CONTEXT','SL_OJSQ_COMP_CODE') or maybe it is not a table/data but a package...?
    Any guidance is appreciated,

    Hello, I am not familiar with this function and am
    trying to get a better understanding of how it works
    and how to find WHERE the data is being stored.
    I understand that this is an Oracle Function as well
    as how its parameters are used, but I don't
    understand where the data is stored:
    Example (my client created this query - in part):
    SELECT
    COLUMN1,
    COLUMN 2
    from TABLEA A
    where a.company =
    sys_context('USER_CONTEXT','SL_OJSQ_COMP_CODE')
    and a.job_code =
    sys_context('USER_CONTEXT','SL_OJSQ_JOB_CODE')
    and a.phase =
    sys_context('USER_CONTEXT','SL_OJSQ_PHS_CODE')
    and a.category =
    nvl(sys_context('USER_CONTEXT','SL_OJSQ_CAT_CODE'),
    a.category)
    I am trying to figure out how the JOIN is being used.
    How can I find the table/data for
    sys_context('USER_CONTEXT','SL_OJSQ_COMP_CODE') or
    maybe it is not a table/data but a package...?
    Any guidance is appreciated,There is no JOIN in your statement.
    USER_CONTEXT is the name of an application context which is already created and should be initialized in your session. It is simply a set of attributes and your query shows some of them : SL_OJSQ_COMP_CODE, SL_OJSQ_CAT_CODE, ...
    you can query the view session_context to see attributes and values of contexts initialized in your session

  • Private function / procedure to be used with in a package

    Hi All
    I wanted to find out how would the definition be for a function which is defined so as to be used/called by the other functions / procedures with in a particular pakage and should not be visible/accessible for any other routine out side the package in which it is defined..
    could you please advice me on this? Thanks!
    Sarat

    It is possible: you can nest one function/procedure in another:
    SQL>CREATE OR REPLACE FUNCTION sum_squares(
      2     p_a   IN   NUMBER,
      3     p_b   IN   NUMBER)
      4     RETURN NUMBER
      5  IS
      6     FUNCTION square(
      7        p_n   IN   NUMBER)
      8        RETURN NUMBER
      9     IS
    10     BEGIN
    11        RETURN p_n * p_n;
    12     END square;
    13  BEGIN
    14     RETURN square(p_a) + square(p_b);
    15  END sum_squares;
    16  /
    Function created.
    SQL>SELECT sum_squares(3, 4) FROM dual;
    SUM_SQUARES(3,4)
                  25Urs

  • Metrics " Current Open Cursors Count "

    Hi,
    I get an Alert message Metrics " Current Open Cursors Count is at 1201 '" on 10g database version 10.2.0.1.0 . Can anyone help me to solve this.
    Thanks
    Sree

    Sree,
    The Metric corresponds to the number of records in V$OPEN_CURSOR internal view.
    The number of open cursors is a function of the number of concurrent users and the application code ,so 1201 may not necessaryly indicate a problem – it could be that you system is genuinely very busy.
    You should start worrying if the number of open cursors consistently grows over time (while the workload is steady). In this case you may have a “cursor leak” – a piece of code that opens a cursor, but does not close it.
    You can check that with
    select substr(sql_text,1,30) , count(*) cnt
    from v$open_cursor
    group by substr(sql_text,1,30)
    order by 2 desc
    If the current open cursor are getting close to the max allowed(OPEN_CURSOR parameter), you may reset them using share pool flush (note that the shared pool flush may have some small performance impact on the system).
    Hope that helps,

  • Maximum Open Cursors Exceeded - Oracle & Java

    I am using NetBeans ( Forte 5) for developing an application with Oracle Database. My application makes use of executeUpdate, executeQuery statements inorder to access Database.
    After few insertions and deletions of data through the host language( Java), my application stops working. It gives out the error.
    java.sql.SQLException: ORA-01000: maximum open cursors exceeded[/b
    Is this the problem with Forte or Oracle. I am using Oracle in a network in which i have got a tablespace in the Database server.
    How to tackle this problem.

    I am using 3 methods preparedStatements
    1. execute - returns boolean
    2. executeQuery - returns ResultSet
    3. executeUpdate - returns int
    I am closing the ResultSet object returned by executeQuery using
    close() method.
    Is this the correct way to close the open cursor.
    I access the table attributes using a rs.getString(colNum) and
    rs.getInt(colNum)
    Even then i am getting the maximum open cursors exceeded message.
    Will Oracle open a cursor for execute and executeUpdate which is not returning a ResultSet object .
    If Oracle opens a cursor for these two methods, how should i close the open cursor.

  • ORA-01000: maximum open cursors exceeded--Error

    Hi
    What is "ORA-01000: maximum open cursors exceeded" error,How to solve.
    Thanks
    Miseba

    Hi
    ORA-01000: maximum open cursors exceeded
    Other terms
    Oracle, open cursors, exchange infrastructure
    Reason and Prerequisites
    The parameter "open_cursors" is set too low. Long transactions, such as imports, may use up all available cursors and fail.
    Solution :
    THIS NOTE APPLIES TO XI 3.0 SP2 ONLY **
    if you encounter an exception that reports "ORA-01000: maximum open cursors exceeded" please adjust the open_cursors parameter as follows:
    If the BR*Tools exist on your system:
    1] directory: /usr/sap/<SID>/SYS/exe/run
    2] "brspace -c force -f dbparam -a change -p open_cursors -v 100000"
    3] directory: $ORACLE_HOME/dbs (Unix) or %ORACLE_HOME%/database (Win)
    4] change open_cursors parameter in init<SID>.ora to 100000
    If the BR*Tools are not available (2] above - command not found)
    1] change the open_cursors parameter as in 4] above
    2] restart DB, for changes to take effect. _ NOTE: This problem has been fixed with XI 3.0 SP3 (see note 735078)
    Plz asign points if helpfull.
    Regards
    Padmanabha

  • Oracle database open cursor created by clob.getCharacterStream()

    I cannot close open cursor created by clob.getCharacterStream();
    I use the following code. Please note that I close the Reader Stream.
    Since my database connection is pooled I cannot close the connection to close the cursor. SQL_TEXT field in v$open_cursor shows "table_4_200_1862_0_0_0" or some thing like that.
    Thanks in advance for any reply.
    public static String readClob( Clob clob )
    StringBuffer bufCLOB = new StringBuffer();
    int nbytes = 0;
    char[] buffer = new char[ 32768 ];
    try
    java.io.Reader clobReader = clob.getCharacterStream();
    int len = 0;
    while( ( len = clobReader.read( buffer ) ) != -1 ){
    bufCLOB.append( buffer, 0, len );
    clobReader.close();
    catch( Exception ex )
    ex.printStackTrace();
    return bufCLOB.toString();
    }

    I found the reply from somewhere. It seems implecit open cursors donot count to maximum allowed one. While updaint clob fields oracle opens implecit open cursors.

  • How can i measure the transmision time in gpib with visual basic with more precision if i use time() function?

    I want to take a measurement of the time that i use to make a gpib transmision in a Visual Basic program,i use the function TIME() to take the time in the begining and other time in the end,but this way only give me precision of seconds, and i want miliseconds,can i use other function,other way?
    Can answer in spanish?

    Try using GetTickCount() API function, which provides millisecond precision. If you need more precise timer, try using QueryPerformanceCounter() function.
    Makoto

  • How to use replace function to replace word

    I am trying to write a replace function in which I replace CA with California in an address string.
    I am trying to avoid using regular expression and just use other functions like replace, instr, trim etc.
    But what my main confusion is how do i take care of three cases in which.
    CA can be present with spaces before and after it like.
    - Redwood City, CA 96403
    CA can be present with spaces only before it and after it the string ends.
    - Redwood City, CA
    and I do not want to replace any other CA in the string that is part of other word
    - Blaca Street CA
    ( for example do not replace ca in Blaca)
    or
    - Cardinal Dr CA
    Thanks

    Hi,
    user6287828 wrote:
    ... (only four of these abbreviations need to be replaced)In that case, nesting the functions one inside another won't be too bad. But watch out: this is exactly the kind of requirement that changes over time. You might only need 4 states now, nut next year they might expand the application so that you need all 50 states (plus Puerto Rico, and DC, and ....). In that case, something like MODEL, or a user-defined PL/SQL function, would be better.
    As these are abbreviations these will always be stand alone words and never part of words. And these abbreviation can be at the beginning or end or in between the string.
    And any abbreviation can be present in one column.
    More than one abbreviation can be present in one column
    None of the abbreviations can be present in this column.
    For example
    column
    3251 BLACA ROAD CA 94305
    74 CALDWIN STREET CA
    67 DIGITAL DRIVE NM
    NM UNIVERSITY AVENUE 890
    7645 ROCHESTER NY PARK STREET
    834 GRAND AVENUE ATLANTAPost CREATE TABLE and INSERT statements for the sample data.
    Include all special cases, e.g. more that one abbreviation in the same column.

  • Generating Data for INSERT using a Stored Procedure, Function and Cursor

    I've written a function that I finally got to compile, but was not successful in importing and inserting the data needed to populate a table with at least 1800 rows. Here's what I needed to do:
    -- Generate a random test score ranging from 20 to 100 (already done)
    -- Generate a random final grade for the course ranging from 4 to 0 (representing A to F) (already done, but question below.
    -- Use conditional statements based on the counter to assign three courses (already done -- see SQL statements)
    -- Process no more than 95% of the students (300) for test 1.
    -- For test 2, process no more than 80% of the students who took test 1. Student cannot take test 2 unless the student takes test 1 (does this require a trigger? If so, how would I go about doing this?)
    -- Use a function or another subprocedure to process the grade using IF-ELSIF statements
    For example, I've tried the following statements:
    For procedures
    IF birth_date BETWEEN to_date('01-Jan-89 AND to_date('31-Dec-89','dd-Mon-yy') THEN
    school_grade := 6;
    AND for functions:
    IF birth_date BETWEEN to_date('01-Jan-89 AND to_date('31-Dec-89','dd-Mon-yy') THEN
    RETURN (6);
    RETURN;
    - or -
    IF birth_date BETWEEN to_date('01-Jan-89','dd-Mon-yy') AND to_date('31-Dec-89','dd-Mon-yy') THEN
    school_grade := 9
    RETURN school_grade;
    -- Read the birth_date into the main procedure so that the value returned from the subprocedure or function can populate the birth_date column.
    To give you an idea of what I've already done:
    SQL>
    SQL> CREATE OR REPLACE PROCEDURE add_tests (v_school_grade IN NUMBER) AS
    2
    3 v_counter NUMBER(3) := 0;
    4 v_num_students CONSTANT NUMBER(3) := 300;
    5 v_students_test1 NUMBER := 0;
    6 v_students_test2 NUMBER := 0;
    7 v_student_id VARCHAR2(5);
    8 v_course1 VARCHAR2(2);
    9 v_course2 VARCHAR2(2);
    10 v_course3 VARCHAR2(2);
    11 v_course4 VARCHAR2(2);
    12 v_student_grade NUMBER(1) := 0;
    13 v_test_score NUMBER(3) := 0;
    14 v_course_final_grade NUMBER(1) := 0;
    15 v_birth_date DATE;
    16
    17 FUNCTION pkg_get_grade RETURN NUMBER
    18 IS
    19
    20 v_birth_date DATE;
    21 v_school_grade NUMBER(1) :=0;
    22
    23 CURSOR grade_cur IS
    24 SELECT birth_date FROM students;
    25
    26 BEGIN
    27 OPEN grade_cur;
    28 LOOP
    29 FETCH grade_cur INTO v_birth_date;
    30
    31 EXIT WHEN grade_cur%NOTFOUND;
    32
    33 -- Assign student grade
    34
    35 -- 9th Grade
    36
    37 IF v_birth_date < TO_DATE('01-Jan-87','DD-Mon-YY') THEN
    38 v_school_grade := 9;
    39
    40 -- 8th grade
    41
    42 ELSIF v_birth_date BETWEEN
    43 TO_DATE('01-Jan-87','DD-Mon-YY') AND
    44 TO_DATE('31-Dec-87','DD-Mon-YY') THEN
    45
    46 v_school_grade := 8;
    47
    48 -- 7th grade
    49
    50 ELSIF v_birth_date BETWEEN
    51 TO_DATE('01-Jan-88','DD-Mon-YY') AND
    52 TO_DATE('31-Dec-88','DD-Mon-YY') THEN
    53
    54 v_school_grade := 7;
    55
    56 -- 6th grade
    57
    58 ELSIF v_birth_date BETWEEN
    59 TO_DATE('01-Jan-89','DD-Mon-YY') AND
    60 TO_DATE('31-Dec-89','DD-Mon-YY') THEN
    61
    62 v_school_grade := 6;
    63
    64 -- 5th grade
    65
    66 ELSIF v_birth_date > TO_DATE('31-Dec-89','DD-Mon-YY') THEN
    67
    68 v_school_grade := 5;
    69
    70 END IF; -- end if loop for student's grade
    71 END LOOP; -- end loop for grade_cur
    72 CLOSE grade_cur; -- close cursor for assigning grade
    73 RETURN v_school_grade;
    74
    75 END pkg_get_grade;
    76
    77 PROCEDURE delete_test_info AS
    78
    79 BEGIN
    80
    81 DELETE FROM student_facts;
    82
    83 END delete_test_info;
    84
    85 BEGIN
    86
    87 -- Process student for tests
    88
    89 WHILE (v_counter <= v_num_students) LOOP
    90 v_counter := v_counter + 1; -- initialize counter
    91
    92 -- Set student id
    93
    94 v_student_id := 'S'&#0124; &#0124;v_counter;
    95
    96 -- portion of students taking beginning of year tests
    97
    98 v_students_test1 := v_num_students * .95;
    99
    100
    101 -- Portion of students taking end of year tests
    102
    103 v_students_test2 := v_students_test1 * .80;
    104
    105
    106 -- Est. test scores between 20 and 100
    107
    108 v_test_score := random.rand_max(80) + 20;
    109
    110
    111 -- Est. final grade for course between 0 and 4
    112
    113 v_course_final_grade := random.rand_max(4);
    114
    115
    116 -- Process tests for courses
    117
    118 IF v_counter < ROUND(v_num_students * .20) THEN
    119 v_course1 := 'C1';
    120 v_course2 := 'C2';
    121 v_course3 := 'C3';
    122
    123 ELSIF v_counter BETWEEN ROUND(v_num_students * .20)
    124 AND ROUND(v_num_students * .40) THEN
    125
    126 v_course1 := 'C2';
    127 v_course2 := 'C1';
    128 v_course3 := 'C3';
    129
    130 ELSE IF v_counter BETWEEN ROUND(v_num_students * .40)
    131 AND ROUND(v_num_students * .60) THEN
    132
    133 v_course1 := 'C3';
    134 v_course2 := 'C1';
    135 v_course3 := 'C2';
    136
    137 ELSE IF v_counter BETWEEN (v_num_students * .60)
    138 AND ROUND(v_num_students * .80) THEN
    139
    140 v_course1 := 'C3';
    141 v_course2 := 'C1';
    142 v_course3 := 'C2';
    143
    144 ELSE
    145 v_course1 := 'C4';
    146 v_course2 := 'C2';
    147 v_course3 := 'C3';
    148
    149 END IF;
    150 END IF;
    151 END IF;
    152
    153 -- Input test information for students
    154
    155 -- Beginning of year test for Course 1
    156
    157 IF v_counter <= v_students_test1 THEN
    158 INSERT INTO studentfacts
    159 VALUES(v_student_id, v_course1, 'ACH1999',
    160 TO_DATE('01-SEP-1999','DD-MON-YYYY'),
    161 v_student_grade, v_course_final_grade, v_test_score);
    162 ELSE
    163 INSERT INTO studentfacts
    164 VALUES(v_student_id, v_course1, 'ACH1999',
    165 TO_DATE('01-SEP-1999','DD-MON-YYYY'),
    166 v_student_grade, v_course_final_grade, NULL);
    167 END IF;
    168
    169
    170 -- End of year test for Course 1
    171
    172 IF v_counter <= v_students_test2 THEN
    173 INSERT INTO studentfacts
    174 VALUES(v_student_id, v_course1,'ACH2000',
    175 TO_DATE('01-JUN-2001','DD-MON-YYYY'),
    176 v_student_grade, v_course_final_grade, v_test_score);
    177 ELSE
    178 INSERT INTO studentfacts
    179 VALUES(v_student_id, v_course1, 'ACH2000',
    180 TO_DATE('01-JUN-2001','DD-MON-YYYY'),
    181 v_student_grade, v_course_final_grade, NULL);
    182 END IF;
    183
    184
    185 -- Beginning of year test for Course 2
    186
    187 IF v_counter <= v_students_test1 THEN
    188 INSERT INTO studentfacts
    189 VALUES(v_student_id, v_course2, 'ACH1999',
    190 TO_DATE('01-SEP-1999','DD-MON-YYYY'),
    191 v_student_grade, v_course_final_grade,
    192 v_test_score);
    193 ELSE
    194 INSERT INTO studentfacts
    195 VALUES(v_student_id, v_course2, 'ACH1999',
    196 TO_DATE('01-SEP-1999','DD-MON-YYYY'),
    197 v_student_grade, v_course_final_grade, NULL);
    198 END IF;
    199
    200
    201 -- End of year test for Course 2
    202
    203 IF v_counter <= v_students_test2 THEN
    204 INSERT INTO studentfacts
    205 VALUES(v_student_id, v_course2,'ACH2000',
    206 TO_DATE('01-JUN-2001''DD-MON-YYYY'),
    207 v_student_grade, v_course_final_grade,
    208 v_test_score);
    209 ELSE
    210 INSERT INTO studentfacts
    211 VALUES(v_student_id, v_course2, 'ACH2000',
    212 TO_DATE('01-JUN-2001','DD-MON-YYYY'),
    213 v_student_grade, v_course_final_grade, NULL);
    214 END IF;
    215
    216
    217 -- Beginning of year test for Course 3
    218
    219 IF v_counter <= v_students_test1 THEN
    220 INSERT INTO studentfacts
    221 VALUES(v_student_id, v_course3, 'ACH1999',
    222 TO_DATE('01-SEP-1999','DD-MON-YYYY'),
    223 v_student_grade, v_course_final_grade,
    224 v_test_score);
    225 ELSE
    226 INSERT INTO studentfacts
    227 VALUES(v_student_id, v_course3, 'ACH1999',
    228 TO_DATE('01-SEP-1999','DD-MON-YYYY'),
    229 v_student_grade, v_course_final_grade, NULL);
    230 END IF;
    231
    232
    233 -- End of year test for Course 3
    234
    235 IF v_counter <= v_students_test2 THEN
    236 INSERT INTO studentfacts
    237 VALUES(v_student_id, v_course3,'ACH2000',
    238 TO_DATE('01-JUN-2001','DD-MON-YYYY'),
    239 v_student_grade, v_course_final_grade,
    240 v_test_score);
    241 ELSE
    242 INSERT INTO studentfacts
    243 VALUES(v_student_id, v_course3, 'ACH2000',
    244 TO_DATE('01-JUN-2001','DD-MON-YYYY'),
    245 v_student_grade, v_course_final_grade, NULL);
    246 END IF;
    247
    248
    249 -- Beginning of year test for Course 4
    250
    251 IF v_counter <= v_students_test1 THEN
    252 INSERT INTO studentfacts
    253 VALUES(v_student_id, v_course4, 'ACH1999',
    254 TO_DATE('01-SEP-1999','DD-MON-Y YYY'),
    255 v_student_grade, v_course_final_grade,
    256 v_test_score);
    257 ELSE
    258 INSERT INTO studentfacts
    259 VALUES(v_student_id, v_course4, 'ACH1999',
    260 TO_DATE('01-SEP-1999','DD-MON-YYYY'),
    261 v_student_grade, v_course_final_grade, NULL);
    262 END IF;
    263
    264
    265 -- End of year test for Course 4
    266
    267 IF v_counter <= v_students_test2 THEN
    268 INSERT INTO studentfacts
    269 VALUES(v_student_id, v_course4,'ACH2000',
    270 TO_DATE('01-JUN-2001', 'DD-MON-YYYY'),
    271 v_student_grade, v_course_final_grade, v_test_score);
    272 ELSE
    273 INSERT INTO studentfacts
    274 VALUES(v_student_id, v_course4, 'ACH2000',
    275 TO_DATE('01-JUN-2001','DD-MON-YYYY'),
    276 v_student_grade, v_course_final_grade, NULL);
    277
    278 END IF;
    279 END LOOP;
    280 END add_tests;
    281 /
    Procedure created.
    SQL>
    SQL> show errors
    No errors.
    SQL>
    SQL> Input truncated to 9 characters
    spool off
    When I executed the main procedure, no data populated the student_table. I've tried several things, but I was not still able to populate the student_fact table (I've been at this for more than a week now, but haven't figured a way to populate the student_facts table with at least 1800 rows). Can you tell me what I need to change (if anything) whether if I need to structure things differently? I'm thinking that I missed something in calling the birth_date into the main procedure or returning the value from either a function or subprocedure. Related to the random final grade -- is there a way to sum the totals of the test scores (each student will have three), and generate a final grade from these values.
    I also compiled successfully a package containing this same information, but don't know how to execute it to see whether this approach works.
    Many thanks to anyone who can help.
    null

    ldsw,
    I am not sure if I totally understand everything that you are trying to do, but I tried to clean up your code and what is listed below is what I came up with. Please see if you can make use of any of it.
    SQL> EDIT ldsw
    CREATE OR REPLACE PACKAGE ldsw
    AS
    CURSOR grade_cur
    IS
    SELECT birth_date
    FROM students;
    PROCEDURE delete_test_info;
    FUNCTION get_grade
    (v_birth_date IN DATE)
    RETURN NUMBER;
    PRAGMA RESTRICT_REFERENCES (get_grade, WNDS, WNPS, RNDS, RNPS);
    PROCEDURE add_tests;
    END ldsw;
    CREATE OR REPLACE PACKAGE BODY ldsw
    AS
    v_student_grade NUMBER (1) := 0;
    PROCEDURE delete_test_info
    IS
    BEGIN
    DELETE FROM studentfacts;
    END delete_test_info;
    FUNCTION get_grade
    (v_birth_date IN DATE)
    RETURN NUMBER
    IS
    v_school_grade NUMBER (1) := 0;
    BEGIN
    IF v_birth_date < TO_DATE ('01-Jan-1987', 'DD-Mon-YYYY')
    THEN
    v_school_grade := 9;
    ELSIF v_birth_date BETWEEN TO_DATE ('01-Jan-1987', 'DD-Mon-YYYY') AND TO_DATE ('31-Dec-1987', 'DD-Mon-YYYY')
    THEN
    v_school_grade := 8;
    ELSIF v_birth_date BETWEEN TO_DATE ('01-Jan-1988', 'DD-Mon-YYYY') AND TO_DATE ('31-Dec-1988', 'DD-Mon-YYYY')
    THEN
    v_school_grade := 7;
    ELSIF v_birth_date BETWEEN TO_DATE ('01-Jan-1989', 'DD-Mon-YYYY') AND TO_DATE ('31-Dec-1989', 'DD-Mon-YYYY')
    THEN
    v_school_grade := 6;
    ELSIF v_birth_date > TO_DATE ('31-Dec-1989', 'DD-Mon-YYYY')
    THEN
    v_school_grade := 5;
    END IF;
    RETURN v_school_grade;
    END get_grade;
    PROCEDURE add_tests
    IS
    v_num_students CONSTANT NUMBER (3) := 300;
    v_students_test1 NUMBER := 0;
    v_students_test2 NUMBER := 0;
    v_counter NUMBER (3) := 0;
    v_student_id VARCHAR2 (5);
    v_test_score NUMBER (3) := 0;
    v_course_final_grade NUMBER (1) := 0;
    v_course1 VARCHAR2 (2) := NULL;
    v_course2 VARCHAR2 (2) := NULL;
    v_course3 VARCHAR2 (2) := NULL;
    v_course4 VARCHAR2 (2) := NULL;
    BEGIN
    ldsw.delete_test_info;
    v_students_test1 := v_num_students * .95;
    v_students_test2 := v_students_test1 * .80;
    FOR rec IN grade_cur
    LOOP
    v_counter := v_counter + 1;
    IF v_counter <= v_num_students
    THEN
    v_student_id := 'S' &#0124; &#0124; TO_CHAR (v_counter);
    v_test_score := random.rand_max (80) + 20;
    v_course_final_grade := random.rand_max (4);
    IF v_counter < ROUND (v_num_students * .20)
    THEN
    v_course1 := 'C1';
    v_course2 := 'C2';
    v_course3 := 'C3';
    ELSIF v_counter BETWEEN ROUND (v_num_students * .20) AND ROUND (v_num_students * .40)
    THEN
    v_course1 := 'C2';
    v_course2 := 'C1';
    v_course3 := 'C3';
    ELSIF v_counter BETWEEN ROUND (v_num_students * .40) AND ROUND (v_num_students * .60)
    THEN
    v_course1 := 'C3';
    v_course2 := 'C1';
    v_course3 := 'C2';
    ELSIF v_counter BETWEEN ROUND (v_num_students * .60) AND ROUND (v_num_students * .80)
    THEN
    v_course1 := 'C3';
    v_course2 := 'C1';
    v_course3 := 'C2';
    ELSE
    v_course1 := 'C4';
    v_course2 := 'C2';
    v_course3 := 'C3';
    END IF;
    SELECT ldsw.get_grade (rec.birth_date)
    INTO v_student_grade
    FROM DUAL;
    IF v_counter <= v_students_test1
    THEN
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course1,
    'ACH1999',
    TO_DATE ('01-SEP-1999', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    v_test_score);
    ELSE
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course1,
    'ACH1999',
    TO_DATE ('01-SEP-1999', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    NULL);
    END IF;
    IF v_counter <= v_students_test2
    THEN
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course1,
    'ACH2000',
    TO_DATE ('01-JUN-2001', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    v_test_score);
    ELSE
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course1,
    'ACH2000',
    TO_DATE ('01-JUN-2001', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    NULL);
    END IF;
    IF v_counter <= v_students_test1
    THEN
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course2,
    'ACH1999',
    TO_DATE ('01-SEP-1999', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    v_test_score);
    ELSE
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course2,
    'ACH1999',
    TO_DATE ('01-SEP-1999', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    NULL);
    END IF;
    IF v_counter <= v_students_test2
    THEN
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course2,
    'ACH2000',
    TO_DATE ('01-JUN-2001', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    v_test_score);
    ELSE
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course2,
    'ACH2000',
    TO_DATE ('01-JUN-2001', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    NULL);
    END IF;
    IF v_counter <= v_students_test1
    THEN
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course3,
    'ACH1999',
    TO_DATE ('01-SEP-1999', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    v_test_score);
    ELSE
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course3,
    'ACH1999',
    TO_DATE ('01-SEP-1999', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    NULL);
    END IF;
    IF v_counter <= v_students_test2
    THEN
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course3,
    'ACH2000',
    TO_DATE ('01-JUN-2001', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    v_test_score);
    ELSE
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course3,
    'ACH2000',
    TO_DATE ('01-JUN-2001', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    NULL);
    END IF;
    IF v_counter <= v_students_test1
    THEN
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course4,
    'ACH1999',
    TO_DATE ('01-SEP-1999', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    v_test_score);
    ELSE
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course4,
    'ACH1999',
    TO_DATE ('01-SEP-1999', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    NULL);
    END IF;
    IF v_counter <= v_students_test2
    THEN
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course4,
    'ACH2000',
    TO_DATE ('01-JUN-2001', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    v_test_score);
    ELSE
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course4,
    'ACH2000',
    TO_DATE ('01-JUN-2001', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    NULL);
    END IF;
    END IF;
    END LOOP;
    END add_tests;
    END ldsw;
    Save the file.
    SQL> START ldsw
    Package created.
    Package body created.
    SQL> EXECUTE ldsw.add_tests
    PL/SQL procedure successfully completed.
    SQL> SELECT * FROM student_facts;
    null

  • Opening two cursors using open cursor with bulk collect on colections ..

    Is it possible to have the implementatiion of using bulk collect with collections using two open cursors ..
    first c1
    second c2
    open c1
    loop
    open c2
    loop
    end loop
    close c2
    end loop;
    close c1
    what i found is for every outer loop of cursor c1 , cursor c2 is open and closed for every record.
    is this willl imporove the performace .?
    EXAMPLE:-
    NOTE: The relatoin between finc and minc is one to many ..finc is parent and minc is child
    function chk_notnull_blank ( colname IN number ) return number is
    BEGIN
    if ( colname is NOT NULL and colname not in ( -8E14, -7E14, -6E14, -5E14, -4E14, -3E14, -2E14, -1E14, -1E9 )) then
    RETURN colname ;
    else
    RETURN 0;
    end if;
    END chk_notnull_blank;
    procedure Proc_AnnualFmlyTotIncSummary is
    CURSOR c_cur_finc IS SELECT FAMID FROM FINC ;
    CURSOR c_cur_minc IS SELECT FAMID, MEMBNO , ANFEDTX, ANGOVRTX, ANPRVPNX, ANRRDEDX, ANSLTX, SALARYX, SALARYBX, NONFARMX, NONFRMBX , FARMINCX, FRMINCBX, RRRETIRX, RRRETRBX, SOCRRX, INDRETX, JSSDEDX, SSIX, SSIBX from MINC minc WHERE FAMID IN ( SELECT FAMID FROM FINC finc WHERE minc.FAMID = finc.FAMID );
    v_tot_fsalaryx number := 0;
    v_tot_fnonfrmx number := 0;
    v_tot_ffrmincx number := 0;
    v_tot_frretirx number := 0;
    v_tot_findretx number := 0;
    v_tot_fjssdedx number := 0;
    v_tot_fssix number := 0;
    v_temp_sum_fsalaryx number := 0;
    v_temp_sum_fnonfrmx number := 0;
    v_temp_sum_ffrmincx number := 0;
    v_temp_sum_frretirx number := 0;
    v_temp_sum_findretx number := 0;
    v_temp_sum_fjssdedx number := 0;
    v_temp_sum_fssix number := 0;
    TYPE minc_rec IS RECORD (FAMID MINC.FAMID%TYPE, MEMBNO MINC.MEMBNO%TYPE , ANFEDTX MINC.ANFEDTX%TYPE, ANGOVRTX MINC.ANGOVRTX%TYPE , ANPRVPNX MINC.ANPRVPNX%TYPE , ANRRDEDX MINC.ANRRDEDX%TYPE , ANSLTX MINC.ANSLTX%TYPE, SALARYX MINC.SALARYX%TYPE , SALARYBX MINC.SALARYBX%TYPE , NONFARMX MINC.NONFARMX%TYPE , NONFRMBX MINC.NONFRMBX%TYPE, FARMINCX MINC.FARMINCX%TYPE , FRMINCBX MINC.FRMINCBX%TYPE , RRRETIRX MINC.RRRETIRX%TYPE , RRRETRBX MINC.RRRETRBX%TYPE, SOCRRX MINC.SOCRRX%TYPE , INDRETX MINC.INDRETX%TYPE , JSSDEDX MINC.JSSDEDX%TYPE , SSIX MINC.SSIX%TYPE , SSIBX MINC.SSIBX%TYPE );
    v_flag_boolean boolean := false;
    v_famid number ;
    v_stmt varchar2(3200) ;
    v_limit number := 50;
    v_temp_FAMTFEDX number := 0 ;
    v_temp_FGOVRETX number := 0 ;
    v_temp_FPRIVPENX number := 0 ;
    v_temp_FRRDEDX number := 0 ;
    v_temp_FSLTAXX number := 0 ;
    v_temp_FSALARYX number := 0 ;
    v_temp_FNONFRMX number := 0 ;
    v_temp_FFRMINCX number := 0 ;
    v_temp_FRRETIRX number := 0 ;
    v_temp_FINDRETX number := 0 ;
    v_temp_FJSSDEDX number := 0 ;
    v_temp_FSSIX number := 0 ;
    BEGIN
    OPEN c_cur_finc ;
    LOOP
         FETCH c_cur_finc BULK COLLECT INTO famid_type_tbl LIMIT v_limit;
         EXIT WHEN famid_type_tbl.COUNT = 0;
         FOR i in famid_type_tbl.FIRST..famid_type_tbl.LAST
         LOOP
         OPEN c_cur_minc ;
         LOOP
         FETCH c_cur_minc BULK COLLECT INTO minc_rec_type_tbl LIMIT v_limit;
         EXIT WHEN minc_rec_type_tbl.COUNT = 0;
              FOR j IN minc_rec_type_tbl.FIRST..minc_rec_type_tbl.LAST
              LOOP
              if ( famid_type_tbl(i) = minc_rec_type_tbl(j).FAMID ) THEN
              v_temp_FAMTFEDX := v_temp_FAMTFEDX + chk_notnull_blank(minc_rec_type_tbl(j).ANFEDTX );
              v_temp_FGOVRETX := v_temp_FGOVRETX + chk_notnull_blank(minc_rec_type_tbl(j).ANGOVRTX);
              v_temp_FPRIPENX := v_temp_FPRIPENX + chk_notnull_blank(minc_rec_type_tbl(j).ANPRVPNX);
              v_temp_FRRDEDX := v_temp_FRRDEDX + chk_notnull_blank(minc_rec_type_tbl(j).ANRRDEDX);
              v_temp_FSLTAXX := v_temp_FSLTAXX + chk_notnull_blank(minc_rec_type_tbl(j).ANSLTX );
              v_temp_FSALARYX := v_temp_FSALARYX + chk_notnull_blank(minc_rec_type_tbl(j).SALARYX ) + chk_notnull_blank(minc_rec_type_tbl(j).SALARYBX);
              v_temp_FNONFRMX := v_temp_FNONFRMX + chk_notnull_blank(minc_rec_type_tbl(j).NONFARMX) + chk_notnull_blank(minc_rec_type_tbl(j).NONFRMBX);
              v_temp_FFRMINCX := v_temp_FFRMINCX + chk_notnull_blank(minc_rec_type_tbl(j).FARMINCX) + chk_notnull_blank(minc_rec_type_tbl(j).FRMINCBX );
              v_temp_FRRETIRX := v_temp_FRRETIRX + chk_notnull_blank(minc_rec_type_tbl(j).RRRETIRX) + chk_notnull_blank(minc_rec_type_tbl(j).RRRETRBX ) + chk_notnull_blank(minc_rec_type_tbl(j).SOCRRX);
              v_temp_FINDREXT := v_temp_FINDRETX + chk_notnull_blank(minc_rec_type_tbl(j).INDRETX);
              v_temp_FJSSDEDX := v_temp_FJSSDEDX + chk_notnull_blank(minc_rec_type_tbl(j).JSSDEDX);
              v_temp_FSSIX := v_temp_FSSIX + chk_notnull_blank(minc_rec_type_tbl(j).SSIX ) + chk_notnull_blank(minc_rec_type_tbl(j).SSIBX);
              END IF;
              END LOOP;
         END LOOP ;
         CLOSE c_cur_minc;
         UPDATE FINC SET FAMTFEDX = v_temp_FAMTFEDX WHERE FAMID = famid_type_tbl(i);
         END LOOP;
    END LOOP;
    CLOSE c_cur_finc;
    END;
    EXCEPTION
    WHEN OTHERS THEN
    raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
    v_err_code := SQLCODE;
    v_err_msg := substr(SQLERRM, 1, 200);
    INSERT INTO audit_table (error_number, error_message) VALUES (v_err_code, v_err_msg);
    error_logging(p_error_code => substr(sqlerrm,1,9), p_error_message => substr(sqlerrm,12), p_package =>'PKG_FCI_APP',p_procedure => 'Proc_Annual_Deductions_FromPay ' , p_location => v_location);
    end Proc_AnnualFmlyTotIncSummary ;
    Is the proga efficient and free from compilation errors ..?
    thanks/kumar
    Edited by: kumar73 on Sep 22, 2010 12:48 PM

    function chk_notnull_blank ( colname IN number ) return number is Maybe this function should have its own forum:
    how to use case in this program
    Re: how to declare a formal parameter in a function of type record and access ?
    Re: how to define a function with table type parameter
    Re: creation of db trigger with error ..
    Re: How to write a trigger for the below scenario
    how to improve the code using advanced methods
    yours advice in improving the coding ..
    How to use bulk in multiple cursors !!
    ;-)

Maybe you are looking for

  • Deployed BP for retail store and inventory management

    Hi, I have installed BP for retail which gives me the pages of store and inventory management but the iViews are not opening even after assignig the roles to the users. I have created the system alias SAP_ECC_RETAIL but still no luck. Please help. Th

  • How to access and control a Windows 7 computer from a Mac - long distance?

    I bought my parents their very first computer. They are 2000 miles away in another state. Currently I have the computer in my possession to "set-up" everything so it is as seamless as possible when they receive it. It is an HP with Windows 7. I have

  • IPhoto5 to iPhoto6 question

    I tried searching the threads here but haven't seen an answer to my specific question. Apologies if this has been already answered... Had my old PowerMac (running iPhoto5) die recently (hard drive survived) and I upgraded to the MacPro (now running i

  • Discover deskto 10g  ,Calculation problem

    Dear All in very short,i have one worksheet with 3 columns,shop name,gross sales,and discount i made total field to display sum of gross sale and discount.i also created one calculation to display discount amount in percent % of gross sale.but i dont

  • Show a message if the search result is 0

    Hi all, I have html jspbean , html for enter , jsp for display, bean for business. i want to handle if the search is not match display a message. i not how to handle in servlet just is whiler(rs.next(){ count ++ if (count<=1) display message. but how