More on IF statements Use speaker notes for additional information!

Slides:



Advertisements
Similar presentations
Relational database - student system As always please use speaker notes!
Advertisements

Creating an Oracle Database Table Additional information is available in speaker notes!
PL/SQL User Defined Types Record and Table Please use speaker notes for additional information!
Reports Using SQL Script Please check speaker notes for additional information!
Order Entry System Please use speaker notes for additional information!
Line Efficiency     Percentage Month Today’s Date
Group functions using SQL Additional information in speaker notes!
Relational example using donor, donation and drive tables For additional information see the speaker notes!
Using input variables Please use speaker notes for additional information!
PL/SQL - Using IF statements Please use speaker notes for additional information!
Unit Number Oct 2011 Nov 2011 Dec 2011 Jan 2012 Feb 2012 Mar 2012 Apr 2012 May 2012 Jun 2012 Jul 2012 Aug 2012 Sep (3/4 Unit) 7 8 Units.
SQL Use of Functions Character functions Please use speaker notes for additional information!
SQL functions - numeric and date Speaker notes contain additional information!
Cursors in PL/SQL Includes cursor example and continuation of first cursor example Please use speaker notes for additional information!
More on variables with Oracle’s SQL*Plus As always, speaker notes will contain additional information!
XML, DTD, ENTITY Please see speaker notes for additional information!
XML and DTD Please you speaker notes for additional information!
Examples dealing with cursors and tables Please use speaker notes for additional information!
More on views Please refer to speaker notes for additional information!
SQL and Conditions Speaker notes will provide additional information!
Manipulating data within PL/SQL Please use speaker notes for additional information!
Functions Please use speaker notes for additional information!
Exceptions in PL/SQL Please use speaker notes for additional information!
Indexes in Oracle An Introduction Please check speaker notes for additional information!
Introduction to Oracle - SQL Additional information is available in speaker notes!
More on Primary and Foreign Keys Please see speaker notes for additional information!
Introduction to PL/SQL As usual, use speaker notes for additional information!
PHP with MYSQL Please use speaker notes for additional information!
More SQL functions As usual,there is additional information in the speaker notes!
Windows Server 2008 R2 Oct 2009 Windows Server 2003
Jan 2016 Solar Lunar Data.
Introduction to Triggers
More on Procedures (Internal/Local procedures)
Introduction to Procedures
Q1 Jan Feb Mar ENTER TEXT HERE Notes
MySQL - Creating donorof database offline

Project timeline # 3 Step # 3 is about x, y and z # 2
Average Monthly Temperature and Rainfall
Introduction to Functions
Please use speaker notes for additional information!
Mammoth Caves National Park, Kentucky
2017 Jan Sun Mon Tue Wed Thu Fri Sat
Introduction to Views and Reports

Gantt Chart Enter Year Here Activities Jan Feb Mar Apr May Jun Jul Aug
Q1 Q2 Q3 Q4 PRODUCT ROADMAP TITLE Roadmap Tagline MILESTONE MILESTONE
Free PPT Diagrams : ALLPPT.com
Proposed Strategic Planning Process for FY 2013/14 thru FY 2015/16

MONTH CYCLE BEGINS CYCLE ENDS DUE TO FINANCE JUL /2/2015
Jan Sun Mon Tue Wed Thu Fri Sat
Electricity Cost and Use – FY 2016 and FY 2017
More and Still More on Procedures and Functions
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Q1 Q2 Q3 Q4 PRODUCT ROADMAP TITLE Roadmap Tagline MILESTONE MILESTONE
Free PPT Diagrams : ALLPPT.com

Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Project timeline # 3 Step # 3 is about x, y and z # 2
TIMELINE NAME OF PROJECT Today 2016 Jan Feb Mar Apr May Jun
Q1 Q2 Q3 Q4 PRODUCT ROADMAP TITLE Roadmap Tagline MILESTONE MILESTONE
Presentation transcript:

