Loop cursor question

Hi all...
Really stuck here. So, I have two tables.... one is passenger info, the other is flight info. The passengers have id numbers. When I enter a correct passenger num and flight num my program works fine. What Im trying to do is cause an error to appear if I enter an invalid flight or passenger number. I have a cursor set up for flight and one set up for passenger. I believe my error may be in the fetch? Can someone take a look?
Thanks in advance
CURSOR pass_cursor IS
SELECT pnum, name, age FROM passengers
WHERE pnum=V_pnum;
CURSOR flights_cursor IS
SELECT flnum, dest, hours, cost FROM flights
WHERE flnum=v_flnum;
OPEN pass_cursor;
LOOP
FETCH pass_cursor INTO v_pnum, v_name, v_age;
EXIT WHEN pass_cursor%NOTFOUND;
IF flights_cursor%ISOPEN THEN
CLOSE flights_cursor;
END IF;
OPEN flights_cursor;
LOOP
FETCH flights_cursor INTO v_flnum,v_dest,v_hours,v_cost;
EXIT WHEN flights_cursor%NOTFOUND;

You don't need to loop through the cursors if you just need a validation on primary or unique keys.
DECLARE
CURSOR pass_cursor IS
SELECT pnum, name, age
   FROM passengers
WHERE pnum=V_pnum;
CURSOR flights_cursor IS
SELECT flnum, dest, hours, cost
   FROM flights
WHERE flnum=v_flnum;
-- <variable declaration>
BEGIN
OPEN pass_cursor;
FETCH pass_cursor INTO v_pnum, v_name, v_age;
IF pass_cursor%NOTFOUND THEN
DBMS_OUTPUT.PUT_LINE('Invalid passenger id entered');
CLOSE pass_cursor;
-- RAISE exception;
END IF;
CLOSE pass_cursor;
OPEN flights_cursor;
FETCH flights_cursor INTO v_flnum,v_dest,v_hours,v_cost;
IF flights_cursor%NOTFOUND THEN
DBMS_OUTPUT.PUT_LINE('Invalid flight id entered');
CLOSE flights_cursor;
--RAISE exception;
END IF;
CLOSE flights_cursor;
EXCEPTION
WHEN OTHERS THEN
-- Logic if any exception is raised 
END;

