Fundamentals of PL/SQL part 1 (Basics)

Slides:



Advertisements
Similar presentations
PL/SQL.
Advertisements

Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
PL/SQL (Procedural Language extensions to SQL) Prepared by: Manoj Kathpalia Edited by: M V Ramakrishna.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Data types and variables
JavaScript, Fourth Edition
Chapter 2 Data Types, Declarations, and Displays
JavaScript, Third Edition
Objectives You should be able to describe: Data Types
Chapter 3: Data Types and Operators JavaScript - Introductory.
Chapter 5 Using Data and COBOL Operators. Initializing Variables When you define a variable in WORKING- STORAGE, you also can assign it an initial value.
Oracle10g Developer: PL/SQL Programming1 Objectives Programming fundamentals The PL/SQL block Define and declare variables Initialize variables The NOT.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic Operators.
INTRODUCTION TO PL/SQL. Class Agenda Introduction Introduction to PL/SQL Declaring PL/SQL Variable Creating the Executable Section Interacting with the.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
COMPUTER PROGRAMMING II SUMMER 2011 Visual Basic to C#
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Programming with Microsoft Visual Basic th Edition
CIVIL AND GEOMATIC ENGINEERING FT Okyere. CIV 257- COMPUTER PROGRAMMING Lecture 3.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Primitive Data Types. int This is the type you are familiar with and have been using Stores an integer value (whole number) between -2,147,483,648 (-2.
Introduction to PL/SQL N. Dimililer. About PL/SQL –PL/SQL is an extension to SQL with design features of programming languages. –Data manipulation and.
1Object-Oriented Program Development Using C++ Built-in Data Types Data type –Range of values –Set of operations on those values Literal: refers to acceptable.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Welcome to Computer Programming II! Computer Programming II Summer 2015.
Creating Database Objects
C LANGUAGE MULITPLE CHOICE QUESTION SET-2
VBScript Session 3.
Chapter 2 Variables.
Topics Designing a Program Input, Processing, and Output
The Machine Model Memory
Data Types and Expressions
An Application Uses Variables to Hold Information So It May Be Manipulated, Used to Manipulate Other Information, or Remembered for Later Use.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Java Primer 1: Types, Classes and Operators
Variables A variable is a placeholder for a value. It is a named memory location where that value is stored. Use the name of a variable to access or update.
Oracle11g: PL/SQL Programming Chapter 2 Basic PL/SQL Block Structures.
ITEC113 Algorithms and Programming Techniques
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Revision Lecture
Variables and Primative Types
The Selection Structure
Fundamental of Java Programming Basics of Java Programming
Data Structures Mohammed Thajeel To the second year students
Chapter 6 Variables What is VBScript?
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Console input.
Numbers.
Variables Numbers can be stored and retrieved while a program is running if they are given a home. The way that integers and decimal numbers are stored.
PHP.
C++ Data Types Data Type
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Chapter 2: Introduction to C++.
PL/SQL Declaring Variables.
Boolean Expressions to Make Comparisons
Topics Designing a Program Input, Processing, and Output
Chapter 3 Selections Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.
Programming Logic and Design Fifth Edition, Comprehensive
Topics Designing a Program Input, Processing, and Output
Matlab Basics.
Chapter 2 Variables.
Creating Database Objects
Class code for pythonroom.com cchsp2cs
Variables and Constants
Presentation transcript:

Fundamentals of PL/SQL part 1 (Basics)

Defining variables and constants The most common datatypes in PL/SQL are in four families: string, number, date, and logical (Boolean). Strings are "free form" data. A string can contain any valid character in the character set of a language. While there are several variations of strings, the datatype you will mostly use is VARCHAR2. The general format for a VARCHAR2 declaration is: variable_name VARCHAR2(n); The declaration of a NUMBER looks like this: variable_name NUMBER [ ( precision [, scale ] ) ];

Examples The following examples demonstrate the different ways you can declare variables of type NUMBER: The bean_counter variable can hold values with up to ten digits of precision, three of which are to the right of the decimal point. If you assign 12345.6784 to bean_counter, it is rounded to 12345.678. If you assign 1234567891.23 to the variable, the operation will return an error because there are more digits than allowed for in the precision: bean_counter NUMBER (10,3); The any_number variable can span the full range of supported values, because the default precision and scale are unspecified: any_number NUMBER;

Rules Here are some rules to keep in mind when declaring numbers: If the scale is positive, then the scale determines the point at which rounding occurs to the right of the decimal point. You can use a negative scale, in which case the scale determines the point at which rounding occurs to the left of the decimal point. If the scale is zero, then rounding occurs to the nearest whole number. If the scale is not specified, then no rounding occurs. The absolute magnitude range of legal numbers is fairly enormous: from 10-130 to 10125 NOTE: You can also declare numbers that are whole numbers (they have no fractional components) as having the INTEGER datatype. An Oracle integer may have up to 38 digits.

Constants The complete syntax template for declaring a variable is: variable_name DATATYPE [ CONSTANT ] [ := | DEFAULT initial_value ]; CONSTANT If this keyword is present, prevents the program from changing the value of the variable. Must be accompanied by an initial value. A convenience that the compiler provides to help you protect yourself from silly errors. := | DEFAULT Designates the presence of an optional clause that can initialize the variable to a non-null value (see the following discussion). You can use either the assignment operator, :=, or the keyword DEFAULT to set apart the initial value.

Examples of variables and Constants Normal integer initialized to the highest possible value without resorting to scientific notation (there are 38 nines): max_grains_of_sand INTEGER := 99999999999999999999999999999999999999; Number variable whose default value is the result of an arithmetic operator: national_debt FLOAT DEFAULT 10**10; A quantity unlikely to change, and therefore made a constant, which requires an initial value: earth_circumference_miles CONSTANT NUMBER := 24859.82;

Types of PL/SQL Operators Operator Category Notation Meaning Assignment := Store the value Arithmetic + - / * ** Addition Subtraction Division Multiplication Exponentiation Logical AND OR NOT Conjunction Disjunction Negation

Types of PL/SQL Operators Operator Category Notation Meaning Comparison (of non-nulls) = != < > <= >= IN BETWEEN Equality Inequality Less than Greater than Less than or equal Greater than or equal Equality disjunction Range test

Types of PL/SQL Operators Operator Category Notation Meaning Comparison (of nulls) IS NULL IS NOT NULL Nullity test Non-nullity test String LIKE || Wildcard matching Concatenation

First PL/SQL Procedure Example 1: BEGIN DBMS_OUTPUT.PUT_LINE('hello, world'); END; / Example 2: Declare Str1 varchar2(20):=‘Hello, world’; Begin Dbms_output.put_line(Str1); End NOTE: These are called as anonymous block—that is, a block with no name. Its only executable statement is a call to the procedure PUT_LINE, supplied in Oracle's built-in package named DBMS_OUTPUT. This built-in stored procedure can accept a string that can get printed to the screen when you run it.

Types of Blocks In PL/SQL, there are only three types of blocks: Anonymous blocks Procedures Functions

Named blocks: procedures and functions A named program that executes some predefined statements and then returns control to whatever called it. After creating a procedure, you can invoke it by name from other programs. Function Similar to a procedure, except that it returns a value to the program that calls it. The data returned by a function is always of a specific, predefined datatype.

Conditional Statements Syntax IF Statement If <some condition> …… End If; IF-THEN-ELSE STATEMENT if condition then ……. else End if;

Conditional Statements Syntax IF-THEN-ELSIF statement if <some condition> then ……. Elsif<some condition> Then …. Else …… End if; IF-THEN-ELSE STATEMENT IF condition THEN else

Conditional Statements Syntax Case Statement CASE selector WHEN 'value1' THEN S1; WHEN 'value2' THEN S2; WHEN 'value3' THEN S3; ELSE Sn; -- default case END CASE; Nested IF-THEN-ELSE I If( <some condition>) Then If(<some condition>) End if Else ……

Summary How to define variables and constants Types of PL/SQL Operators Types of Blocks Conditional Statements