More on IF statements Use speaker notes for additional information!

PL/SQL - IF BEGIN SELECT yrgoal, state INTO v_yrgoal, v_state FROM donornew WHERE idno = v_idno; IF v_state = 'MA' THEN IF v_yrgoal > 300 THEN v_newgoal := v_yrgoal * 1.3; ELSE IF v_yrgoal > 100 THEN v_newgoal := v_yrgoal * 1.2; ELSE v_newgoal := v_yrgoal * 1.1; END IF; ELSE IF v_state = 'RI' THEN IF v_yrgoal > 250 THEN v_newgoal := v_yrgoal * 1.25; ELSE v_newgoal := v_yrgoal * 1.15; END IF; ELSE v_newgoal := v_yrgoal; END IF; UPDATE donornew SET yrgoal = v_newgoal WHERE idno = v_idno; COMMIT; END; / SET VERIFY ON SET VERIFY OFF DECLARE v_idno VARCHAR2(5) :=&input_idno; v_yrgoal NUMBER(7,2); v_newgoal NUMBER(7,2); v_state VARCHAR2(2); This is the code for donor2 as it appears in the editor (shown in two columns for space considerations). This code uses a complex IF structure with IF statements embedded in other IF statements. The flowchart for the logic is shown on the next slide.

PL/SQL - IF v_state = MA v_yrgoal > 300 v_newgoal := v_yrgoal * 1.3 v_yrgoal > 100 v_newgoal := v_yrgoal * 1.2 v_newgoal := v_yrgoal * 1.1 v_state = RI v_yrgoal > 300 v_newgoal := v_yrgoal * 1.25 v_newgoal := v_yrgoal * 1.15 v_newgoal := v_yrgoal YN Y Y Y Y N N N N

SQL> SELECT * FROM donornew; IDNO NAME STADR CITY ST ZIP DATEFST YRGOAL CONTACT Stephen Daniels 123 Elm St Seekonk MA JUL John Smith Jennifer Ames 24 Benefit St Providence RI MAY Susan Jones Carl Hersey 24 Benefit St Providence RI JAN-98 Susan Jones Susan Ash 21 Main St Fall River MA MAR Amy Costa Nancy Taylor 26 Oak St Fall River MA MAR John Adams Robert Brooks 36 Pine St Fall River MA APR Amy Costa PL/SQL - IF donor2 Enter value for input_idno: PL/SQL procedure successfully completed. Input truncated to 13 characters SQL> SELECT * FROM donornew; IDNO NAME STADR CITY ST ZIP DATEFST YRGOAL CONTACT Stephen Daniels 123 Elm St Seekonk MA JUL John Smith Jennifer Ames 24 Benefit St Providence RI MAY Susan Jones Carl Hersey 24 Benefit St Providence RI JAN-98 Susan Jones Susan Ash 21 Main St Fall River MA MAR Amy Costa Nancy Taylor 26 Oak St Fall River MA MAR John Adams Robert Brooks 36 Pine St Fall River MA APR Amy Costa This is the segment of code that was executed to cause donor to increase from 440 to 550. IF v_state = 'RI' THEN IF v_yrgoal > 250 THEN v_newgoal := v_yrgoal * 1.25;

SET VERIFY OFF DECLARE v_pay_id first_pay_new.pay_id%TYPE :=&input_pay_id; v_salary first_pay_new.salary%TYPE; v_jobcode first_pay_new.jobcode%TYPE; v_bonus first_pay_new.bonus%TYPE; v_new_bonus first_pay_new.bonus%TYPE; BEGIN SELECT salary, jobcode, bonus INTO v_salary, v_jobcode, v_bonus FROM first_pay_new WHERE pay_id = v_pay_id; IF v_jobcode = 'CI' THEN IF v_salary > THEN v_new_bonus := v_bonus + 500; ELSE v_new_bonus := v_bonus + 250; END IF; ELSE IF v_jobcode = 'IN' THEN IF v_salary > THEN v_new_bonus := v_bonus + 250; ELSE IF v_salary > THEN v_new_bonus := v_bonus + 100; ELSE v_new_bonus := v_bonus + 50; END IF; ELSE IF v_jobcode = 'AP' THEN IF v_salary > THEN v_new_bonus := v_bonus + 100; END IF; IF v_new_bonus != v_bonus THEN UPDATE first_pay_new SET bonus = v_new_bonus WHERE pay_id = v_pay_id; END IF; END; / SET VERIFY ON PL/SQL - IF This is firstpay5. It is a series of embedded IF statements some with an ELSE and some without. NOTE that there is an IF before the update to see if a new bonus was calculated. If it was, then the update is done.