Similar Messages

  • FOR LOOP cursor that updates table A based on a value in table B

    Hi,
    I need a FOR LOOP cursor that scans and updates all pro-rata column in table EMPLOYEE(child) based on what pay classification all employees are on in the CLASSIFICATION(parent) table.
    DECLARE
    BEGIN
    IF employee.emp_type = 'FT' THEN
    UPDATE employee
    SET employee.pro_rata = ((classification.yearly_pay/52)*52)
    WHERE employee.empid = v_empid AND classification.class_id = employee.class_id;
    END IF;
    IF employee.emp_type = 'PT1' THEN
    UPDATE employee
    SET employee.pro_rata = ((classification.yearly_pay/39)*52)
    WHERE employee.empid = v_empid AND classification.class_id = employee.class_id;
    END IF;
    IF employee.emp_type = 'PT2' THEN
    UPDATE employee
    SET employee.pro_rata = ((classification.yearly_pay/21)*52)
    WHERE employee.empid = v_empid AND classification.class_id = employee.class_id;
    END IF;
    END;
    How do I create a cursor that cuts across these two table
    See tables and data
    CREATE TABLE CLASSIFICATION(
    CLASS_ID VARCHAR2(6) NOT NULL,
    CLASS_TYPE VARCHAR2(10),
    DESCRIPTION VARCHAR2(30) NOT NULL,
    YEARLY_PAY NUMBER(8),
    HOURLY_RATE NUMBER,
    WEEKDAY_OVER_TIME NUMBER,
    WEEKEND_OVER_TIME NUMBER,
    CONSTRAINT PK_CLASS_ID PRIMARY KEY (CLASS_ID));
    INSERT INTO CLASSIFICATION VALUES('PR1','PERMANENT','MANAGER',45000,'','',NULL);
    INSERT INTO CLASSIFICATION VALUES('PR2','PERMANENT','ADMIN ASSISTANT',22000,'',1.5,NULL);
    INSERT INTO CLASSIFICATION VALUES('PR3','PERMANENT','CONTROLLER',32000,'',1.5,NULL);
    INSERT INTO CLASSIFICATION VALUES('PR4','PERMANENT','CASH OFFICER',22000,'',1.5,NULL);
    INSERT INTO CLASSIFICATION VALUES('PR5','PERMANENT','CLEANERS',16000,'',1.5,NULL);
    INSERT INTO CLASSIFICATION VALUES('PR6','PERMANENT','ADMIN OFFICER',22000,'',1.5,NULL);
    INSERT INTO CLASSIFICATION VALUES('PR7','PERMANENT','WAREHOUSE ATTENDANT',20000,'',1.5,NULL);
    INSERT INTO CLASSIFICATION VALUES('PR8','PERMANENT','WINDOWS DRESSER',22000,'',1.5,NULL);
    INSERT INTO CLASSIFICATION VALUES('PR9','PERMANENT','DIRECTOR',60000,'','',NULL);
    INSERT INTO CLASSIFICATION VALUES('PR10','PERMANENT','DEPUTY DIRECTOR',52000,'','',NULL);
    INSERT INTO CLASSIFICATION VALUES('PR11','PERMANENT','SALES ASSISTANT',21000,'',1.5,NULL);
    INSERT INTO CLASSIFICATION VALUES('TEMP2','TEMP STAFF','ADMIN ASSISTANT','',16.50,'',NULL);
    INSERT INTO CLASSIFICATION VALUES('TEMP3','TEMP STAFF','CONTROLLER','',29.00,'',NULL);
    INSERT INTO CLASSIFICATION VALUES('TEMP4','TEMP STAFF','CASH OFFICER','',19.00,'',NULL);
    INSERT INTO CLASSIFICATION VALUES('TEMP5','TEMP STAFF','CLEANERS','',10.00,'',NULL);
    INSERT INTO CLASSIFICATION VALUES('TEMP6','TEMP STAFF','ADMIN OFFICER','',20.00,'',NULL);
    INSERT INTO CLASSIFICATION VALUES('TEMP7','TEMP STAFF','WAREHOUSE ATTENDANT','',18.00,'',NULL);
    INSERT INTO CLASSIFICATION VALUES('TEMP8','TEMP STAFF','WINDOWS DRESSER','',18.50,'',NULL);
    INSERT INTO CLASSIFICATION VALUES('TEMP11','TEMP STAFF','SALES ASSISTANT','',16.00,'',NULL);
    CREATE TABLE EMPLOYEE(
    EMPID NUMBER(5) NOT NULL,
    SURNAME VARCHAR2(30) NOT NULL,
    FNAME VARCHAR2(30) NOT NULL,
    GENDER CHAR(1) NOT NULL,
    DOB DATE NOT NULL,
    EMP_TYPE VARCHAR2(20) NOT NULL,
    ANNUAL_WEEKS_REQD NUMBER(2),
    PRO_RATA_WAGES NUMBER(7,2),
    HOLIDAY_ENTLMENT NUMBER(2),
    SICK_LEAVE_ENTLMENT NUMBER(2),
    HIRE_DATE DATE NOT NULL,
    END_DATE DATE,
    ACCNO NUMBER(8) NOT NULL,
    BANKNAME VARCHAR2(20) NOT NULL,
    BRANCH VARCHAR2(20) NOT NULL,
    ACCOUNTNAME VARCHAR2(20),
    CLASS_ID VARCHAR2(6),
    CONSTRAINT CK_HIRE_END CHECK (HIRE_DATE < END_DATE),
    CONSTRAINT CK_HIRE_DOB CHECK (HIRE_DATE >= ADD_MONTHS(DOB, 12 * 18)),
    CONSTRAINT CK_EMP_TYPE CHECK (EMP_TYPE IN ('FT','PT1','PT2','PT3','HOURLY')),
    CONSTRAINT CK_EMP_GENDER CHECK (GENDER IN ('M','F')),
    CONSTRAINT FK_EMP_CLASS FOREIGN KEY (CLASS_ID) REFERENCES CLASSIFICATION(CLASS_ID),
    CONSTRAINT PK_EMP PRIMARY KEY (EMPID));
    CREATE SEQUENCE SEQ_EMPID START WITH 1;
    INSERT INTO EMPLOYEE VALUES(
    SEQ_EMPID.NEXTVAL,'RICHARD','BRANDON','M','25-DEC-1966','FT',52,22000.00,28,14,'10-JAN-2005',NULL,90823227,'NATWEST','BROMLEY','DEPOSIT','PR2');
    INSERT INTO EMPLOYEE VALUES(
    SEQ_EMPID.NEXTVAL,'BOYCE','CODD','M','15-JAN-1972','PT1','','','','','12-JAN-2005',NULL,72444091,'LLOYDS','KENT','CURRENT','PR8');
    INSERT INTO EMPLOYEE VALUES(
    SEQ_EMPID.NEXTVAL,'ALHAJA','BROWN','F','20-MAY-1970','HOURLY','','','','','21-JUN-2000',NULL,09081900,'ABBEY','ESSEX','CURRENT','TEMP2');
    INSERT INTO EMPLOYEE VALUES(
    SEQ_EMPID.NEXTVAL,'RON','ATKINSON','M','10-AUG-1955','PT3','','','','','12-JAN-2005','26-MAR-2006',01009921,'HALIFAX','KENT','SAVINGS','PR6');
    INSERT INTO EMPLOYEE VALUES(
    SEQ_EMPID.NEXTVAL,'CHAMPI','KANE','F','01-JAN-1965','PT2','','','','','12-JAN-2004',NULL,98120989,'HSBC','ILFORD','CURRENT','PR4');
    INSERT INTO EMPLOYEE VALUES(
    SEQ_EMPID.NEXTVAL,'NED','VED','M','15-JAN-1980','HOURLY','','','','','29-DEC-2005',NULL,90812300,'WOOLWICH','LEWISHAM','CURRENT','TEMP6');
    INSERT INTO EMPLOYEE VALUES(
    SEQ_EMPID.NEXTVAL,'JILL','SANDER','F','22-MAR-1971','FT','','','','','30-NOV-2003',NULL,23230099,'BARCLAYS','PENGE','DEPOSIT','PR1');
    Any contribution would be appreciated
    many thanks
    Cube60

    Hi,
    I have triede this cursor procedure but I get an compilation error.
    See first post for tables and data..
    Can someone help me out please.
    SQL> CREATE OR REPLACE PROCEDURE update_employee(
    2 p_empid employee.empid%type,
    3 p_emp_type employee.emp_type%type)
    4 IS
    5 CURSOR c1 is
    6 select e.empid, e.emp_type, c.yearly_pay from employee e, classification c where
    7 c.class_id = e.class_id;
    8 BEGIN
    9 OPEN c1
    10 LOOP
    11 FETCH c1 INTO p_empid, p_emp_type;
    12 exit when c1%notfound;
    13
    14 IF v_emp_type ='PT1' THEN
    15 UPDATE employee SET annual_weeks_reqd = 39, pro_rata_wages = ((v_yearly_pay/52)*39), holiday_en
    tlment=21, sick_leave_entlment = 10.5 WHERE c.class_id = e.class_id;
    16 END IF;
    17 END;
    18 /
    Warning: Procedure created with compilation errors.
    SQL> SHOW ERR;
    Errors for PROCEDURE UPDATE_EMPLOYEE:
    LINE/COL ERROR
    10/1 PLS-00103: Encountered the symbol "LOOP" when expecting one of
    the following:
    . ( % ; for
    The symbol "; was inserted before "LOOP" to continue.
    Many thanks

  • How to get last Record ior Total rows in For Loop Cursor ?

    Hi Friends
    I would like to know , the last record in for loop cursor, i have the code in following format
    cursor c1 is
    select * from emp;
    begin
    for r1 in c1 loop
    v_total_rec := ? ( i would like to know total rows in the cursor , say for example if cursor has 10 rows, i want10 into this variable )
    v_count := v_count +1;
    dbms_output.put_line(r1.emp_name);
    end loop;
    end;
    Hope i am clear
    Any suggestions?
    Thanks
    Ravi

    Even though cursor loops are generally a Bad Idea ^tm^ as Dan says, here's an example of how you can get the information you wanted within the query itself...
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    cursor c1 is
      3      select emp.*
      4            ,count(*) over (order by empno) as cnt
      5            ,count(*) over () as total_cnt
      6      from emp
      7      order by empno;
      8  begin
      9    for r1 in c1 loop
    10      dbms_output.put_line(r1.ename||' - row: '||r1.cnt||' of '||r1.total_cnt);
    11    end loop;
    12* end;
    SQL> /
    SMITH - row: 1 of 14
    ALLEN - row: 2 of 14
    WARD - row: 3 of 14
    JONES - row: 4 of 14
    MARTIN - row: 5 of 14
    BLAKE - row: 6 of 14
    CLARK - row: 7 of 14
    SCOTT - row: 8 of 14
    KING - row: 9 of 14
    TURNER - row: 10 of 14
    ADAMS - row: 11 of 14
    JAMES - row: 12 of 14
    FORD - row: 13 of 14
    MILLER - row: 14 of 14
    PL/SQL procedure successfully completed.
    SQL>

  • Process having dynamic subqery in for loop cursor

    I created a process that puts all retrieved rows into a collection. Users can select on quite a few columns, say unit, last_name, shift, etc. When the query is built based on users' inputs, I can't get it working using a For Loop Cursor (code 3.). But I tried and found out that sample 1 is working while sample 2 is not.
    Can anyone please help? give advices or point to the right direction?
    Thanks very much in advance!!!
    DC
    sample 1, works:
    begin
    :P8_TEST_CURSOR := '';
    for c in ( select ename from emp ) loop
    :P8_TEST_CURSOR := :P8_TEST_CURSOR || ', ' || c.ename;
    end loop;
    end;
    sample 2, does not work:
    declare
    q varchar2(2000) := 'select ename from emp';
    begin
    :P8_TEST_CURSOR := '';
    for c in q loop
    :P8_TEST_CURSOR := :P8_TEST_CURSOR || ', ' || c.ename;
    end loop;
    end;
    code 3, my actually pursuing code, sorry it's long:
    declare
    q varchar2(2000);
    v_unit_id cpd_units.id%TYPE;
    begin
    q := 'select distinct e.user_id
    , nvl(to_char(law_common.get_star_no(e.id)), ''-'') star_no
    , nvl(e.last_nme, ''-'') last_name
    , nvl(e.first_nme, ''-'') first_name
    , nvl(e.MIDDLE_INITIAL, ''-'') middle_initial
    , e.employee_no
    , nvl(to_char(e.employee_position_cd), ''-'')
    , nvl(w.uod_cd, e.cpd_unit_assigned_no) unit
    , nvl(w.watch_cd, ''-'')
    from cpd_employees e, dpv2wtch w
    where e.status_i = ''Y''
    and nvl(e.resignation_date, sysdate) >= sysdate
    and e.employee_position_cd in (''9112'', ''9152'', ''9153'', ''9155'', ''9161'', ''9164'')
    and e.user_id is not null
    and w.ssn_no(+) = e.ssn
    and e.user_id not in (select c001
    from htmldb_collections
    where collection_name = ''ACTIVITY''
    if :P300_STAR_NO is not NULL then
    q := q || ' and e.id = law_common.get_employee_id(:P300_STAR_NO)';
    --q := q || ' and law_common.get_star_no(e.id) = :P300_STAR_NO';
    end if;
    if :P300_EMPLOYEE_NO is not NULL then
    q := q || ' and e.employee_no = :P300_EMPLOYEE_NO';
    end if;
    if :P300_USER_ID is not NULL then
    q := q || ' and e.user_id = :P300_USER_ID';
    end if;
    if :P300_LAST_NAME is not NULL then
    q := q || ' and upper(e.last_nme) like ''' || upper(:P300_LAST_NAME) || '%''';
    end if;
    if :P300_FIRST_NAME is not NULL then
    q := q || ' and upper(e.first_nme) like ''' || upper(:P300_FIRST_NAME) || '%''';
    end if;
    if :P300_EMPLOYEE_POSITION_CD is not NULL then
    q := q || ' and e.employee_position_cd = :P300_EMPLOYEE_POSITION_CD';
    end if;
    if :P300_UNIT is not NULL then
    q := q || ' and nvl(w.uod_cd, e.cpd_unit_assigned_no) = :P300_UNIT';
    end if;
    if :P300_WATCH_CD <> 'NULL' then
    q := q || ' and w.watch_cd = :P300_WATCH_CD';
    end if;
    --htp.p('Limit Unit '||:P0_LIMIT_UNIT);
    /* authorization of editing OWN, UNIT, or ALL recs */
    if substr(:P0_PERMISSION, 1, 5) = 'QUERY' then
    q := q || ' and e.user_id = v(''FLOW_USER'')';
    elsif substr(:P0_PERMISSION, -4, 4) = 'UNIT' then
    q := q || ' and coalesce(w.uod_cd, e.cpd_unit_assigned_no)= :P0_LIMIT_UNIT ';
    end if;
    htp.p('q: ' || q);
    cursor q_c is q;
    for c in ( q_c ) loop /* HOW CAN BE DYNAMIC ???? */
    l_seq_id := htmldb_collection.add_member(
    p_collection_name => 'OFFICER_ACTIVITY'
    , p_c001 => c.user_id
    , p_c002 => c.star_no
    , p_c003 => c.last_name
    , p_c004 => c.first_name
    , p_c005 => c.middle_initial
    , p_c006 => c.employee_no
    , p_c007 => c.employee_position_cd
    , p_c008 => c.unit
    , p_c009 => c.watch_cd
    , p_c050 => :P0_APP_USER
    end loop;
    end;

    Come back to solve my need. I get the working test process:
    declare
    type ty_cursor is ref cursor;
    my_cursor ty_cursor;
    my_rec emp%rowtype;
    l_num number := 7900;
    q varchar2(2000) ;
    l_using varchar2(200) := null;
    begin
    :P8_TEST_CURSOR := '';
    q := 'select * from emp';
    if :P8_ENAME is not null then
    q := q || ' where ename like :P8_ENAME';
    l_using := ':P8_ENAME';
    end if;
    if l_using is not null then
    open my_cursor for q using :P8_ENAME; --l_using;
    else
    open my_cursor for q;
    end if;
    loop
    fetch my_cursor into my_rec;
    exit when my_cursor%notfound;
    :P8_TEST_CURSOR := :P8_TEST_CURSOR || ', ' || my_rec.empno;
    end loop;
    end;
    But I need
    open my_cursor for q using l_using;
    to be working since my application has several searchable columns for users and I have to put users' input search into l_using. It does NOT work: q got 'select * from emp where ename like :P8_ENAME' and l_using got ':P8_ENAME' at "open ...." statement.
    How can I get this cursor opened dynamically?
    Thanks again!
    DC

  • CBO (optimizer) nest-loop join question

    OS: Red Hat Linux
    DB: 11gR1
    I have gotten two conflicting answers while reading books by Don Burleson and Dan Hotka. It has to do with the CBO and nested-joins:
    One says the CBO will choose the 'smaller' table as the driving table, the other states that the 'larger' table will be the driving table. And both stick by this philosophy as the preferred goal of any SQL Tuning -- that is, one states that the 'smaller' table should be the driving table. The other says the 'larger' table should be the driving table.
    I had always thought that the 'smaller' table should be the driving table. That in a nested loop the driving will not likely use an index even. Who is correct? (I am not going to say who said what, btw). :-)
    But I got to let one of them know they got a 'typo' ... :-)
    Thx.

    user601798 wrote:
    It is an over-simplistic scenario but, as I mentioned, if all other things are 'equal' -- which would include 'access time/work', then I think the small table as the driving table has the advantage.
    It is not possible for +"*all* other things to be equal"+. (my emphasis).
    If by +'access time/work'+ you mean the total is the same then it doesn't matter which table is first, the time/work is the same either way round.
    If you want to say that the +'access time/work'+ for acquiring the first rowsource is the same for both paths, and the +'access time/work'+ for acquiring related rows from the second table is the same FOR EACH DRIVING ROW, then the total +'access time/work'+ will be difference, and it would be better to start with the smaller table. (The example by Salman Qureshi above: Re: CBO (optimizer) nest-loop join question would apply.)
    On the other hand, and ignoring any idea of "all other things being equal", smaller tables tend to have smaller indexes, so if your smaller rowsource comes from a smaller table then acquiring those rows may be cheaper than acquiring rows from a larger table - which leads to the observation that (even with perfectly precise indexing):
    <ul>
    smaller number of rows * larger unit cost to find related rows
    </ul>
    may produce a larger value than
    <ul>
    larger number of rows * smaller unit cost to find related rows
    </ul>
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk
    A general reminder about "Forum Etiquette / Reward Points": http://forums.oracle.com/forums/ann.jspa?annID=718
    If you never mark your questions as answered people will eventually decide that it's not worth trying to answer you because they will never know whether or not their answer has been of any use, or whether you even bothered to read it.
    It is also important to mark answers that you thought helpful - again it lets other people know that you appreciate their help, but it also acts as a pointer for other people when they are researching the same question, moreover it means that when you mark a bad or wrong answer as helpful someone may be prompted to tell you (and the rest of the forum) what's so bad or wrong about the answer you found helpful.

  • Nested FOR cursor LOOPs, BASIC QUESTION

    Hello,
    I am trying to nest a For-loop using a cursor (see below), but the program is not entering the second (nested) for-loop. This program compiles fine, but during run-time, the nested loop does not execute. I'd rather not use FETCH statements and keep everything in place. I think the solution is rather trivial, but I'm new to PL/SQL. PLEASE HELP!!!!!
    cursor c1 is
    select coi_con_uid,coi_not_code,coi_closed_yn,coi_timestamp
    from s_coi_con_issue
    where coi_not_code = 'NOT107'
    and coi_timestamp <= v_aweekago
    and coi_closed_yn = 'N';
    cursor c2 is
         select tsk_uid
         from s_tsk_task
         where tsk_status in ('C')
         and tsk_tty_code = 'CONTAC'
         and tsk_date_end = '' FOR UPDATE;     
    BEGIN
    select to_date(sysdate - 7) into v_aweekago from dual;
    DBMS_OUTPUT.PUT_LINE('System date used is ' || v_aweekago);
    FOR coi_row in c1 LOOP
    v_tsk_cnt := 0;
    v_coi_row_cnt := v_coi_row_cnt + 1;
    v_con_uid := rtrim(to_char(coi_row.coi_con_uid));
    v_tsk_act_str := ('"CON_UID","' || v_con_uid || '"') ;
    DBMS_OUTPUT.PUT_LINE('COI_CON_UID: ' || v_con_uid);
    DBMS_OUTPUT.PUT_LINE('v_tsk_act_str: ' || v_tsk_act_str);
    -----The Program is not entering into this Loop
              FOR tsk_row in c2 LOOP
              v_update_cnt := v_update_cnt + 1;
                   update s_tsk_task
                   set tsk_status = 'A'
                   where tsk_uid = tsk_row.tsk_uid and
                   tsk_action_string = v_tsk_act_str;     
                   DBMS_OUTPUT.PUT_LINE('----Task updated');                         
              END LOOP;
    END LOOP;
    COMMIT;

    using your query on your cursor c2 when you execute it on sql*plus did it return any rows?
      select tsk_uid
        from s_tsk_task
       where tsk_status in ('C')
         and tsk_tty_code = 'CONTAC'
         and tsk_date_end = ''; if not it might have something to do with the predicates in your where clause
         and tsk_date_end = '';consider revising your c2 cursor select statement to something like:
    cursor c2 is
      select tsk_uid
        from s_tsk_task
       where tsk_status   = 'C'
         and tsk_tty_code = 'CONTAC'
         and tsk_date_end IS NULL
      FOR UPDATE;

  • SQL Statement as Loop - easy question?

    Am reading from S. Feuerstein's book:
    DECLARE
    CURSOR checked_out_cur IS
    SELECT pet_id, name, checkout_date
    FROM occupancy WHERE checkout_date IS NOT NULL;
    BEGIN
    FOR checked_out_rec IN checked_out_cur
    LOOP
    INSERT INTO occupancy_history (pet_id, name, checkout_date)
    VALUES (checked_out_rec.pet_id, checked_out_rec.name, checked_out_rec.checkout_date);
    My question is - where did checked_out_rec came from? Doesn't look like it's declared.
    Thanks,

    http://www.unix.org.ua/orelly/oracle/prog2/ch07_07.htm
    In fact the very next section begins,
    "This will work just fine. But do we really need to use a cursor FOR loop to accomplish this task?"
    (I think the above is from an earlier edition of the book, but later editions make the same point.)
    If you flip back a couple of pages there is whole section on the convenience of the implicit record declaration, along with the implicit open, fetch and close.

  • Adding loops and loops format question

    Hi, i've been facing difficulties adding loops into my GB. My problem is: "Loops do not appear in my loop browser nor the loop list from the silver loop bar above the browser".
    Yes, forgive me for asking this repeated question but after checking the help tutorial, my personal GB guide books, and even HangTime's FAQ, sadly, i still dont find any answers.
    Generally, the procedure is pretty simple from all the sources i've read. Simply drag the folder or loops into the browser and thats DONE right? I did exactly what it said but sigh...maybe there's something wrong with my Macbook?
    For your information, all the loops that i've been adding are loops from CDs coupled with FutureMusic and ComputerMusic magazines, so i believe the sources are pretty reliable i hope.
    As i was struggling to add the loops, this msg popped up for the first time; "Loops that are not in Apple format will not be added into GB"
    So, is the loop format the main cause of my problem?
    if yes, is there any way to convert the format? what is the procedure?
    ps: My current status is, some loops i added are in my browser while some dont although they exist in User/Library/Audio/AppleLoops/UserLoops.
    Thank you in advance.
    Peace

    So, is the loop format the main cause of my problem?
    likely.
    if yes, is there any way to convert the format? what is the procedure?
    apple's loop utility:
    http://www.bulletsandbones.com/GB/GBFAQ.html#looputility
    also note:
    http://www.bulletsandbones.com/GB/GBFAQ.html#missingloops

  • Logic Loop Copyright Question

    Hi all. My question is, are all of the loops provided in Logic, Garageband, or any of the Jampacks, free from copyright restrictions? Meaning when utilized for commercial purpose, do they need to be declared as samples, or is everything provided, basically up for grabs? Thanks!

    I thought this was quite clear:
    "2. Permitted License Uses and Restrictions.
    This License allows you to install and use one copy of the Apple Software on a single Apple-labeled computer at a time. You may use the Apple and third party audio loop content (“Audio Content”), contained in or otherwise included with the Apple Software, on a royalty-free basis, to create your own original soundtracks for your video and audio projects.
    You may broadcast and/or distribute your own soundtracks that were created using the Audio Content, however, individual samples, sound sets, or audio loops may not be commercially or otherwise distributed on a standalone basis, nor may they be repackaged in whole or in part as audio samples, sound libraries, sound effects or music beds."

  • Closed loop configuration question

    I have a motor(with encoder feedback) attached to a linear actuator(with end limit switches).
    The motor has a commercially bought servo drive for control. 
    The servo drive will accept either a step/direction (2 seperate TTL
    digital pulse train inputs) or an analog -10 to 10vdc input for
    control. 
    The purpose is to drive a linear actuator(continiously in and out) in
    closed loop operation utilizing a ( (SV) Setpoint variable)value from a
    file converted to a frequency to compare with an actual ( (PV) Position
    variable) measured frequency.
    I have created and experimented with individual vi's allows analog
    control and digital pulse train control (thankfully with the help of
    examples). 
    Before I pose my question, I would like to make the following
    observations:  It is my understanding that Closed loop control
    means that I dont need to know an exact position at which to drive, but
    constant comparision of PV and SV through PID applictation. 
    Without getting into any proprietery information I can say that the
    constant positioning of the linear actuator will produce a latency of 2
    to 3 seconds based on the time the actuator moves to a new position and
    when the PV will change.  While experimenting with the analog
    input, i noticed imediate response to motor velocity, but after the
    motor is stopped, position is not held in place.  However, while
    experimenting with the Digital pulse train input, I noticed that the
    servo drive can only accept one command at one time; if, halfway
    through a move, position error produces a response to move the linear
    actuator in the opposite or different direction, the origional move
    must finish first. 
    Can anyone recommend the proper configuration for the closed loop control i have described?
    If I can make the system work with the servo drive/motor I plan to use
    the simple (pci 6014) daq card with the Analog out, or utilize the
    digital out.
    If I cant get this to work, we do have a pxi with 7344 motion card(I
    would like to exhaust all efforts to use the PCI 6014 card).
    Depending on where I go from here, I planned to use the PID vi's for the loop control.
    Thanks,
    Wayne Hilburn

    Thanks for the reply
    Jochen.  I realize there is a built-in latency with windows but I
    think the I/O control would be ok.  A change in actuator position
    will not result in an immediate change in process variable;  Is
    there a way to measure the latency or is it calculated?  A
    satisfactory reaction time could be from 1 to 1.5 sec.
    Use of the PCI-6014 is to supply the control output to the servo
    drive/amp, and not to drive the motor itself.  As stated earlier,
    while using the 6014 board, I have the choice of digital or analog
    output.
    Currently I am at a point where I must choose which configuration,
    analog control or digital control(in the form of digital pulse train),
    (i am inserting from first message)
    While experimenting with the analog
    input, i noticed imediate response to motor velocity, but after the
    motor is stopped, position is not held in place.  However, while
    experimenting with the Digital pulse train input, I noticed that the
    servo drive can only accept one command at one time; if, halfway
    through a move, position error produces a response to move the linear
    actuator in the opposite or different direction, the origional move
    must finish first.  .
    I dont claim to understand all the limitations with the
    specific boards, however, i am using an approach that is showing me the
    characteristics(a couple are listed in the above paragraph)  of
    the hardware and software configurations.
    So I am really back to my origional question;  Which configuration
    would be better for closed loop control, analog or digital pulse train?
    Thanks,
    Wayne Hilburn

  • Need help with loop cursor

    Hi,
    I'm doing a data conversion and am fairly new to PL/SQL.
    I have a cursor and in the loop i have a select statement
    which returns ORA-01403(no data found). I need to skip this
    row in the cursor and continue with the next.
    BEGIN
    OPEN cur_fill_split;
    LOOP
    FETCH cur_fill_split into S_ASR,S_CLIENT_NO, S_DIRCODE, S_SPLIT_RATE, I_WAYS,
    S_BRANCH_NUMBER, S_BRANCH_NAME, S_DIV_NUMBER, S_DIV_NAME, S_ITEMCODE, S_LINE;
    EXIT WHEN cur_fill_split%NOTFOUND;
    select order_number INTO N_ORDER_NUMBER from order_header
    where cmr_number||client_number||dir_number = s_asr||s_client_no||s_dircode;
    SELECT SEQ INTO I_SEQ FROM ORDER_DETAIL
    WHERE ORDER_NUMBER = N_ORDER_NUMBER
    AND LINE_ORDER_NUMBER = TO_NUMBER(S_LINE);
    ********(errors on the above select)********
    END LOOP;
    CLOSE cur_fill_split;
    END;
    Thanks,
    Brian

    Hi,
    I think there r 2 methods, one is by giving begin - end inside the loop as shown below 1st ex:
    & the 2nd method is by selecting the record count & then based on that value executing further commands.
    I think 2nd method is more safer than the 1st method.
    Method 1:
    1)
    -- ---------------Procedure Begin------------------
    BEGIN
    OPEN cur_fill_split;
    LOOP
    FETCH cur_fill_split into S_ASR,S_CLIENT_NO, S_DIRCODE, S_SPLIT_RATE, I_WAYS,
    S_BRANCH_NUMBER, S_BRANCH_NAME, S_DIV_NUMBER, S_DIV_NAME, S_ITEMCODE, S_LINE;
    EXIT WHEN cur_fill_split%NOTFOUND;
    select order_number INTO N_ORDER_NUMBER from order_header
    where cmr_number||client_number||dir_number = s_asr||s_client_no||s_dircode;
    BEGIN
    SELECT SEQ INTO I_SEQ FROM ORDER_DETAIL
    WHERE ORDER_NUMBER = N_ORDER_NUMBER
    AND LINE_ORDER_NUMBER = TO_NUMBER(S_LINE);
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    NULL;
    END;
    END LOOP;
    CLOSE cur_fill_split;
    END;
    -- ---------------Procedure End------------------
    Method 2)
    By selecting the record count & based on that records, deciding the program control.
    -- ---------------Procedure Begin------------------
    declare
    rec_cnt number := 0;
    BEGIN
    OPEN cur_fill_split;
    LOOP
    FETCH cur_fill_split into S_ASR,S_CLIENT_NO, S_DIRCODE, S_SPLIT_RATE, I_WAYS,
    S_BRANCH_NUMBER, S_BRANCH_NAME, S_DIV_NUMBER, S_DIV_NAME, S_ITEMCODE, S_LINE;
    EXIT WHEN cur_fill_split%NOTFOUND;
    select order_number INTO N_ORDER_NUMBER from order_header
    where cmr_number||client_number||dir_number = s_asr||s_client_no||s_dircode;
    /* Here we are using cnt variable & checking for
    the record count, if count = 0, then it will skip */
    select count(*) into rec_cnt from ORDER_DETAIL
    WHERE ORDER_NUMBER = N_ORDER_NUMBER
    AND LINE_ORDER_NUMBER = TO_NUMBER(S_LINE);
    if rec_cnt > 0 then
    SELECT SEQ INTO I_SEQ FROM ORDER_DETAIL
    WHERE ORDER_NUMBER = N_ORDER_NUMBER
    AND LINE_ORDER_NUMBER = TO_NUMBER(S_LINE);
    end if;
    END LOOP;
    CLOSE cur_fill_split;
    END;
    -- ---------------Procedure End------------------
    Try it out & mail me
    Good luck

  • Cursor Question

    Hi
    I have a multi-tab form and in the first tab block (B1) one of the field's values is used to populate an NBT field in another multi-record tab block (B2). When tab B2 fields are filled in, the last value is populated automatically with the value from B1. I had thought that if the value in B1 is subsequently changed then I would like the form, in B2, to update the field(s) (if any) with the new value input in B1.
    DB relation is B1 parent, B2 child.
    I thought the best option would be to use a cursor to loop through the records in B2 when:
    B1 field's system record status is 'CHANGED'
    And PK(s) in B2 are present i.e. records are present and need updated.
    So i've not really get much experience using cursors so thought this would be ideal opportunity to learn it. I created the following cursor:
    IF :system.record_status = 'CHANGED' AND :B2.ID IS NOT NULL THEN
    DECLARE
         v_mod_id NUMBER := :B2.FK; --variable used for join condition in cursor
         v_cvs_val VARCHAR2(100) := :B1.UpdatedValue; Passes updated B1 value into variable so it can be used to update B2
         CURSOR c_cvs IS
    SELECT B2_PK, B2_current_val --Current value to be updated
         FROM B2 table
         WHERE B2_FK = v_mod_id;
         B2_Table_rec c_cvs%ROWTYPE; --declares record of cursor type
    BEGIN
         OPEN c_cvs;
         LOOP
              FETCH c_cvs INTO B2_Table_rec;
              EXIT WHEN c_cvs%NOTFOUND;
              :B2.field_requiring_B1updatedValue := v_cvs_val; Passes updated value into --each field in the block B2
         END LOOP;
         CLOSE c_cvs;
    END;
    END IF;
    What I am a bit confused about is what trigger to use this in. I have used it in when validate item in B1, so when I update value the cursor should go through the records in B2 to update them, and it does, but only does it once, and only does it to the record in B2 that I left focus in; so if I was on row 2 in B2 and went and changed value in B1 it would only update row 2 in B2.
    I would appreciate if anyone can offer any advice as to where i'm going wrong, either in the cursor statement itself or in what trigger I should put it.
    thanks
    Andrew

    http://asktom.oracle.com/pls/ask/f?p=4950:8:3983328209686210967::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:5241391331097
    Rgds.

  • Open cursors in loop (cursor name as a variable)

    Hi,
    I have such a problem:
    In my procedure I have declared 200 cursors.
    Now I want to open,fetch and close them one by one in Loop .
    I'm thinking about some array with all cursor's names.
    That is what I have (maybe stupid example but just to explain the issue) :
    DECLARE
    v_empno VARCHAR2(10);
    v_empname VARCHAR2(10);
    Cursor c1 IS
    SELECT '1' EMPNO,'Adam' EMPNAME
    FROM dual;
    Cursor c2 IS
    SELECT '2' EMPNO,'John' EMPNAME
    FROM dual;
    BEGIN
    OPEN c1;
    LOOP
    FETCH c1 INTO v_empno, v_empname;
    EXIT WHEN c1%NOTFOUND;
    dbms_output.put_line (v_empno||' '|| v_empname);
    END LOOP;
    CLOSE c1;
    OPEN c2;
    LOOP
    FETCH c2 INTO v_empno, v_empname;
    EXIT WHEN c2%NOTFOUND;
    dbms_output.put_line (v_empno||' '|| v_empname);
    END LOOP;
    CLOSE c2;
    END;
    And that is what I want to achieve:
    DECLARE
    v_empno VARCHAR2(10);
    v_empname VARCHAR2(10);
    TYPE cursors_tab IS TABLE OF VARCHAR(5);
    t_cursors cursors_tab := cursors_tab('c1','c2');
    Cursor c1 IS
    SELECT '1' EMPNO,'Adam' EMPNAME
    FROM dual;
    Cursor c2 IS
    SELECT '2' EMPNO,'John' EMPNAME
    FROM dual;
    BEGIN
    for i in t_cursors.first .. t_cursors.last loop
    OPEN :t_cursors(i);
    LOOP
    FETCH :t_cursors(i) INTO v_empno, v_empname;
    EXIT WHEN t_cursors(i)%NOTFOUND;
    dbms_output.put_line (v_empno||' '|| v_empname);
    END LOOP;
    CLOSE :t_cursors(i);
    end loop;
    END;
    Is that possible ?? I'm trying to solve it but I'm loosing hope ;)

    DECLARE
    v_empno VARCHAR2(10);
    v_empname VARCHAR2(10);
    TYPE stmt_tab IS TABLE OF VARCHAR(32767);
    t_stmt stmt_tab := stmt_tab(
                                'SELECT ''1'' EMPNO,''Adam'' EMPNAME FROM dual',
                                'SELECT ''2'' EMPNO,''John'' EMPNAME FROM dual'
    t_cur sys_refcursor;
    BEGIN
    for i in t_stmt.first .. t_stmt.last loop
    OPEN t_cur for t_stmt(i);
    LOOP
    FETCH t_cur INTO v_empno, v_empname;
    EXIT WHEN t_cur%NOTFOUND;
    dbms_output.put_line (v_empno||' '|| v_empname);
    END LOOP;
    CLOSE t_cur;
    end loop;
    END;
    1 Adam
    2 John
    PL/SQL procedure successfully completed.
    SQL> SY.

  • Loop Cursor Fetch Insert Rows Into Global Temporay Table

    Hi friends,
    I want to know there where is the problem in my this query
    cursor c1 is select empno
    from scott.emp;
    b number;
    begin
    open c1;
         loop
         fetch c1 into b;
         exit when c1%notfound;
    insert into scheema.a1
    (a)
    values
    (b);
    commit;
         end loop;
         close c1;
    end;
    There is no any error displaying while proceeding this query but the table a1 which is (Global temporary table with ON COMMIT PRESERVE ROWS option enabled) does not gets any records. Kindly let me know the problem.
    Regards.

    Are you sure that the query returns date? Are you checking the table via the same session?
    SQL> create global temporary table a1 (
      a  number)
      on commit preserve rows
    Table created.
    SQL> declare
       cursor c1 is select empno
          from scott.emp;
       b number;
    begin
       open c1;
       loop
          fetch c1 into b;
          exit when c1%notfound;
          insert into a1
          (a)
          values
          (b);
          commit;
       end loop;
       close c1;
    end;
    PL/SQL procedure successfully completed.
    SQL> select * from a1
             A
          7369
          7499
          7521
          7566
          7654
          7698
          7782
          7788
          7839
          7844
          7876
          7900
          7902
          7934
    14 rows selected.

  • Ref cursor question

    Hi,
    I have stored proc that takes pl/sql table as IN parameter and returns a ref cursor.
    Data from pl/sql table is separated into two table type objects ... oType1 and oType2 based on some condition.
    following works fine...
    If oType1.Count > 0 then
         OPEN list_out FOR
         select col1, col2, col3, col4 ..... col20
         from TABLE(CAST(oType1 AS obj_table_t)) a,
         t1,
         t2
         where a.colvalue = t1.colvalue
         and etc....
    UNION ALL
         select col1, col2, col3, col4 ..... col20
         from TABLE(CAST(oType1 AS obj_table_t)) a,
         t3,
         t4
         where a.colvalue = t3.colvalue
         and different conditions etc....
    I have 4 UNION ALL's. Had to use this because of different where coditions.
    end if..
    The problem is with oType2......
    If oType2.Count > 0 then
    -- getting data from different database using dblink along with values from present database.
    -- resultset columns will be same as above
    -- Question is how to send these results in same refcursor.
    end if;
    Thanks for your time.

    Hi,
    I think that a plsql table is what you want and not a ref cursor. If you have a plsql table based on your user defined type you can keep assigning all the values you want to it and then pass it out of your procedure.
    null

Maybe you are looking for