Special Registers, Date functions, Case and User Defined Functions!!

Slides:



Advertisements
Similar presentations
Files Used to transfer data to and from disk. Opening an Output File Stream #include // File stream library. ofstream outfile;// Declare file stream variable.
Advertisements

C Language.
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Lab 8 User Defined Function.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Introduction to C Programming
CSE1301 Computer Programming Lecture 4: C Primitives I.
Honors Compilers The Course Project Feb 28th 2002.
Mathematical Operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming in.
Function with Output Parameters 4 We have seen that functions can return a single value or no value (void return type) 4 It is quite often useful to be.
1 9/08/06CS150 Introduction to Computer Science 1 Arithmetic Operators.
Chapter 8 Arrays and Strings
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Basic Input/Output and Variables Ethan Cerami New York
Programming is instructing a computer to perform a task for you with the help of a programming language.
Introduction to C++ - How C++ Evolved Most popular languages currently: COBOL, Fortran, C, C++, Java (script) C was developed in 1970s at AT&T (Richie)
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
Decision II. CSCE 1062 Outline  Boolean expressions  switch statement (section 4.8)
C++ PROGRAMMING: PROGRAM DESIGN INCLUDING DATA STRUCTURES, FIFTH EDITION Chapter 10: Strings and string type.
Stored Procedures Week 9. Test Details Stored Procedures SQL can call code written in iSeries High Level Languages –Called stored procedures SQL has.
CS146 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman
CS178 Database Management PL/SQL session 8 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman.
NA2204.1jcmt CSE 1320 Intermediate Programming C Program Basics Structure of a program and a function type name (parameters) { /* declarations */ statement;
Introduction to Programming
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
More About Data Types & Functions. General Program Structure #include statements for I/O, etc. #include's for class headers – function prototype statements.
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
Chapter 15 Strings as Character Arrays
Char ch; ch ‘L’‘X’‘V’‘I’ As in Roman numerals Want to give each a value, n say switch (ch) { case ‘I’:n = 1; break; case ‘V’:n = 5; break; … default:cout.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the concept and use of pointers ❏ To be able to declare, define,
Pointer Lecture 2 Course Name: High Level Programming Language Year : 2010.
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
CS422 Principles of Database Systems Stored Procedures and Triggers Chengyu Sun California State University, Los Angeles.
Creating Functions This presentation was prepared by Professor Steve Ross, with the advice of other MIS Faculty, for use in MIS Classes at Western Washington.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Case Statements and Functions
Objectives Identify the built-in data types in C++
Lecture-5 Arrays.
Section 3.2c Strings and Method Signatures
Lecture2.
Agenda Warmup Lesson 2.5 (Ascii, Method Overloading)
Chapter 9 Pointers Objectives
Chapter 2.
Control Statement Examples
The C “switch” Statement
The C “switch” Statement
CS 1430: Programming in C++ Turn in your Quiz1-2 No time to cover HiC.
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Introduction to CS Your First C Programs
Topics discussed in this section:
Chapter 2: Basic Elements of Java
More About Data Types & Functions
Review for Final Exam.
Strings A collection of characters taken as a set:
Lecture 12 Oct 16, 02.
SQL-1 Week 8-9.
Additional Topics in VB.NET
Review for Final Exam.
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Tutorial 6 PHP & MySQL Li Xu
Programs written in C and C++ can run on many different computers
Fundamental Programming
Hint idea 2 Split into shorter tasks like this.
Presentation transcript:

Special Registers, Date functions, Case and User Defined Functions!!

Agenda Review ISeries installed products Special Registers – System Values Create Tables Date Functions Case Building our own SQL Functions

Review Table vs *FILE Library vs Collection What is a schema? Constraints?

ISeries installed Products Display Software Resources

Build the following Database Students Student Number Student Name Address Enrolled Date Student Marks Student Number Course Code Final Grade

Insert Data

Add 1 year, 2 months and 3 days to enrolled date Select Statement As?

How many days has a student been at Seneca? Select Statement

Case Statements Provides a multiconditional test Eg: select orderid, when totamt <= 100 then ‘Small’ when totamt <= 500 then ‘Medium’ else ‘Large’ end as SalesSize From Sale

Case Statements select orderid, case ShipCity when ‘Toronto’ then ‘Ontario’ when ‘Montreal’ then ‘Quebec’ else ‘Invalid’ end as CustProv From Sale

Write a select statement that produces a student marks report and lists the letter grade

Build your own SQL function First line: Create Function fname Where fname is the name for the function. Second set of lines is used to define input parameters Eg: (Str char(10), StrLen int) defines the parameter Str as a 10 characters and defines the parameter StrLen as an integer

UDF cont’d Third line declares the one variable returned eg: RETURNS CHAR(10) Means return a 10 character value Fourth Line declares the language of the function: Language SQL

UDF Cont’d Fifth line: Returns null on null input Means that if there are no input values to the function, then NULL will be returned. Sixth line: BEGIN Starts the code section of the function

UDF Cont’d Last line END Comments start with --

Coding functions DECLARE Used to declare variables SET used to assign values to variables RETURN used to return the output parameter

Coding Functions Most built-in SQL functions can be used including case Case statements must end in end case Each statement must end in an ‘;’

Build a function that calculates a Letter Grade based on a Final Mark

Coding UDF create function dbpract.gradeStr (grade dec(5,2)) returns char(2) language sql returns null on null input begin -- declare variables declare chargrade char(2); -- calculate char grade case when grade >= 90 then set chargrade = 'A+'; when grade >= 80 then set chargrade = 'A'; else set chargrade = 'F'; end case; return chargrade; end