PL/SQL - IF IF v_new_bonus != v_bonus THEN UPDATE first_pay_new SET bonus = v_new_bonus WHERE pay_id = v_pay_id; END IF; END; / SET VERIFY ON SET VERIFY OFF DECLARE v_pay_id first_pay_new.pay_id%TYPE :=&input_pay_id; v_salary first_pay_new.salary%TYPE; v_jobcode first_pay_new.jobcode%TYPE; v_bonus first_pay_new.bonus%TYPE; v_new_bonus first_pay_new.bonus%TYPE; BEGIN SELECT salary, jobcode, bonus INTO v_salary, v_jobcode, v_bonus FROM first_pay_new WHERE pay_id = v_pay_id; IF v_jobcode = 'CI' THEN IF v_salary > THEN v_new_bonus := v_bonus + 500; ELSE v_new_bonus := v_bonus + 250; END IF; ELSE IF v_jobcode = 'IN' THEN IF v_salary > THEN v_new_bonus := v_bonus + 250; ELSE IF v_salary > THEN v_new_bonus := v_bonus + 100; ELSE v_new_bonus := v_bonus + 50; END IF; ELSE IF v_jobcode = 'AP' THEN IF v_salary > THEN v_new_bonus := v_bonus + 100; END IF;

PL/SQL - IF v_jobcode = CI v_salary > Increase bonus by 500 Increase bonus by 250 v_jobcode = IN v_salary > Increase bonus by 250 Increase bonus by 50 v_salary > Increase bonus by 100 v_jobcode = AP v_salary > Increase bonus by 100 Y Y Y Y Y Y Y N N N N N N N

SQL> SELECT * FROM first_pay_new; PAY_ NAME JO STARTDATE SALARY BONUS Linda Costa CI 15-JAN John Davidson IN 25-SEP Susan Ash AP 05-FEB Stephen York CM 03-JUL Richard Jones CI 30-OCT Joanne Brown IN 18-AUG Donald Brown CI 05-NOV Paula Adams IN 12-DEC firstpay5 Enter value for input_pay_id: 5555 PL/SQL procedure successfully completed. SQL> SELECT * FROM first_pay_new; PAY_ NAME JO STARTDATE SALARY BONUS Linda Costa CI 15-JAN John Davidson IN 25-SEP Susan Ash AP 05-FEB Stephen York CM 03-JUL Richard Jones CI 30-OCT Joanne Brown IN 18-AUG Donald Brown CI 05-NOV Paula Adams IN 12-DEC PL/SQL - IF This is the code that was executed to make the salary for employee 5555 increase by 500. IF v_jobcode = 'CI' THEN IF v_salary > THEN v_new_bonus := v_bonus + 500;

firstpay5 Enter value for input_pay_id: 7777 PL/SQL procedure successfully completed. SQL> SELECT * FROM first_pay_new; PAY_ NAME JO STARTDATE SALARY BONUS Linda Costa CI 15-JAN John Davidson IN 25-SEP Susan Ash AP 05-FEB Stephen York CM 03-JUL Richard Jones CI 30-OCT Joanne Brown IN 18-AUG Donald Brown CI 05-NOV Paula Adams IN 12-DEC firstpay5 Enter value for input_pay_id: 3333 PL/SQL procedure successfully completed. SQL> SELECT * FROM first_pay_new; PAY_ NAME JO STARTDATE SALARY BONUS Linda Costa CI 15-JAN John Davidson IN 25-SEP Susan Ash AP 05-FEB Stephen York CM 03-JUL Richard Jones CI 30-OCT Joanne Brown IN 18-AUG Donald Brown CI 05-NOV Paula Adams IN 12-DEC PL/SQL - IF Bonus was null so no activity. Bonus was increased by 100 because v_jobcode = AP and v_salary >

SET VERIFY OFF DECLARE v_idno VARCHAR2(5) :=&input_idno; v_yrgoal NUMBER(7,2); v_newgoal NUMBER(7,2); v_state VARCHAR2(2); BEGIN SELECT yrgoal, state INTO v_yrgoal, v_state FROM donornew WHERE idno = v_idno; IF v_yrgoal > 250 AND v_state = 'MA' THEN v_newgoal := v_yrgoal * 1.1 ; ELSE v_newgoal := v_yrgoal * 1.2; END IF; UPDATE donornew SET yrgoal = v_newgoal WHERE idno = v_idno; END; / SET VERIFY ON SQL> edit donor3 PL/SQL - IF This is an example of a compound AND.

PL/SQL - Compound AND v_yrgoal > 250 v_state = MA Increase goal by 10% Increase goal by 20% Y Y N N Increase goal by 20% IF v_yrgoal > 250 AND v_state = 'MA' THEN v_newgoal := v_yrgoal * 1.1; ELSE v_newgoal := v_yrgoal * 1.2; END IF;

SQL> SELECT * FROM donornew; IDNO NAME STADR CITY ST ZIP DATEFST YRGOAL CONTACT Stephen Daniels 123 Elm St Seekonk MA JUL John Smith Jennifer Ames 24 Benefit St Providence RI MAY Susan Jones Carl Hersey 24 Benefit St Providence RI JAN-98 Susan Jones Susan Ash 21 Main St Fall River MA MAR Amy Costa Nancy Taylor 26 Oak St Fall River MA MAR John Adams Robert Brooks 36 Pine St Fall River MA APR Amy Costa PL/SQL - Compound AND donor3 Enter value for input_idno: PL/SQL procedure successfully completed. SQL> SELECT * FROM donornew; IDNO NAME STADR CITY ST ZIP DATEFST YRGOAL CONTACT Stephen Daniels 123 Elm St Seekonk MA JUL John Smith Jennifer Ames 24 Benefit St Providence RI MAY Susan Jones Carl Hersey 24 Benefit St Providence RI JAN-98 Susan Jones Susan Ash 21 Main St Fall River MA MAR Amy Costa Nancy Taylor 26 Oak St Fall River MA MAR John Adams Robert Brooks 36 Pine St Fall River MA APR Amy Costa IF v_yrgoal > 250 AND v_state = 'MA' THEN v_newgoal := v_yrgoal * 1.1; ELSE v_newgoal := v_yrgoal * 1.2; END IF; Since goal was not greater than 250 the ELSE was executed and the goal was increased by 20%. Before After

PL/SQL - Compound AND SET VERIFY OFF DECLARE v_pay_id first_pay_new.pay_id%TYPE :=&input_pay_id; v_new_sal first_pay_new.salary%TYPE; v_jobcode first_pay_new.jobcode%TYPE; v_bonus first_pay_new.bonus%TYPE; BEGIN SELECT salary, jobcode, bonus INTO v_new_sal, v_jobcode, v_bonus FROM first_pay_new WHERE pay_id = v_pay_id; IF v_jobcode = 'CI' AND v_bonus > 1000 THEN v_new_sal := v_new_sal * 1.05; ELSE v_new_sal := v_new_sal * 1.02; END IF; UPDATE first_pay_new SET salary = v_new_sal WHERE pay_id = v_pay_id; END; / SET VERIFY ON SQL> edit firstpay6

v_jobcode=CI v_bonus > 1000 Increase salary by 5% Increase salary by 2% Y Y N N Increase salary by 2% PL/SQL - Compound AND IF v_jobcode = 'CI' AND v_bonus > 1000 THEN v_new_sal := v_new_sal * 1.05; ELSE v_new_sal := v_new_sal * 1.02; END IF;

SQL> SELECT * FROM first_pay_new; PAY_ NAME JO STARTDATE SALARY BONUS Linda Costa CI 15-JAN John Davidson IN 25-SEP Susan Ash AP 05-FEB Stephen York CM 03-JUL Richard Jones CI 30-OCT Joanne Brown IN 18-AUG Donald Brown CI 05-NOV Paula Adams IN 12-DEC PL/SQL - Compound AND firstpay6 Enter value for input_pay_id: 5555 PL/SQL procedure successfully completed. SQL> SELECT * FROM first_pay_new; PAY_ NAME JO STARTDATE SALARY BONUS Linda Costa CI 15-JAN John Davidson IN 25-SEP Susan Ash AP 05-FEB Stephen York CM 03-JUL Richard Jones CI 30-OCT Joanne Brown IN 18-AUG Donald Brown CI 05-NOV Paula Adams IN 12-DEC firstpay6 Enter value for input_pay_id: 1111 PL/SQL procedure successfully completed. firstpay6 Enter value for input_pay_id: 2222 PL/SQL procedure successfully completed.

PL/SQL - Compound OR SET VERIFY OFF DECLARE v_idno VARCHAR2(5) :=&input_idno; v_yrgoal NUMBER(7,2); v_newgoal NUMBER(7,2); v_state VARCHAR2(2); BEGIN SELECT yrgoal, state INTO v_yrgoal, v_state FROM donornew WHERE idno = v_idno; IF v_yrgoal > 250 OR v_state = 'MA' THEN v_newgoal := v_yrgoal * 1.1 ; ELSE v_newgoal := v_yrgoal * 1.2; END IF; UPDATE donornew SET yrgoal = v_newgoal WHERE idno = v_idno; END; / SET VERIFY ON SQL> edit donor3a

v_yrgoal > 250 v_state = MA Increase goal by 10% Increase goal by 20% Y Y N N PL/SQL - Compound OR Increase goal by 10% IF v_yrgoal > 250 OR v_state = 'MA' THEN v_newgoal := v_yrgoal * 1.1; ELSE v_newgoal := v_yrgoal * 1.2; END IF;

SQL> SELECT * FROM donornew; IDNO NAME STADR CITY ST ZIP DATEFST YRGOAL CONTACT Stephen Daniels 123 Elm St Seekonk MA JUL John Smith Jennifer Ames 24 Benefit St Providence RI MAY Susan Jones Carl Hersey 24 Benefit St Providence RI JAN-98 Susan Jones Susan Ash 21 Main St Fall River MA MAR Amy Costa Nancy Taylor 26 Oak St Fall River MA MAR John Adams Robert Brooks 36 Pine St Fall River MA APR Amy Costa donor3a Enter value for input_idno: PL/SQL procedure successfully completed. donor3a Enter value for input_idno: PL/SQL procedure successfully completed. SQL> SELECT * FROM donornew; IDNO NAME STADR CITY ST ZIP DATEFST YRGOAL CONTACT Stephen Daniels 123 Elm St Seekonk MA JUL John Smith Jennifer Ames 24 Benefit St Providence RI MAY Susan Jones Carl Hersey 24 Benefit St Providence RI JAN-98 Susan Jones Susan Ash 21 Main St Fall River MA MAR Amy Costa Nancy Taylor 26 Oak St Fall River MA MAR John Adams Robert Brooks 36 Pine St Fall River MA APR Amy Costa PL/SQL - Compound OR

SQL> edit firstpay7 SET VERIFY OFF DECLARE v_pay_id first_pay_new.pay_id%TYPE :=&input_pay_id; v_new_sal first_pay_new.salary%TYPE; v_jobcode first_pay_new.jobcode%TYPE; v_bonus first_pay_new.bonus%TYPE; BEGIN SELECT salary, jobcode, bonus INTO v_new_sal, v_jobcode, v_bonus FROM first_pay_new WHERE pay_id = v_pay_id; IF v_jobcode = 'CI' OR v_bonus > 1000 THEN v_new_sal := v_new_sal * 1.05; ELSE v_new_sal := v_new_sal * 1.02; END IF; UPDATE first_pay_new SET salary = v_new_sal WHERE pay_id = v_pay_id; END; / SET VERIFY ON

PL/SQL - Compound OR SQL> SELECT * FROM first_pay_new; PAY_ NAME JO STARTDATE SALARY BONUS Linda Costa CI 15-JAN John Davidson IN 25-SEP Susan Ash AP 05-FEB Stephen York CM 03-JUL Richard Jones CI 30-OCT Joanne Brown IN 18-AUG Donald Brown CI 05-NOV Paula Adams IN 12-DEC SQL> SELECT * FROM first_pay_new; PAY_ NAME JO STARTDATE SALARY BONUS Linda Costa CI 15-JAN John Davidson IN 25-SEP Susan Ash AP 05-FEB Stephen York CM 03-JUL Richard Jones CI 30-OCT Joanne Brown IN 18-AUG Donald Brown CI 05-NOV Paula Adams IN 12-DEC Enter value for input_pay_id: 6666 PL/SQL procedure successfully completed. Enter value for input_pay_id: 3333 PL/SQL procedure successfully completed. Enter value for input_pay_id: 1111 PL/SQL procedure successfully completed.

SET VERIFY OFF DECLARE v_idno VARCHAR2(5) :=&input_idno; v_yrgoal donornew.yrgoal%TYPE; v_newgoal donornew.yrgoal%TYPE; v_state donornew.state%TYPE; v_datefst donornew.datefst%TYPE; BEGIN SELECT yrgoal, state, datefst INTO v_yrgoal, v_state, v_datefst FROM donornew WHERE idno = v_idno; IF v_state = 'MA' AND (v_yrgoal '01-JAN-98') THEN v_newgoal := v_yrgoal * 1.1 ; ELSE v_newgoal := v_yrgoal; END IF; UPDATE donornew SET yrgoal = v_newgoal WHERE idno = v_idno; END; / SET VERIFY ON SQL> edit donor3b PL/SQL - compound AND / OR

v_state=MA v_yrgoal < 100 Increase goal by 10% No change to goal Y Y N N No change to goal v_datefst > 01-JAN-98 Increase goal by 10% YN IF v_state = 'MA' AND (v_yrgoal '01-JAN-98') THEN v_newgoal := v_yrgoal * 1.1; ELSE v_newgoal := v_yrgoal;

SQL> SELECT * FROM donornew; IDNO NAME STADR CITY ST ZIP DATEFST YRGOAL CONTACT Stephen Daniels 123 Elm St Seekonk MA JUL John Smith Jennifer Ames 24 Benefit St Providence RI MAY Susan Jones Carl Hersey 24 Benefit St Providence RI JAN-98 Susan Jones Susan Ash 21 Main St Fall River MA MAR Amy Costa Nancy Taylor 26 Oak St Fall River MA MAR John Adams Robert Brooks 36 Pine St Fall River MA APR Amy Costa donor3b Enter value for input_idno: PL/SQL procedure successfully completed. donor3b Enter value for input_idno: PL/SQL procedure successfully completed. donor3b Enter value for input_idno: PL/SQL procedure successfully completed. SQL> SELECT * FROM donornew; IDNO NAME STADR CITY ST ZIP DATEFST YRGOAL CONTACT Stephen Daniels 123 Elm St Seekonk MA JUL John Smith Jennifer Ames 24 Benefit St Providence RI MAY Susan Jones Carl Hersey 24 Benefit St Providence RI JAN-98 Susan Jones Susan Ash 21 Main St Fall River MA MAR Amy Costa Nancy Taylor 26 Oak St Fall River MA MAR John Adams Robert Brooks 36 Pine St Fall River MA APR Amy Costa Record met the criteria and a change was made to the goal. Records and did not meet the criteria.

PL/SQL - compound AND / OR SET VERIFY OFF DECLARE v_idno VARCHAR2(5) :=&input_idno; v_yrgoal donornew.yrgoal%TYPE; v_newgoal donornew.yrgoal%TYPE; v_state donornew.state%TYPE; v_datefst donornew.datefst%TYPE; BEGIN SELECT yrgoal, state, datefst INTO v_yrgoal, v_state, v_datefst FROM donornew WHERE idno = v_idno; IF v_state = 'MA' AND v_yrgoal '01-JAN-98' THEN v_newgoal := v_yrgoal * 1.1 ; ELSE v_newgoal := v_yrgoal; END IF; UPDATE donornew SET yrgoal = v_newgoal WHERE idno = v_idno; END; / SET VERIFY ON SQL> edit donor3c

v_state=MA v_yrgoal < 100 Increase goal by 10% No change to goal Y Y N N v_datefst > 01-JAN-98 Increase goal by 10% YN PL/SQL - compound AND / OR No change to goal v_datefst > 01-JAN-98 Increase goal by 10% YN IF v_state = 'MA' AND v_yrgoal '01-JAN-98' THEN v_newgoal := v_yrgoal * 1.1; ELSE v_newgoal := v_yrgoal; END IF;

v_state=MA v_yrgoal < 100 Increase goal by 10% No change to goal Y Y N N No change to goal v_datefst > 01-JAN-98 Increase goal by 10% YN PL/SQL - compound AND / OR IF v_datefst > '01-JAN-98’ OR v_state = 'MA' AND v_yrgoal < 100 THEN v_newgoal := v_yrgoal * 1.1; ELSE v_newgoal := v_yrgoal; END IF;

SQL> SELECT * FROM donornew; IDNO NAME STADR CITY ST ZIP DATEFST YRGOAL CONTACT Stephen Daniels 123 Elm St Seekonk MA JUL John Smith Jennifer Ames 24 Benefit St Providence RI MAY Susan Jones Carl Hersey 24 Benefit St Providence RI JAN-98 Susan Jones Susan Ash 21 Main St Fall River MA MAR Amy Costa Nancy Taylor 26 Oak St Fall River MA MAR John Adams Robert Brooks 36 Pine St Fall River MA APR Amy Costa donor3c Enter value for input_idno: PL/SQL procedure successfully completed. donor3c Enter value for input_idno: PL/SQL procedure successfully completed. SQL> SELECT * FROM donornew; IDNO NAME STADR CITY ST ZIP DATEFST YRGOAL CONTACT Stephen Daniels 123 Elm St Seekonk MA JUL John Smith Jennifer Ames 24 Benefit St Providence RI MAY Susan Jones Carl Hersey 24 Benefit St Providence RI JAN-98 Susan Jones Susan Ash 21 Main St Fall River MA MAR Amy Costa Nancy Taylor 26 Oak St Fall River MA MAR John Adams Robert Brooks 36 Pine St Fall River MA APR Amy Costa PL/SQL - compound AND / OR

PL/SQL - null SET VERIFY OFF DECLARE v_idno VARCHAR2(5) :=&input_idno; v_yrgoal donornew.yrgoal%TYPE; v_newgoal donornew.yrgoal%TYPE; v_state donornew.state%TYPE; BEGIN SELECT yrgoal, state INTO v_yrgoal, v_state FROM donornew WHERE idno = v_idno; IF v_state = 'RI' AND (v_yrgoal < 100 OR v_yrgoal IS NULL) THEN v_newgoal := 100; ELSE v_newgoal := v_yrgoal; END IF; UPDATE donornew SET yrgoal = v_newgoal WHERE idno = v_idno; END; / SET VERIFY ON SQL> edit donor3d

SQL> SELECT * FROM donornew; IDNO NAME STADR CITY ST ZIP DATEFST YRGOAL CONTACT Stephen Daniels 123 Elm St Seekonk MA JUL John Smith Jennifer Ames 24 Benefit St Providence RI MAY Susan Jones Carl Hersey 24 Benefit St Providence RI JAN-98 Susan Jones Susan Ash 21 Main St Fall River MA MAR Amy Costa Nancy Taylor 26 Oak St Fall River MA MAR John Adams Robert Brooks 36 Pine St Fall River MA APR Amy Costa donor3d Enter value for input_idno: PL/SQL procedure successfully completed. SQL> SELECT * FROM donornew; IDNO NAME STADR CITY ST ZIP DATEFST YRGOAL CONTACT Stephen Daniels 123 Elm St Seekonk MA JUL John Smith Jennifer Ames 24 Benefit St Providence RI MAY Susan Jones Carl Hersey 24 Benefit St Providence RI JAN Susan Jones Susan Ash 21 Main St Fall River MA MAR Amy Costa Nancy Taylor 26 Oak St Fall River MA MAR John Adams Robert Brooks 36 Pine St Fall River MA APR Amy Costa PL/SQL - null Record is for RI and the yrgoal is null so it meets the criteria and the change is made.

SQL> edit firstpay8 PL/SQL - compound SET VERIFY OFF DECLARE v_pay_id first_pay_new.pay_id%TYPE :=&input_pay_id; v_new_sal first_pay_new.salary%TYPE; v_jobcode first_pay_new.jobcode%TYPE; v_bonus first_pay_new.bonus%TYPE; BEGIN SELECT salary, jobcode, bonus INTO v_new_sal, v_jobcode, v_bonus FROM first_pay_new WHERE pay_id = v_pay_id; IF v_jobcode = 'CI' AND v_bonus > 1500 OR v_jobcode = 'IN' AND v_bonus > 1000 THEN v_new_sal := v_new_sal * 1.05; END IF; UPDATE first_pay_new SET salary = v_new_sal WHERE pay_id = v_pay_id; END; / SET VERIFY ON

IF v_jobcode = 'CI' AND v_bonus > 1500 OR v_jobcode = 'IN' AND v_bonus > 1000 THEN v_new_sal := v_new_sal * 1.05; END IF; v_jobcode=CI v_bonus > 1500 Increase salary by 5% Y Y N N v_jobcode=IN YN PL/SQL - compound v_bonus > 1000 Increase salary by 5% YN

SQL> SELECT * FROM first_pay_new; PAY_ NAME JO STARTDATE SALARY BONUS Linda Costa CI 15-JAN John Davidson IN 25-SEP Susan Ash AP 05-FEB Stephen York CM 03-JUL Richard Jones CI 30-OCT Joanne Brown IN 18-AUG Donald Brown CI 05-NOV Paula Adams IN 12-DEC firstpay8 Enter value for input_pay_id: 1111 PL/SQL procedure successfully completed. firstpay8 Enter value for input_pay_id: 5555 PL/SQL procedure successfully completed. SQL> SELECT * FROM first_pay_new; PAY_ NAME JO STARTDATE SALARY BONUS Linda Costa CI 15-JAN John Davidson IN 25-SEP Susan Ash AP 05-FEB Stephen York CM 03-JUL Richard Jones CI 30-OCT Joanne Brown IN 18-AUG Donald Brown CI 05-NOV Paula Adams IN 12-DEC firstpay8 Enter value for input_pay_id: 2222 PL/SQL procedure successfully completed. firstpay8 Enter value for input_pay_id: 8888 PL/SQL procedure successfully completed. PL/SQL - compound