PL/SQL is Oracle Corporation's procedural extension for SQL and the Oracle relational database. PL/SQL is available in Oracle Database, Times Ten in-memory database, and IBM DB 2. Oracle Corporation usually extends PL/SQL functionality with each successive release of the Oracle Database.
VBScript provides two main types of conditional statements for controlling program flow: the If...Then statement and Select Case statement. The If...Then statement allows executing different blocks of code based on conditional checks, and can include ElseIf and Else clauses. The Select Case statement chooses between multiple blocks of code based on the value of an expression. VBScript also supports looping structures like For...Next, Do...Loop, and While...Wend to repeat blocks of code. These conditional and looping statements allow inserting verification points and error handling in scripts.
The document discusses different types of loops and conditional statements in programming languages. It explains the if, if-else, and switch conditional statements, providing examples of each. It also covers different types of loops - while, do-while, for, and nested loops. Examples are given to illustrate the syntax and usage of each loop and conditional statement.
Control structures in C++ allow programs to conditionally execute code or repeat code in loops. The if/else statement executes code based on a condition being true or false. A while loop repeats a statement as long as a condition is true. A do/while loop repeats a statement first, then checks a condition to repeat. A for loop initializes a counter, checks a condition, and increments the counter on each iteration while the condition is true. Break and continue can prematurely exit or skip iterations in loops.
Latest C Interview Questions and AnswersDaisyWatson5
3. What is a register variable?
Register variables are stored in the CPU registers. Its default value is a garbage value. Scope of a register variable is local to the block in which it is defined. Lifetime is till control remains within the block in which the register variable is defined. Variable stored in a CPU register can always be accessed faster than the one that is stored in memory. Therefore, if a variable is used at many places in a program, it is better to declare its storage class as register
Example: register int x=5;
Variables for loop counters can be declared as register. Note that register keyword may be ignored by some compilers.
4. Where is an auto variables stored?
Main memory and CPU registers are the two memory locations where auto variables are stored. Auto variables are defined under automatic storage class. They are stored in main memory. Memory is allocated to an automatic variable when the block which contains it is called and it is de-allocated at the completion of its block
execution.
Auto variables:
Storage
:
main memory.
Default value
:
garbage value.
Scope
:
local to the block in which the variable is defined.
Lifetime
:
till the control remains within the block in which the variable is defined.
5. What is scope & storage allocation of extern and global variables?
Extern variables: belong to the External storage class and are stored in the main memory. extern is used when we have to refer a function or variable that is implemented in another file in the same project. The scope of the extern variables is Global.
The original Creative JavaScript tutorial, covering loops in JavaScript. This tutorial is aimed at creative people with no programming experience who are interested to learn loops JavaScript.
Checking Wine with PVS-Studio and Clang Static AnalyzerAndrey Karpov
In this article, I'm going to tell you about the check of the Wine project done by the static analyzers for C/C++ code PVS-Studio and Clang Static Analyzer.
VBScript provides two main types of conditional statements for controlling program flow: the If...Then statement and Select Case statement. The If...Then statement allows executing different blocks of code based on conditional checks, and can include ElseIf and Else clauses. The Select Case statement chooses between multiple blocks of code based on the value of an expression. VBScript also supports looping structures like For...Next, Do...Loop, and While...Wend to repeat blocks of code. These conditional and looping statements allow inserting verification points and error handling in scripts.
The document discusses different types of loops and conditional statements in programming languages. It explains the if, if-else, and switch conditional statements, providing examples of each. It also covers different types of loops - while, do-while, for, and nested loops. Examples are given to illustrate the syntax and usage of each loop and conditional statement.
Control structures in C++ allow programs to conditionally execute code or repeat code in loops. The if/else statement executes code based on a condition being true or false. A while loop repeats a statement as long as a condition is true. A do/while loop repeats a statement first, then checks a condition to repeat. A for loop initializes a counter, checks a condition, and increments the counter on each iteration while the condition is true. Break and continue can prematurely exit or skip iterations in loops.
Latest C Interview Questions and AnswersDaisyWatson5
3. What is a register variable?
Register variables are stored in the CPU registers. Its default value is a garbage value. Scope of a register variable is local to the block in which it is defined. Lifetime is till control remains within the block in which the register variable is defined. Variable stored in a CPU register can always be accessed faster than the one that is stored in memory. Therefore, if a variable is used at many places in a program, it is better to declare its storage class as register
Example: register int x=5;
Variables for loop counters can be declared as register. Note that register keyword may be ignored by some compilers.
4. Where is an auto variables stored?
Main memory and CPU registers are the two memory locations where auto variables are stored. Auto variables are defined under automatic storage class. They are stored in main memory. Memory is allocated to an automatic variable when the block which contains it is called and it is de-allocated at the completion of its block
execution.
Auto variables:
Storage
:
main memory.
Default value
:
garbage value.
Scope
:
local to the block in which the variable is defined.
Lifetime
:
till the control remains within the block in which the variable is defined.
5. What is scope & storage allocation of extern and global variables?
Extern variables: belong to the External storage class and are stored in the main memory. extern is used when we have to refer a function or variable that is implemented in another file in the same project. The scope of the extern variables is Global.
The original Creative JavaScript tutorial, covering loops in JavaScript. This tutorial is aimed at creative people with no programming experience who are interested to learn loops JavaScript.
Checking Wine with PVS-Studio and Clang Static AnalyzerAndrey Karpov
In this article, I'm going to tell you about the check of the Wine project done by the static analyzers for C/C++ code PVS-Studio and Clang Static Analyzer.
This document discusses MATLAB control structures for flow of execution including if/else statements, while loops, and for loops. It provides examples of basic syntax and use cases for each structure. Key points covered include evaluating conditional expressions, updating loop variables, and using for loops to iterate over array elements or ranges of indices.
In this lecture we will discuss about another flow control method – Loop control.
A loop control is used to execute a set of commands repeatedly
The set of commands is called the body of the loop
MATLAB has two loop control techniques
Counted loops - executes commands a specified number of times
Conditional loops - executes commands as long as a specified expression is true
Iterative structures, also known as loops, repeat sections of code and are used for tasks like calculating multiple values, computing iterative results, printing tables of data, and processing large amounts of input or array data. The three types of loops in C++ are the while loop, do-while loop, and for loop, each with different test conditions to control the loop execution. Loops can also be nested within each other to perform multiple iterations or to loop through multi-dimensional data structures.
Loop control statements in C are used to repeatedly execute a block of code while or until a given condition is true. There are three main types of loop control statements in C: for, while, and do-while loops. The for loop allows executing a block of code a specific number of times. The while loop repeatedly executes the block as long as the condition is true. The do-while loop is similar to the while loop, but it will always execute the block at least once even if the condition is false.
Exception handling in C++ allows programs to deal with abnormal or unexpected behaviors during execution. It uses three keywords - try, catch, and throw. The try block defines the code that might cause exceptions. If an exception occurs, the program flow moves to the catch block to handle it. Multiple catch blocks can be chained to handle different exception types. The throw keyword transfers control from the try block to the catch block when an exception happens.
The document discusses the different types of loops in C language: while loop, do-while loop, and for loop. It provides the syntax and an example of each loop. The while loop checks the condition first and repeats the block of code as long as the condition is true. The do-while loop ensures the block of code executes at least once before checking the condition. The for loop allows initialization of a counter, specifies a condition to test, and how to change the counter between iterations of the loop.
The document discusses different control structures in C++ programs including sequence, selection, and repetition. It defines each structure and provides examples. Sequence refers to executing statements in order. Selection (branching) executes different statements depending on conditions. Repetition (looping) repeats statements while conditions are met. Common control structures in C++ include if/else statements, switch statements, and various loops like while, for, and do-while loops. The document provides details on the syntax and flow of each structure.
For loops allow code to be repeatedly executed until a condition is met. They include initialization, condition, and update statements. While and do-while loops also repeatedly execute code until a condition is met, but check the condition at the start or end of each iteration respectively. Loops are useful for tasks like adding numbers in a range or populating data structures to avoid repetitive code.
The document discusses different loop structures in C++ for getting user input from a menu. It presents an algorithm to get a valid menu choice using a do-while loop, then refines it to display error messages using a forever loop. C++ provides for, while, do-while, and forever loops for different repetition needs depending on an algorithm's structure.
The document discusses the flow of control in programs and control statements. There are two major categories of control statements: loops and decisions. Loops cause a section of code to repeat, while decisions cause jumps in the program flow depending on calculations or conditions. Common loop statements are for, while, and do-while loops. Common decision statements include if-else and switch statements. Nested statements and loops can also be used to further control program flow.
what are loop in general
what is loop in c language
uses of loop in c language
types of loop in c language
program of loop in c language
syantax of loop in c language
The document provides an overview of key concepts in C++ including program structure, data types, variables, operators, control structures like if/else, switch, loops (while, do-while, for), functions, and parameters. It defines common C++ terms and syntax like comments, libraries, main function, return type, and passing arguments by value, reference, and constant reference.
Handling inline assembly in Clang and LLVMMin-Yih Hsu
The document discusses how inline assembly is processed in Clang and LLVM. It outlines the target-specific logic involved at each stage, including operand constraint validation in Clang, lowering operands to LLVM IR, and printing different operand types in the assembler. Target-specific callbacks for inline assembly handling are scattered throughout Clang and LLVM. The goals are to learn the inline assembly workflow and provide documentation for backend developers to add support.
ReactOS is intensively developing, and its codebase is steadily growing in size. On February 16, 2016, a new version of the operating system was released, and we thought it was a good occasion to run it through our static analyzer one more time. The new scan was done with PVS-Studio, version 6.02.
C lecture 4 nested loops and jumping statements slideshareGagan Deep
Nested Loops and Jumping Statements(Loop Control Statements), Goto statement in C, Return Statement in C Exit statement in C, For Loops with Nested Loops, While Loop with Nested Loop, Do-While Loop with Nested Loops, Break Statement, Continue Statement : visit us at : www.rozyph.com
The document provides information on control structures in C++ including relational operators, loops, and decisions. It discusses relational operators like ==, <, > that compare values and return true or false. It describes the three types of loops in C++ - for, while, and do-while loops. The for loop executes a fixed number of times based on initialization, test, and increment expressions. The while loop repeats while a test condition is true. The do-while loop executes the body at least once and then repeats while the test condition is true. The document also covers the if statement for simple conditions and if-else for alternative paths, and provides code examples to demonstrate each control structure.
JavaScript Loop: Optimization of Weak TypingJanlay Wu
This document discusses JavaScript loop optimization and the difference in performance between i++ and i-- loops. It shows that i++ and i-- have similar performance in modern browsers. To better measure the performance, it defines test functions that run the loops 10,000 times with 1,000,000 iterations each. The results show minor differences between browsers but no clear winner between i++ and i--. It also discusses the differences between strong/weak and static/dynamic typing in JavaScript compared to languages like C/Java.
This document provides information on PL/SQL programming language concepts. Some key points:
- PL/SQL allows defining logic blocks that can execute SQL and PL/SQL statements. Blocks have optional declaration, executable, and exception sections.
- PL/SQL supports variables, conditional statements like IF/CASE, and looping with LOOP/WHILE/FOR. Variables can be bound to table columns using %TYPE.
- Cursors allow processing multiple database records in PL/SQL. Explicit cursors are declared and opened/fetched/closed manually while implicit cursors are used for single record queries.
- Parameter cursors can accept parameters. Nested cursors allow querying related data. Cursors
This document provides information on PL/SQL programming language concepts including:
- PL/SQL allows defining logic using variables, conditional statements, loops, and object-oriented programming.
- Code is organized into blocks with declaration, executable, and exception sections.
- Variables can be declared and assigned values. Data types include numbers, strings, records, and collections.
- Conditional statements like IF-THEN-ELSE and CASE support different execution paths.
- Loops like simple, while, and for are used to iterate.
- Cursors access and process multiple database records in PL/SQL blocks.
The document discusses cursors in Oracle databases. It defines cursors as temporary work areas for processing query results row by row. There are two main types of cursors - implicit and explicit. Explicit cursors provide more control and involve declaring, opening, fetching from, and closing the cursor. Examples demonstrate using explicit cursors to retrieve and process multiple rows in a PL/SQL block. The document also covers cursor attributes, cursor for loops, parameterized cursors, and comparisons of implicit and explicit cursors.
The document discusses PL/SQL programming concepts like procedures, cursors, and how to build and use them. It provides examples of creating procedures that update employee salaries, using cursors to loop through database records, and controlling cursor flow. The seminar exercise asks students to create a procedure that increases employee salaries by £500 or £1000 depending on the employee's grade level using concepts covered in the document.
This document discusses MATLAB control structures for flow of execution including if/else statements, while loops, and for loops. It provides examples of basic syntax and use cases for each structure. Key points covered include evaluating conditional expressions, updating loop variables, and using for loops to iterate over array elements or ranges of indices.
In this lecture we will discuss about another flow control method – Loop control.
A loop control is used to execute a set of commands repeatedly
The set of commands is called the body of the loop
MATLAB has two loop control techniques
Counted loops - executes commands a specified number of times
Conditional loops - executes commands as long as a specified expression is true
Iterative structures, also known as loops, repeat sections of code and are used for tasks like calculating multiple values, computing iterative results, printing tables of data, and processing large amounts of input or array data. The three types of loops in C++ are the while loop, do-while loop, and for loop, each with different test conditions to control the loop execution. Loops can also be nested within each other to perform multiple iterations or to loop through multi-dimensional data structures.
Loop control statements in C are used to repeatedly execute a block of code while or until a given condition is true. There are three main types of loop control statements in C: for, while, and do-while loops. The for loop allows executing a block of code a specific number of times. The while loop repeatedly executes the block as long as the condition is true. The do-while loop is similar to the while loop, but it will always execute the block at least once even if the condition is false.
Exception handling in C++ allows programs to deal with abnormal or unexpected behaviors during execution. It uses three keywords - try, catch, and throw. The try block defines the code that might cause exceptions. If an exception occurs, the program flow moves to the catch block to handle it. Multiple catch blocks can be chained to handle different exception types. The throw keyword transfers control from the try block to the catch block when an exception happens.
The document discusses the different types of loops in C language: while loop, do-while loop, and for loop. It provides the syntax and an example of each loop. The while loop checks the condition first and repeats the block of code as long as the condition is true. The do-while loop ensures the block of code executes at least once before checking the condition. The for loop allows initialization of a counter, specifies a condition to test, and how to change the counter between iterations of the loop.
The document discusses different control structures in C++ programs including sequence, selection, and repetition. It defines each structure and provides examples. Sequence refers to executing statements in order. Selection (branching) executes different statements depending on conditions. Repetition (looping) repeats statements while conditions are met. Common control structures in C++ include if/else statements, switch statements, and various loops like while, for, and do-while loops. The document provides details on the syntax and flow of each structure.
For loops allow code to be repeatedly executed until a condition is met. They include initialization, condition, and update statements. While and do-while loops also repeatedly execute code until a condition is met, but check the condition at the start or end of each iteration respectively. Loops are useful for tasks like adding numbers in a range or populating data structures to avoid repetitive code.
The document discusses different loop structures in C++ for getting user input from a menu. It presents an algorithm to get a valid menu choice using a do-while loop, then refines it to display error messages using a forever loop. C++ provides for, while, do-while, and forever loops for different repetition needs depending on an algorithm's structure.
The document discusses the flow of control in programs and control statements. There are two major categories of control statements: loops and decisions. Loops cause a section of code to repeat, while decisions cause jumps in the program flow depending on calculations or conditions. Common loop statements are for, while, and do-while loops. Common decision statements include if-else and switch statements. Nested statements and loops can also be used to further control program flow.
what are loop in general
what is loop in c language
uses of loop in c language
types of loop in c language
program of loop in c language
syantax of loop in c language
The document provides an overview of key concepts in C++ including program structure, data types, variables, operators, control structures like if/else, switch, loops (while, do-while, for), functions, and parameters. It defines common C++ terms and syntax like comments, libraries, main function, return type, and passing arguments by value, reference, and constant reference.
Handling inline assembly in Clang and LLVMMin-Yih Hsu
The document discusses how inline assembly is processed in Clang and LLVM. It outlines the target-specific logic involved at each stage, including operand constraint validation in Clang, lowering operands to LLVM IR, and printing different operand types in the assembler. Target-specific callbacks for inline assembly handling are scattered throughout Clang and LLVM. The goals are to learn the inline assembly workflow and provide documentation for backend developers to add support.
ReactOS is intensively developing, and its codebase is steadily growing in size. On February 16, 2016, a new version of the operating system was released, and we thought it was a good occasion to run it through our static analyzer one more time. The new scan was done with PVS-Studio, version 6.02.
C lecture 4 nested loops and jumping statements slideshareGagan Deep
Nested Loops and Jumping Statements(Loop Control Statements), Goto statement in C, Return Statement in C Exit statement in C, For Loops with Nested Loops, While Loop with Nested Loop, Do-While Loop with Nested Loops, Break Statement, Continue Statement : visit us at : www.rozyph.com
The document provides information on control structures in C++ including relational operators, loops, and decisions. It discusses relational operators like ==, <, > that compare values and return true or false. It describes the three types of loops in C++ - for, while, and do-while loops. The for loop executes a fixed number of times based on initialization, test, and increment expressions. The while loop repeats while a test condition is true. The do-while loop executes the body at least once and then repeats while the test condition is true. The document also covers the if statement for simple conditions and if-else for alternative paths, and provides code examples to demonstrate each control structure.
JavaScript Loop: Optimization of Weak TypingJanlay Wu
This document discusses JavaScript loop optimization and the difference in performance between i++ and i-- loops. It shows that i++ and i-- have similar performance in modern browsers. To better measure the performance, it defines test functions that run the loops 10,000 times with 1,000,000 iterations each. The results show minor differences between browsers but no clear winner between i++ and i--. It also discusses the differences between strong/weak and static/dynamic typing in JavaScript compared to languages like C/Java.
This document provides information on PL/SQL programming language concepts. Some key points:
- PL/SQL allows defining logic blocks that can execute SQL and PL/SQL statements. Blocks have optional declaration, executable, and exception sections.
- PL/SQL supports variables, conditional statements like IF/CASE, and looping with LOOP/WHILE/FOR. Variables can be bound to table columns using %TYPE.
- Cursors allow processing multiple database records in PL/SQL. Explicit cursors are declared and opened/fetched/closed manually while implicit cursors are used for single record queries.
- Parameter cursors can accept parameters. Nested cursors allow querying related data. Cursors
This document provides information on PL/SQL programming language concepts including:
- PL/SQL allows defining logic using variables, conditional statements, loops, and object-oriented programming.
- Code is organized into blocks with declaration, executable, and exception sections.
- Variables can be declared and assigned values. Data types include numbers, strings, records, and collections.
- Conditional statements like IF-THEN-ELSE and CASE support different execution paths.
- Loops like simple, while, and for are used to iterate.
- Cursors access and process multiple database records in PL/SQL blocks.
The document discusses cursors in Oracle databases. It defines cursors as temporary work areas for processing query results row by row. There are two main types of cursors - implicit and explicit. Explicit cursors provide more control and involve declaring, opening, fetching from, and closing the cursor. Examples demonstrate using explicit cursors to retrieve and process multiple rows in a PL/SQL block. The document also covers cursor attributes, cursor for loops, parameterized cursors, and comparisons of implicit and explicit cursors.
The document discusses PL/SQL programming concepts like procedures, cursors, and how to build and use them. It provides examples of creating procedures that update employee salaries, using cursors to loop through database records, and controlling cursor flow. The seminar exercise asks students to create a procedure that increases employee salaries by £500 or £1000 depending on the employee's grade level using concepts covered in the document.
The document discusses various control structures and functions used in Arduino programming including decision making structures like if, else if, else statements and switch case statements. It also covers different types of loops like while, do-while and for loops that allow repeating blocks of code. Functions are described as reusable blocks of code that perform tasks and help organize a program. Strings can be implemented as character arrays or using the String class, and various string functions are provided to manipulate and work with strings.
Oracle - Program with PL/SQL - Lession 06Thuan Nguyen
This document discusses explicit cursors in PL/SQL. It covers:
1) Declaring explicit cursors to query rows from a table and control the cursor through opening, fetching, and closing.
2) Using cursor attributes to check the status and number of rows fetched.
3) Processing cursor rows using a cursor FOR loop or fetching into a record variable.
PL/SQL is an extension of SQL that allows procedural logic to be added to SQL statements and queries. Key features of PL/SQL include blocks, exceptions, cursors, procedures, functions, packages, and triggers. A PL/SQL block contains a declare section to define variables, an executable section to contain program logic, and an optional exception section. Exceptions can be predefined, non-predefined, or user-defined. The document provides examples of handling different types of exceptions within PL/SQL blocks to avoid abnormal program termination.
This document discusses cursors in PL/SQL. It defines a cursor as a pointer that is used to point to individual rows in a database table. It explains that there are two types of cursors: implicit cursors and explicit cursors. Implicit cursors are used automatically for SQL statements and have attributes like %FOUND and %ROWCOUNT to check the status of DML operations. Explicit cursors must be declared, opened, values fetched from them into variables, and then closed to access multiple rows from a table in a controlled manner using PL/SQL.
This document provides an overview of PL/SQL, including its benefits, basic structure and components, variable types, and examples of common programming constructs like if/else statements, loops, and cursors. PL/SQL allows developers to perform programming within Oracle databases, combining SQL statements with procedural programming elements like conditions and loops. It is useful for modularizing database applications and manipulating query results.
PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language. As of January 2013, PHP was installed on more than 240 million websites (39% of those sampled) and 2.1 million web servers. Originally created by Rasmus Lerdorf in 1994, the reference implementation of PHP (powered by the Zend Engine) is now produced by The PHP Group. While PHP originally stood for Personal Home Page, it now stands for PHP: Hypertext Preprocessor, which is a recursive acronym.
When developing compilers and interpreters, their source code and its testing procedure are demanded to comply with especially strict quality and reliability requirements. However, there are still some suspicious fragments found in the PHP interpreter's source code.
In this article, we are going to discuss the results of the check of the PHP interpreter by PVS-Studio 5.18.
The document discusses JavaScript functions and events. It explains that functions allow code to be reused by defining blocks of code that can be called from different parts of a program. Functions can take parameters and return values. Events trigger JavaScript code to run in response to user actions or browser events like clicking a button. Common events include onclick, which fires when a user clicks an element, and onsubmit, which fires when a form is submitted. The document provides examples of defining and calling functions, passing parameters to functions, and using return values. It also shows examples of handling the onclick and onsubmit events.
Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...WebStackAcademy
Expressions perform operations on data and move data around. Some expressions will be evaluated for their results, some for their side effects, some for both. An expression can have three kinds of result:
a value, such as the result of: (4 * i)
a variable, such as the result of: i = 4
nothing (in the case of an invocation of a method declared as void)
An expression that results in a variable is called an lvalue in C++ and many other languages. A variable expression in Java is the same thing, the Java Language Specification just uses the name variable instead of lvalue. Such an expression can be used on the left hand side of an assignment operator. Side effects come about when an expression includes an assignment, increment, decrement, or method invocation.
In Java language there are several keywords that are used to alter the flow of the program. Statements can be executed multiple times or only under a specific condition. The if, else, and switch statements are used for testing conditions, the while and for statements to create cycles, and the break and continue statements to alter a loop.
When the program is run, the statements are executed from the top of the source file to the bottom. One by one.
C for Loop
Loops are used in programming to execute a block of code repeatedly until a specified condition is met. In this tutorial, you will learn to create for loop in C programming.
C programming has three types of loops:
for loop
while loop
do...while loop
This document discusses cursors in PL/SQL. It begins by defining cursors and their types, including implicit and explicit cursors. It then covers processing explicit cursors using declare, open, fetch, and close statements. The document also discusses cursor attributes, parameterized cursors, advanced cursor features like SELECT FOR UPDATE, and cursor variables including declaring REF cursor types and variables. The overall purpose is to explain how to work with different types of cursors in PL/SQL to retrieve and manipulate result sets.
This document discusses different types of simulation for digital circuits including analog simulation using a SPICE engine, digital simulation, and event-driven simulation. It also covers testbenches, including generating stimulus, monitoring outputs, and exhaustively testing designs. Key topics covered include clocks, finite state machine testing, and force/release in testbenches.
This document contains lecture notes on Verilog syntax and structural modeling. It discusses various Verilog concepts like commenting code, numbers and identifiers, vectors, arrays, parameters and defines, gate primitives, and hierarchy. It provides examples of modeling half adders and full adders structurally and behaviorally using primitives, modules, and always blocks. The document emphasizes choosing descriptive names and commenting code to explain the purpose or motivation behind design decisions.
The document discusses input and output functions in C programming. It describes the printf() and scanf() functions for output and input. printf() displays output and can print variables and messages. scanf() reads input from the keyboard and stores it in variables. It also discusses control flow statements like if-else, switch case, loops (while, do-while, for), and statements like break, continue, and goto.
Below are the lists of available Webi 3.1 report functions and will describe each & every functions along with example. Webi 4.0 reports are also having some functions with some additional futures.
SQL is a domain-specific language used in programming and designed for managing data held in a relational database management system, or for stream processing in a relational data stream management system.
SAP Analytics Cloud combines BI, planning, predictive, and augmented analytics capabilities into one simple cloud environment. Powered by AI technologies and an in-memory database, it is one of the most advanced analytics solutions available today.
In this context, SAP introduced its new flagship some time ago: SAP Analytics Cloud (SAC). This will replace Lumira Designer and enable both power users and business users to create dashboards. SAP Analytics Cloud is currently being enhanced with new functions in fairly rapid cycles and is already competing with Lumira Designer in the current version, even though SAC does not yet offer the full functionality of Lumira. But where exactly are the differences between the two solutions? Which tool is the best for you to meet your dashboard requirements?
The document outlines key aspects of the National Education Policy 2020, including its vision, principles, and focus areas.
It discusses universal access to early childhood care and education from ages 3-6, as well as foundational literacy and numeracy goals for students by grade 3. The document also covers transforming the curriculum, pedagogy, assessment systems, and teacher education to focus on conceptual understanding, critical thinking, and learning outcomes over rote learning.
Key changes proposed include restructuring school education into 5+3+3+4 year stages, multilingual education, holistic progress reports, integration of arts and skills, health and wellness promotion, use of technology, and establishing school complexes for better resource sharing.
Tableau - Learning Objectives for Data, Graphs, Filters, Dashboards and Advan...Srinath Reddy
Step-1 Tableau Introduction
Step-2 Connecting to Data
Step-3 Building basic views
Step-4 Data manipulations and Calculated fields
Step-5 Tableau Dashboards
Step-6 Advanced Data Options
Step-7 Advanced graph Options
The document discusses the history and evolution of the English language from its origins as Anglo-Frisian dialects brought to Britain by Anglo-Saxon settlers in the 5th century AD. It details how Old English emerged as the dominant language by the 7th century and later transformed into Middle English after the Norman conquest of 1066, absorbing elements from Old Norse and Norman French. The document also briefly examines the development of Modern English from the 15th century onward.
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxEduSkills OECD
Iván Bornacelly, Policy Analyst at the OECD Centre for Skills, OECD, presents at the webinar 'Tackling job market gaps with a skills-first approach' on 12 June 2024
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumMJDuyan
(𝐓𝐋𝐄 𝟏𝟎𝟎) (𝐋𝐞𝐬𝐬𝐨𝐧 𝟏)-𝐏𝐫𝐞𝐥𝐢𝐦𝐬
𝐃𝐢𝐬𝐜𝐮𝐬𝐬 𝐭𝐡𝐞 𝐄𝐏𝐏 𝐂𝐮𝐫𝐫𝐢𝐜𝐮𝐥𝐮𝐦 𝐢𝐧 𝐭𝐡𝐞 𝐏𝐡𝐢𝐥𝐢𝐩𝐩𝐢𝐧𝐞𝐬:
- Understand the goals and objectives of the Edukasyong Pantahanan at Pangkabuhayan (EPP) curriculum, recognizing its importance in fostering practical life skills and values among students. Students will also be able to identify the key components and subjects covered, such as agriculture, home economics, industrial arts, and information and communication technology.
𝐄𝐱𝐩𝐥𝐚𝐢𝐧 𝐭𝐡𝐞 𝐍𝐚𝐭𝐮𝐫𝐞 𝐚𝐧𝐝 𝐒𝐜𝐨𝐩𝐞 𝐨𝐟 𝐚𝐧 𝐄𝐧𝐭𝐫𝐞𝐩𝐫𝐞𝐧𝐞𝐮𝐫:
-Define entrepreneurship, distinguishing it from general business activities by emphasizing its focus on innovation, risk-taking, and value creation. Students will describe the characteristics and traits of successful entrepreneurs, including their roles and responsibilities, and discuss the broader economic and social impacts of entrepreneurial activities on both local and global scales.
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPRAHUL
This Dissertation explores the particular circumstances of Mirzapur, a region located in the
core of India. Mirzapur, with its varied terrains and abundant biodiversity, offers an optimal
environment for investigating the changes in vegetation cover dynamics. Our study utilizes
advanced technologies such as GIS (Geographic Information Systems) and Remote sensing to
analyze the transformations that have taken place over the course of a decade.
The complex relationship between human activities and the environment has been the focus
of extensive research and worry. As the global community grapples with swift urbanization,
population expansion, and economic progress, the effects on natural ecosystems are becoming
more evident. A crucial element of this impact is the alteration of vegetation cover, which plays a
significant role in maintaining the ecological equilibrium of our planet.Land serves as the foundation for all human activities and provides the necessary materials for
these activities. As the most crucial natural resource, its utilization by humans results in different
'Land uses,' which are determined by both human activities and the physical characteristics of the
land.
The utilization of land is impacted by human needs and environmental factors. In countries
like India, rapid population growth and the emphasis on extensive resource exploitation can lead
to significant land degradation, adversely affecting the region's land cover.
Therefore, human intervention has significantly influenced land use patterns over many
centuries, evolving its structure over time and space. In the present era, these changes have
accelerated due to factors such as agriculture and urbanization. Information regarding land use and
cover is essential for various planning and management tasks related to the Earth's surface,
providing crucial environmental data for scientific, resource management, policy purposes, and
diverse human activities.
Accurate understanding of land use and cover is imperative for the development planning
of any area. Consequently, a wide range of professionals, including earth system scientists, land
and water managers, and urban planners, are interested in obtaining data on land use and cover
changes, conversion trends, and other related patterns. The spatial dimensions of land use and
cover support policymakers and scientists in making well-informed decisions, as alterations in
these patterns indicate shifts in economic and social conditions. Monitoring such changes with the
help of Advanced technologies like Remote Sensing and Geographic Information Systems is
crucial for coordinated efforts across different administrative levels. Advanced technologies like
Remote Sensing and Geographic Information Systems
9
Changes in vegetation cover refer to variations in the distribution, composition, and overall
structure of plant communities across different temporal and spatial scales. These changes can
occur natural.
Walmart Business+ and Spark Good for Nonprofits.pdfTechSoup
"Learn about all the ways Walmart supports nonprofit organizations.
You will hear from Liz Willett, the Head of Nonprofits, and hear about what Walmart is doing to help nonprofits, including Walmart Business and Spark Good. Walmart Business+ is a new offer for nonprofits that offers discounts and also streamlines nonprofits order and expense tracking, saving time and money.
The webinar may also give some examples on how nonprofits can best leverage Walmart Business+.
The event will cover the following::
Walmart Business + (https://business.walmart.com/plus) is a new shopping experience for nonprofits, schools, and local business customers that connects an exclusive online shopping experience to stores. Benefits include free delivery and shipping, a 'Spend Analytics” feature, special discounts, deals and tax-exempt shopping.
Special TechSoup offer for a free 180 days membership, and up to $150 in discounts on eligible orders.
Spark Good (walmart.com/sparkgood) is a charitable platform that enables nonprofits to receive donations directly from customers and associates.
Answers about how you can do more with Walmart!"
Chapter wise All Notes of First year Basic Civil Engineering.pptxDenish Jangid
Chapter wise All Notes of First year Basic Civil Engineering
Syllabus
Chapter-1
Introduction to objective, scope and outcome the subject
Chapter 2
Introduction: Scope and Specialization of Civil Engineering, Role of civil Engineer in Society, Impact of infrastructural development on economy of country.
Chapter 3
Surveying: Object Principles & Types of Surveying; Site Plans, Plans & Maps; Scales & Unit of different Measurements.
Linear Measurements: Instruments used. Linear Measurement by Tape, Ranging out Survey Lines and overcoming Obstructions; Measurements on sloping ground; Tape corrections, conventional symbols. Angular Measurements: Instruments used; Introduction to Compass Surveying, Bearings and Longitude & Latitude of a Line, Introduction to total station.
Levelling: Instrument used Object of levelling, Methods of levelling in brief, and Contour maps.
Chapter 4
Buildings: Selection of site for Buildings, Layout of Building Plan, Types of buildings, Plinth area, carpet area, floor space index, Introduction to building byelaws, concept of sun light & ventilation. Components of Buildings & their functions, Basic concept of R.C.C., Introduction to types of foundation
Chapter 5
Transportation: Introduction to Transportation Engineering; Traffic and Road Safety: Types and Characteristics of Various Modes of Transportation; Various Road Traffic Signs, Causes of Accidents and Road Safety Measures.
Chapter 6
Environmental Engineering: Environmental Pollution, Environmental Acts and Regulations, Functional Concepts of Ecology, Basics of Species, Biodiversity, Ecosystem, Hydrological Cycle; Chemical Cycles: Carbon, Nitrogen & Phosphorus; Energy Flow in Ecosystems.
Water Pollution: Water Quality standards, Introduction to Treatment & Disposal of Waste Water. Reuse and Saving of Water, Rain Water Harvesting. Solid Waste Management: Classification of Solid Waste, Collection, Transportation and Disposal of Solid. Recycling of Solid Waste: Energy Recovery, Sanitary Landfill, On-Site Sanitation. Air & Noise Pollution: Primary and Secondary air pollutants, Harmful effects of Air Pollution, Control of Air Pollution. . Noise Pollution Harmful Effects of noise pollution, control of noise pollution, Global warming & Climate Change, Ozone depletion, Greenhouse effect
Text Books:
1. Palancharmy, Basic Civil Engineering, McGraw Hill publishers.
2. Satheesh Gopi, Basic Civil Engineering, Pearson Publishers.
3. Ketki Rangwala Dalal, Essentials of Civil Engineering, Charotar Publishing House.
4. BCP, Surveying volume 1
Communicating effectively and consistently with students can help them feel at ease during their learning experience and provide the instructor with a communication trail to track the course's progress. This workshop will take you through constructing an engaging course container to facilitate effective communication.
Gender and Mental Health - Counselling and Family Therapy Applications and In...PsychoTech Services
A proprietary approach developed by bringing together the best of learning theories from Psychology, design principles from the world of visualization, and pedagogical methods from over a decade of training experience, that enables you to: Learn better, faster!
2. PLSQL
Features:
Supports to execute a block of commands as a unit.
Supports variables and constants.
Supports conditional constructs.
Supports iteration control statements.
Supports error handling.
Supports to define composite data types.
Supports to execute the code automatically based on the event threw data base triggers.
Supports to store and shared the code using subprograms.
PLSQL Block:
It is an collection of sql & program language statements.
There are 2 types.
1. Anonymous block
Name less block
Temporary block
Syntax:- Declare
<variable decl>
Begin
<exec stmts>;
End;
2. Named Block
Block with fixed name.
Stored permanently in database
Ex:- Subprograms.
Variable declaration:
All sql data types are supported.
Boolean is supported.
Declare
Veno number(4):=7900;
Vename varchar2(90);
Vjob varchar2(90) NOTNULL :=’CLERK’;
Doj date default sysdate;
Flag Boolean:= TRUE;
Pin constant number(6):=500038;
:= Assignment operator
= Comparission operator
Executable Statements:
DML and TCL are not valid.
DDL and DCL are not allowed.
Page 2 of 54
3. PLSQL
Select ----- into statement.{ Used to retrieve data into Plsql variables.}
Select <column list> into <variables> from <table name>
Where <condition>;
Used to print message & variables contents onto screen.
DBMS_OUTPUT.PUT_LINE(‘message Text’ || Variables);
Comments
--Comment line
/*Multi Line
Comment*/
Activates the DBMS stmt output buffer.
>set server output on;
Ex: Plsql Program retrieves the employ details and calculates the net salary and prints.
Declare
Veno number(4):=3400; or &employ;
Vname varchar2(90);
Vsal number(12,2);
Vcomm number(12,2);
Net number(12,2);
Begin
--Retrieve data from table.
Select ename, sal, comm. Into vname, vsal, vcomm from emp
Where empno=veno;
--Calculated net salary
Net:= vsal+nvl(comm., 0);
Dbms_output.put_line(‘employ details are:’||veno||’’||vename||’’||net);
End;
/
To save to local system(.sql file)
Save <filename>
To display the file
Get filename
To open the file in editor
Ed filename
To execute the file
Start filename or @filename
Page 3 of 54
4. PLSQL
Attribute Declaration:
Used to define the Plsql variables dynamically according to the table structure.
1. %Type:
Column type declaration.
Used to define the variables according to the specific column structure.
Syntax: variable <tablename>.<columnname>%type;
Ex: Declare
--using %type declaration
Veno emp.empno%type := &employ;
Vsal emp.sal%type;
Vcomm emp.comm%type;
Net emp.sal%type;
2. %Rowtype:
Record type declaration
Used to define the variables according to the complete table structure.
Syntax: variable <tablename>%rowtype;
Ex: declare
--using %Rowtype declaration.
I emp%rowtype;
Net number(19,9);
Begin
i.empno :=&empno;
select ename, sal, comm. Into i.ename, i.sal, i.comm from emp
where empno = i.empno;
net:= sal+nvl(comm., 0);
dbms_output.put_line(‘Employ details are:’||i.empno||’’||i.ename||’’||net);
end;
/
Page 4 of 54
5. PLSQL
Conditional Constructs:
Used to check for multiple conditions while manipulating data in plasql
1. If
2. case(8i)
1. Simple If
If <condition 1> then
<exec stmts>;
Elsif <cond 2> then
<exec stmts>;
--
--
Else < exec stmts>;
End if;
Ex: Plsql block checks for existing new comm. And assign new comm..
Declare
Veno emp.empno%type := &employ;
Vname emp.ename%type;
Vcomm emp.comm%type;
Begin
Select ename, comm. Into vname, vcomm from emp
Where empno = veno;
If vcomm is null then
Vcomm :=3000;
Elsif vcomm = 0 then
Vcomm :=2500;
Else vcomm := vcomm+vcomm*.25;
Endif;
Update emp set comm.= vcomm wehre empno = veno;
Dbms_output.put_line(veno||’’||vname|’’||vcom);
Commit;
End;
/
2. Case(8i) :
o Used to check for multiple conditions easily.
o It will check for equality condition.
o It can be used in “select” statement
Syntax:
1. Case <variable>
When <value1> then
<exec stmts>;
When <value2> then
<exec stmts>;
--
--
Page 5 of 54
6. PLSQL
--
Else <exec stmts>
End case;
2. Case
When <cond1> then <value1>
When <cond2> then <value2>
Else <value>
End case;
Using case construct:
Ex:
Declare
Grade char(1):=’&grade’;
Begin
Case grade
When ‘A’ then
Dbms_output.put_line(‘Grade is A’);
When ‘B’ then
Dbms_output.put_line(‘Grade is B’);
When ‘C’ then
Dbms_output.put_line(‘Grade is C’);
Else
Dbms_output.put_line(‘Grade is C’);
End case;
End;
/
Case in select:
select empno, ename, sal, job,
case
when job = ‘CLERK’ then ‘C’
when job = ‘salesman’ then ‘B’
when job in (‘Manager’, ‘Analyst’) then ‘B+’
when job = ‘President’ then ‘A’
else ‘D’
end “Grade”
from emp;
--It is used to generate reports.
Page 6 of 54
7. PLSQL
Iteration control statements: (LOOPS)
Supports to execute a block of stmts until conditions are true.
4 types:
1. simple loop
2. while loop
3. numeric for loop
4. cursor for loop
1. Simple Loop:
It is an infinite loop block.
Syntax: Loop
<exec stmts<;
End loop;
To break simple loop :
o Exit when(cond);
o If(cond) then
Exit;
End if;
Ex: --Prints first 10 numbers onto screen
Declare
A number(3):= 1;
Begin
Dbms_output.put_line(‘The numbers are:’);
Loop
Dbms_output.put_line(‘a’);
A := a+1;
Exit when (a > 10);
End loop;
Dbms_output.put_line(‘End of numbers’);
End;
/
2. While Loop:
It is an pre-tested loop.
Syntax: While (cond)
Loop
<exec stmts>;
End loop;
Ex: Declare
A number(3):=1;
Begin
Dbms_output.put_line(‘The numbers are:’);
While (a<=10) loop
Dbms_output.put_line(‘a’);
Page 7 of 54
8. PLSQL
A := a+1;
End loop;
Dbms_output.put_line(‘End of numbers’);
End;
/
3. Numeric For Loop:
It increments the variable by 1 always.
Variable can’t be assigned with a value in for loop.
Syntax: For <var> in [reverse] <value1>..<value2>
Loop
<Exec stmts>;
End loop;
<var> –Automatically defined by for loop.
Reverse(optional) –Accepts values in reverse order
.. –Range operator
Ex: Begin
Dbms_output.put_line(‘The numbers are:’);
For n in 1..10
Loop
Dbms_output.put_line(n);
End loop;
Dbms_output.put_line(‘end of numbers);
End;
Dbms_output.put : prints the results in same line.
Dms_output.put_line : prints the result in new line.
Put_line must be followed with “put” stmt to activate output
buffer.
4. Cursor For loop:
Used to perform cursor operations automatically
Improves performances
Syntax:
For <var> in <cur name>
Loop
<exec stmts>;
End loop;
Advantages:
No need to open cursor
No need to fetch rows
No need to check for end of rows
No need to close cursor
No need to declare variables
Ex: Declare
Cursor c2 is select * from dept;
Begin
For I in c2
Page 8 of 54
10. PLSQL
CURSORS:
It is a temporary buffer used to hold the transaction data for manipulation purpose.
It is not stored in database.
It is not re-usable.
It is valid in Plsql block only.
It is created in logical memory only.
2 types
A. implicit cursors:
Automatically defined by oracle whenever “DML” operations are performed by user.
It has a fixed name “SQL”
It gives the status of DML statements in Plsql block.
It will not support cursor operations.
It supports %found, %nofound, %rowcount, attributes.
Ex: TO update only 5 employees
Declare
Vdno number(2) := &dno;
Begin
Update emp set sal = sal+1000 where deptno = vdno;
If sql%notfound then
Dbms_output.put_line(‘Unable to update rows –No such dept exists’);
Elsif sql%rowcount > 5 then
Dbms_output.put_line(‘ Invalid operation –Can’t update more than 5 employees’);
Rollback;
Else
Dbms_output.put_line(sql%rowcount||’ employees are updated successfully’);
Commit;
End if;
End;
/
B. Explicit cursors:
Created by user in Plsql block used to retrieve multiple rows into Plsql block for
manipulation purpose.
1. Declaring cursor:
Syntax :
cursor <cur name> is <select stmt>;
2. Cursor Operations:
i. Open cursor:
Open <cur name>;
Used to open the cursor.
Memory will be allocated to cursor after opening it.
Page 10 of 54
11. PLSQL
ii.Fetch Cursor:
Fetch <cur name> into <var’s>;
Used to retrieve data from cursor to Plsql variables.
At a time it can retrieve only one row into variables
Generally fetch will be placed in loop
iii.Close Cursor:
close <cursor name>;
Used to close the cursor.
Memory allocated will be de-allocated.
3. Cursor Attributes:
Gives the status of cursor
<cur name>%<attribute>
i. %isopen (Returns true/false)
Returns True if cursor is opened successfully
ii. %found (Returns true/false)
Returns True if fetch stmt successfully retrieves the into Plsql var’s.
iii. %notfound (Returns true/false)
Returns true if fetch stmt fails to retrieve the row into Plsql var’s.
iv. %rowcount (Returns true/false)
Returns the no of rows successfully retrieved from cursor so far. Initially it holds
0.
After every successful fetch it is incr by 1.
Ex-1: Declaring cursor var with %Type
Declare
Cursor c1
Is
Select empno, ename, comm. From emp
Order by deptno;
Veno emp.empno%type;
Vname emp.ename%type;
Vcomm emp.sal%type;
Begin
Open c1;
If c%isopen then
Dbms_output.put_line(‘EMP NEW COMM’);
LOOP
Fetch c1 into veno, vname, vcomm;
Exit when c1%notfound;
If vcomm is null then
Vcomm := 3000;
Elsif vcomm = 0 then
Vcomm := 2500;
Else vcomm := vcomm+vcomm*.25;
Endif;
Update emp set comm.= vcomm where empno = veno;
Page 11 of 54
12. PLSQL
Dbms_output.put_line(veno||vname||vcomm);
End loop;
Dbms_output.put_line(c1%rowcount||’Employees are updated with new comm’);
Close c1;
Commit;
Else dbms_output.put_line(‘Unable to open cursor’);
End if;
End;
/
Declaring cursor var with rowtype.
Ex-2: Declare
Cursor c2
Is select * from dept;
I c2%rowtype;
Begin
Open c2;
Loop
Fetch c2 into I;
Exit when c2%notfound;
Dbms_output.put_line(c2%rowcount||’’||i.deptno||’’||i.dname||’’||i.loc);
End loop;
Close c2;
End;
Cursor with Scalar query:
Ex1: Declare
Cursor c2
is
select eno, ename, sal ,job,
(select min(sal) from emp where job = e.job) lopay,
(select max(sal) from emp where job = e.job) hipay,
from emp E order by job;
Begin
For k in c2
Loop
Dbms_output.put_line(k.eno||’’||k.job||’’||k.ename||’’||k.sal||’’||k.lopay||k.hipay);
End loop;
End;
/
Ex2: Calculate bonus for first 10 lowest employees.
Declare
Cursor c1
Is
Select eno, ename, sal, sal+nvl(comm., 0) net, job from emp
Order by sal;
I c1%rowtype;
Page 12 of 54
13. PLSQL
Bonus emp.sal%type;
Begin
For I in c1
Loop
If i.job = ‘CLERK’
Then bonus:= round(i.net*.25);
Elsif i.job = ‘EXECUTIVE’
Then bonus := round(i.net*.50);
Else then
Bonus := round(i.net*.1);
End if;
Dbms_output.put_line( i.eno||’’||i.ename||’’||i.job||’’||bonus);
Exit when(c1%rowcount >= 10);
End loop;
End;
/
Cursor with Parameters(8.0):
Used to accept the input dynamically while opening the cursor.
Supports to define generalized cursor.
Maximum 32 parameters can be passed to cursor.
Ex-1: Calculates incr for employees depending on experience for particular dept only.
Declare
Cursor c1(dno number)
Is
Select * from emp
Where deptno = dno;
I c1%rowtype;
Incr number(12);
Expr number(2);
Begin
Open c1(&dno);
Loop
Fetch c1 into i;
Exit when c%notfound;
Net := i.sal + nvl(comm., 0);
Expr := round(months_between(sysdate, i.hiredate))/12);
If expr <=2
Then incr := net*.25;
Elsif expr<=5
Then incr := net*.5;
Else incr := net*.1;
End if;
Update emp set sal := sal+incr where eno = i.eno;
Page 13 of 54
14. PLSQL
Dbms_output.put_line(i.eno||’’||e.job||’’||expr||incr||i.deptno);
End loop;
Close c1;
End;
/
EX-2 :
Cursor c2(dno number, vjob varchar2)
Is select * from emp
Where deptno = dno and job = vjob;
Open c2(30, ‘clerk’);
For I in c2(20, ‘salesman’) loop
Ex-3:
Cursor c3(vcourse varchar2, vtime varchar2)
Is select * from student
where course = vcourse and timing = vtime;
open c3(‘oracle 9i’, ’10AM’);
for I in c3(‘oracle 9i’, ‘6PM’);
EX-4:
Cursor c4
Is select * from student
Where course = &course’;
It is valid in oracle sql environment.
Cursor parameters are used to pass values from other
application s/w tools.
Page 14 of 54
15. PLSQL
EXCEPTIONS:
Errors in Plsql block are termed as exceptions.
Error handling solutions are provided in exception block.
3 types…
1. Pre defined exceptions
Defined by oracle
Activated by oracle automatically.
Solution provided by user.
No_data_found:
Automatically activated whenever select stmt fails to retrieve data into
variables.
Too_many_rows:
Automatically activated whenever select stmt retrieves more than one row into
variables.
Value_Error:
Automatically activated whenever data types are not matching.
Zero_divide:
Automatically activated whenever invalid arithmetic operations is performed
(no/zero).
Dup_val_on_index:
Automatically activated whenever duplicate values are inserted into unique
index column.
Storage_error:
Automatically activated whenever there is lack of memory in server.
Invalid_cursor:
Automatically activated whenever user fetch the rows from cursor without
opening the cursor.
Time_out_on_resoursces:
Automatically activated whenever user performs an infinite loo process.
Transaction_backed_out:
Automatically activated whenever there is an communication problem with
server.
Login_denied:
Automatically activated whenever user name or pwd are not valid.
Cursor_already_open:
Automatically activated whenever user opends the cursor which is already in
open state.
Others:
General exception
Used to handle any pre-defined exception.
It will not support non-predefined/user defined exceptions.
Pseudo columns activated by other exception.
It must be last exception in exception block.
SQLCODE: Holds the currently raised error no.
SQLERRM: Holds the currently raised error message.
Page 15 of 54
16. PLSQL
2. User defined exceptions
Defined by user.
Activated by using “RAISE” stmt.
Solution provided by user.
Ex: Plsql block handles diff types of errors.
Declare
Veno emp.eno%type := &employ;
Vname emp.ename%type;
Vsal emp.sal%type;
Salary_missing exception; --Declaring user defined excep
Begin
Select ename, sal into vname, vsal from emp
Where eno = veno;
If vsal is null then
Raise salary_missing; --Activating user defined excep
Else
vSal := vsal + vsal * .5
Update emp set sal = vsal where eno = veno;
Dbms(‘salary updated for’||veno||’is’||vsal);
Commit;
End if;
When no_data_found then
Dbms_output.put_line(‘No such emp found’||veno);
when too_many_rows then
dbms_output.put_line(‘More than one emp found for’||veno);
when salary_missing then
dbms_output.put_line(‘Emp has null salary –providing default pay’);
update emp set sal=5000 where eno= veno;
commit;
when others then
dbms_output.put_line(‘Error occurred’);
dbms_output.put_line(sqlcode||’’||sqlerrm);
end;
/
3. Non pre-defined exceptions (undefined exceptions)
Defined by user.
Activated automatically by constraints.
Solution provided by user.
Used to handle constraint violation of errors in Plsql.
Ex: Handling foreign key constraint error.
Declare
Vdno number(2) := &dno;
Employ_exists exception;
Page 16 of 54
17. PLSQL
Pragma exception_init(employ_exists, -2292);
Begin
Delete from dept where dno = vdno;
Commit;
Exception
When employ_exists then
Dbms_output.put_line(‘ Emp are still working –can’t remove dept’);
End;
/
EXCEPTION_INIT(Exception_name, Error_no);
Built-in sub-pgm used to provide exception name to the
constraint violation error
EXCEPTION PROPAGATION:
Declare
-------
-------
Begin
-------
-------
Begin
------- ERR
-------
-------
Exception
-------
-------
-------
Solution End; No Solution
-------
-------
Exception
------- Sol No sol
------- Quit with error
------- Quit with success
End;
/
Page 17 of 54
18. PLSQL
PRAGMA:
It is an special instruction to Plsql to execute sub program in declaration section.
DEPT EMP
-- --
-- --
Deptno(PK) eno
Deptno(FK)
Constraint violation error no’s:
-00001 Unique
-1400 Not null
-2290 Check
-2291 Parent not exists(ref)
-2292 Child records exists(ref)
EX-1: create table std_inf(roll number(4), name varchar2(90), course varchar2(20) check( course in
(‘oracle 9i’, ‘unix’, ‘D2k’)), fee number);
Insert into std_inf values( 101, ‘Sai’, ‘java’, 2300);
PLSQL block handling check constraint error
Declare
Invalid_course exception;
Pragma exception_init(invalid_course, -2290);
Begin
Insert into std_inf values(101, ‘Sai’, ‘java’, 2300);
Commit;
Exception
When invalid_course then
Dbms_output.put_line(‘ student course must be oracle 9i or unix or d2k’);
End;
/
EX-2: Using nested blocks, cursors with lock and exceptions.
Create table itemmast(itno number(2), name varchar2(90), qoh number(4), rol number(5));
Insert into itemmast values(&1, ‘&2’, &3, &4);
Create table ittran(itno number(4), tran_type char(1) [I-Issue(-), R-Receipts(+)], qty
number(5), updt char(1));
Insert inot ittran values(&1, ‘&2’, &3, ‘&4’);
Declare
Cursor tran is select into, tran_type, qty from ittran where upper(updt) = ‘N’
for update;
Cursor item is select * from itemmast;
Vname varchar2(20);
Vqoh number(4);
--cursor with lock
Page 18 of 54
19. PLSQL
Begin
For I in tran loop
Begin --nested loop
Select name, qoh into vname, vqoh from itemmast
Where itno = i.itno;
Exception
When no_data_found then
Dbms_output.put_line(‘no such item exists with itno’||itno);
End;
If i.tran_type = ‘R’ then
Vqoh := vqoh + i.qty;
Elsif i.tran_type = ‘I’ then
Vqoh := vqoh – i.qty;
End if;
Update itemmast set qoh = vqoh where itno = i.itno;
Update ittran set updt= ‘Y’ where CURRENT OF TRAN;
End loop;
Commit;
Dbms_output.put_line(‘Stock Report’); For k in
item loop
Dbms_output.put_line(k.itno||’’||k.name||’’||k.qty);
End loop;
Exception
When others than
Dbms_output.put_line(sqlcode||’’||sqlerrm);
End;
FOR UPDATE:
Locks the rows retrieved into cursor
WHERE CURRENT OF: Clause (8.0)
Used to locate the current row manipulated by
cursor
To use this cursor must be locked
Page 19 of 54
20. PLSQL
Composite data types: [User defined data types]
Defined by the user.
Valid in Plsql block only.
They are not stored in the database permanently.
They will not hold data.
They are not re-usable.
This will improve performance of oracle while retrieving or manipulating huge loads of data
into Plsql blocks.
2 types…
1. PLSQL Records:
It is an collection of elements of “different data types” stored at one location.
It is similar to “C Prog” structures.
Syntax:
Type <record name> is record
(element1 <datatype>,
Element2 <datatype>,
…..
Elementn <datatype>);
EX:
Declare --declaring Plsql record.
Type erec is record(eid number(4), name emp.ename%type, basic emp.sal%type, da
emp.sal%type, hra emp.sal%type, e.pf emp.sal%type, gross emp.sal%type);
E erec; --record type variable
Begin
e.eid:= &employ;
select ename, sal into e.name, e.basic from emp
where empno = e.eid;
e.da := e.basic*.24;
e.hra:= e.basic*.15;
e.pf:= e.basic*.15;
e.gross := e.basic+e.da+e.hra-e.pf;
dbms_output.put_line(e.eid||’’||e.name||’’||e.basic||’’||e.pf||’||e.gross);
end;
2. PLSQL Tables:
It is an collection of elements of same datatype stored in continous memory locations.
It is similar to “C Prog” arrays.
It is supported with an index automatically.
Syntax:
Type <table_name> is table of
<datatype> index by binary_integer;
Page 20 of 54
21. PLSQL
EX:
Declare --declaring Plsql tables.
TYPE names IS TABLE OF emp.ename%type
INDEX BY BINARY_INTEGER;
TYPE pays IS TABLE OF emp.sal%type
INDEX BY BINARY_INTEGER;
N names;
P pays;
Totsal number(12) := 0;
Ctr number(9):=1;
Begin --filling tables
For I in (select ename, sal from emp) loop
N(ctr):= i.ename;
P(ctr):=i.sal;
Ctr:= ctr+1;
End loop;
--printing table contents
For k in 1..n.count loop
Dbms_output.put_line(n(k)||’’||p(k));
Totsal:= totsal + p(k);
End loop;
Dbms_output.put_line(‘Total Salary is :’||totsal);
End;
N.COUNT : Gives no of elements in Plsql table
Page 21 of 54
22. PLSQL
Nested records and Plsql tables using records:
Declare
Type pf_rec is record(pfno number(9), amt number(12,2));
--Nested record
Type erec is record(eid number(9), name emp.ename%type, basic emp.sal%type, job
emp.job%types, pf pf_rec);
Type etab is table of erec
Index by binary_integer;
Ctr number(3):=1;
E etab;
Begin
--plsql table using nested records.
For I in (select empno, ename, sal, job from emp) pf.rec
Loop
E(ctr).eid := i.empno; erec
E(ctr).name := i.ename;
E(ctr).job := i.job; etab
E(ctr).pf.pfno := i.empno+1000;
E(ctr).pf.amt := round(i.sal * .15);
Ctr := ctr + 1;
End loop;
--printing table contents
Dbms_output.put_line(‘employee pay details are:’);
For k in 1..e.count
Loop
Dbms_output.put_line(e(k).eid||’’|| e(k).name||’’|| e(k).basic||’’|| e(k).job||’’||
e(k).pf.pfno||’’|| e(k).pf.amt);
End loop;
End;
/
Page 22 of 54
23. PLSQL
DATABASE TRIGGERS:
A set of Plsql stmts stored permanently in database and automatically activated whenever
an event raising stmt (DML) is preformed.
They are stored in user_triggers system table.
They are use to impose business rules/user defined restrictions on table.
They are also activated when tables are manipulated by either users or by other
application s/w tools.
They provide high security on tables.
TCL commands are not allowed in triggers.
Trigger parts:
1. Triggering even:
Indicates when to activate the trigger.
Before – insert/update/delete
After – insert/update/delete
2. Trigger types:
a. Row trigger:
Activates the trigger for every row manipulated by DML stmt.
b. Stmt trigger:
Activates the trigger for only once for 1 DML stmt (Default type).
3. Trigger restriction:
Used to stop the activation of trigger based on condition. If condition is true trigger is active.
4. Trigger Body:
A set of Plsql stmts.
Syntax:
Create or replace TRIGGER <trigger_name>
Before/after insert or update or delete (1)
[of <columns>] on <table_name>
[for each row (2)
When (<condition>) (3)
Declare
<var declaration>; ]
If condition is
true trigger is
activated
Begin
<exec stmts>;
[Exception
<exec stmts>;]
End;
Page 23 of 54
24. INSERT UPDATE DELETE
NEW valid valid invalid
OLD invalid valid valid
PLSQL
EX: Trigger converts student name to upper case automatically.
Create ore replace trigger up_con before insert on stu_info
For each row
Begin
:new.sname := upper(:new.sname);
End;
Triggering Events:
12 Events per table are allowed.
NEW & OLD (pseudo columns):
Used to retrieve data from DML stmt
tempory buffer.
Valid with “ROW” triggers only.
Before insert row before update row before delete row
Before insert stmt before update stmt before delete stmt
After insert row After update row After delete row
After insert stmt After update stmt After delete stmt
EX: Trigger checks fro valid increment.
Create or replace trigger valid_incr
Before update of sal on emp
For each row
Begin
If :new.sal <= :old.sal then
Column specification is supported with
update event only. Not valid with insert
and delete. operations(Row level
operations)
Raise_application_error(-20300, ‘Incr must be more than existing salary’;
End if;
End;
/
Raise_application_error(error no, error message);
Built in subprogram stops DML stmt execution and
displays the error message.
Error_NO range: -20002 to -20990
Oracle Reserved error no’s: -20000 to +20000
Page 24 of 54
25. PLSQL
Constraints vs Triggers:
Constraint provide standard error message.
Triggers provide user friendly error message.
Constraints will for existing errors.
Triggers will not check for existing errors.
If constraint & trigger are defined on table, one time only trigger will be activated.
Ex: Trigger checks for valid salary according to the job.
Create table job_pays(job varchar2(20), losal number(10), hisal number(10));
Create or replace trigger chk_sal Before insert on emp for each
row When(new.job<>’PRESIDENT’) --If true trigger is
activated Declare
Minsal number(10);
Maxsal number(10);
Begin
Select losal, hisal into minsal, maxsal from job_pays
Where job =:new.job;
If :new.sal>maxsal and :new.sal<minsal then
Raise_application_error(-20201, ‘salary must be between’||maxsal||’and’||minsal||’for
job’||:new.job);
End if;
Exception
When no_data_found then
Raise_application_error(-20202, ‘No data found for dept’||:new.job);
End;
/
EX: Trigger adds the fee installment amt automatically into fee installments table
Create fee_installments(roll number(9), prev_fee number(9), curr_fee number(9), dop
date);
Create or replace trigger add_fee
Before update or insert on student
For each row
Begin
If inserting then
Keywords: Inserting, updating, deleting
Represents insert, update, delete operations.
Valid in triggers only
Insert into fee_installments values(:new.roll, :new.fee, :new.fee, sysdate);
Elsif updating then
Insert into fee_installments values(:old.rol, :old.fee, :new.fee - :old.fee, sysdate);
End if;
End;
/
Page 25 of 54
26. PLSQL
Statement level triggers:
Trigger locks the table for DML operations to provide security.
Trigger checks for
o Valid timings
o Weekends
o Public holidays
Ex:
Create or replace trigger security_chk
Before insert or update or delete on bankmaster
Declare
A number;
Begin
--check for valid timings.
If to_char(sysdate, ‘hh24’) not in (10,11,12,13,14,15,16,17,18) then
Raise_application_error(-20111, ‘No operations allowed –invalid timings’);
End if;
--check for week ends.
If to_char(sysdate, ‘dy’) in (‘sat’,’sun’) then
Raise_applicaiton_error(-20112, ‘No operations allowed –week ends’);
End if;
--check for public holidays
Select count(*) into a from holiday where to_date(hdate) = to_date(sysdate);
If a>0 then
Raise_application_error(-20113, ‘No operations allowed –public holidays’);
End if;
End;
/
Instead of triggers:
Triggers supported only on “views”
Used to perform DML operations on “join views”
Instead of ----insert, update, delete
EX:
Create view edept
As
Select empno, ename, job, sal, emp.dtno, dept.dtno dno, dname, loc from emp, dept
Where emp.dno = dept.dno;
Create trigger T1 instead of insert on edept
For each row
Begin
Insert into dept values(:new.dno, :new.dname, :new.loc);
Insert into emp(empno, ename, sal, job, dtno) values(:new.empno, :new.ename, :new.sal, :new.job,
:new.dtno);
End;
Page 26 of 54
27. PLSQL
Disabling triggers:
Alter table <table_name> disable all triggers;
Enabling triggers:
Alter table <table_name> enable all triggers;
Removing triggers:
Drop trigger <trigger_name>;
Checking for existing triggers:
Desc user_triggers;
Select trigger_name, trigger_event from user_triggers
Where table_name = ‘emp’;
Select * from user_triggers
Where trigger_name = ‘chk_sal’
Create trigger T2
Before insert on temp for each row
Begin
Update temp set c2 = ‘HARI’;
End;
--It will not perform update in trigger body because 2 DML operations can’t
be performed on table at once
--It leads to a trigger mutation error while working in other s/w tools.
Page 27 of 54
28. PLSQL
SUBPROGRAMS:
A set of Plsql stmts stored permanently database and used to perform a task.
They can accept input from user as arguments dynamically.
They are stored in “user_source” system table.
They are reusable components.
They can be shared with other users.
They can be used n other application s/2 tools.
They are faster in execution stored n compiled formed.
They support modularity.
2 types…
1. Procedures
2. Functions
A huge task divided into
N no of sub tasks. Easy to
manage the logic easy to
debug errors.
1.Procedures:
A sub prg type performs a task and will return a value.
Generally procedures are used to perform DML operations on database.
They can’t be called in SELECT stmt.
Procedure can be used in sql, other application s/w tools, Plsql triggers
procedures, functions, packages, D6i.
Syntax:
Create or replace procedure <p_name> [(arguments MODE <datatype>)]
Is
[<var_declaration>]
Begin
EX:
End;
<exec stmts>;
Calling a procedure: procedure_name(arguments);
Create or replace procedure Sim_ins(p number, n number, r number)
Is
Si number(12);
Begin
Si := (p*n*r)/100;
Dbms_output.put_line(‘simple interest:’||si);
End;
/
SQL: PLSQL:
Desc sim_ins begin
Exec sim_ins(2,3,4); sim_ins(123,12,8.5);
End;
Page 28 of 54
29. PLSQL
2.Functions:
A sub prog type performs a task and will return the value (Return only one value).
Generally functions are used for reporting purpose or for calculating purpose.
They can be called in SELECT stmt.
Function can be used in sql, select, other application tools, Plsql, triggers, procedures,
functions, packages.
Syntax:
Create or replace function <function_name> [(arg’s MODE <datatype>)]
Return <datatype>
Is
[<var declaration>];
Begin
<exec stmts>;
Return (variable);
[Exception
<exec stmts>;]
End;
Calling a function: var := fun_name(arg’s);
EX:
Create or replace function si(p number, n number, r number)
Return number
Is
Si number(9);
Begin
Si := (p*n*r)/100;
Return(round(si));
End;
SQL: PLSQL:
i. Desc si Declare
Select si(1200,8,7) from dual; result number(12);
begin
ii. Variable result number result:=si(1200,9,7);
exec:result:=si(5400, 10, 9.5); dbms_output.put_line(result);
print result; end;
Create table loan_master(cust_id number(4), cname varchare(9), amount number(12),
duration number(3), irate number(5,2));
Insert into loan_master values(&1, ‘&2’, &3, &4, &5);
Select cust_id, upper(cname), si(amount, duration, irate) interest from loan_master;
Page 29 of 54
30. PLSQL
EX-1: Function checks for leap year
Create or replace function chk_year(y number)
Return varchar2
Is
Begin
If mod(y,4) = 0 then
Return(‘leap year’);
Else
End if;
End;
Return (‘ Not leap year’);
Select chk_year(2008), chk_year(2010) from dual;
Variable result varchar2(90);
Exec:result:=chk_year(2012);
Print result;
SET AUTOPRINT ON Automatically prints the variable,
No need to use print stmt.
EX-2: Procedure cal the new comm. For all emp of particular dept.
Create or replace procedure call_comm(vdept number)
Is
Cursor c1
Is
Select empno, ename, comm. From emp
Where deptno = vdept;
I c1%rowtype;
Begin
For I in c1
Loop
If i.comm is null
Then
i.comm :=3000;
elseif i.comm = 0
then
else
end if;
i.comm:=2500;
i.comm = i.comm+i.comm*.25;
update emp set comm. = i.comm where empno = i.empno;
dbms_output.put_line(i.empno||’has been updated comm. For’||i.comm);
end loop;
commit;
end;
Page 30 of 54
31. PLSQL
Desc user_source
Select name from user_source;
To Remove sub prog’s:
Drop procedure <proc_name>;
Drop function <fun_name>;
Create sequence s1 increment by 1 start with 11;
EX-3: Procedure adds a dept into Dept table
Create or replace procedure add_dept
(vname varchar2 default ‘unknown’, vloc varchar2 default ‘hyderabad’)
Is
Begin
Insert into dept values(s1.nextval, vname, loc);
Commit;
End;
Desc add_dept
Exec add_dept;
Exec add_dept(‘sales’, ‘mumbai’);
Exec add_dept(‘export’);
Exec add_dept(vloc => ‘chennai’);
Exec add_dept(vloc=> ‘pune’, vname => ‘software’);
Sharing Sub-Programs:
Scott:
Grant execute on add_dept to user1;
User1:
Desc scott.add_dept
Exec scott.add_dept(‘Testing’);
Named notation:
Arguments are passed
based on their name.
Insert into scott.dept values(22, ‘HR’, ‘sec’); --Error
User can manipulate the
table only through procedure
but not directly.
Parameter modes in sub-programs:
“MODE” indicates the behaviour of argument in sub program
3 types….
1. IN: (default mode)
IN parameter is used to carry the input into subprogram.
It can’t be assigned with a value in subprogram.
Page 31 of 54
32. PLSQL
2. OUT:
OUT parameter is used to return the results from sub program.
It can’t be assigned with a value in sub program
3. IN OUT:
INOUT parameter is used to carry the input and return the results from subprogram.
It can be assigned with a value in subprogram.
EX-1:
Create or replace procedure P1(a in out number)
Is
Begin
A:= A*A*A;
End;
SQL:
Desc p1
Var x2 number;
Exec :x2 := 5; --intialising variable at sql
Exec p3(:x2);
Print x2
EX-2: Calculate factorial for given number and checks for odd/even number.
Create or replace function call_fact( n in number, f out number);
Return Boolean
Is
Fac number(9) :=1;
Begin
For I in 1..n
Loop
Fac := fac * I;
End loop;
-- cal factorial 5! = 5*4*3*2*1 =120
F:= fac; -- storing result in out parameter
If mod(n,2) = 0
Then
Else
End if;
End;
Return(TRUE);
Return(false);
Function returning
“Boolean” value (or) with
OUT parameter can’t be
used in sql or select stmt.
Using “CALL_FACT” function:
Declare
A number(9) := #
Fact number(90);
Begin
Page 32 of 54
33. PLSQL
If call_fact(a, fact)
Then
Else
End if;
Dbms_output.put_line(‘Given number is even’);
Dbms_output.put_line(‘Given number is odd’);
Dbms_output.put_line(‘Factorial of given number is:’||fact);
End;
Triggers vs Programs:
Triggers are automatically activated by DML statements.
Procedures & functions has to be explicitly activated by user.
Advantages:
Code reusability.
Faster execution of code.
Easy to manage code.
Executed in the oracle server memory even if it is activated from other application software
tools.
Page 33 of 54
34. PLSQL
PACKAGES:
It is a collection of related var’s, cursors, procedures and functions.
It is stored in “user_source” system table.
It can be shared with other users.
They will improve performance of oracle while accessing sub programs from client
environment.
They support oops features live encapsulation, data hiding, and function over loading.
2 parts…
i. package specification:
It holds the declaration of variables, cursors, procedures and functions.
Syntax:
Create or replace package Package_name
As
<Var dec>;
Procedure <proc_name>(arg’s datatype);
Functions <fun_name>(arg’s datatype) return datatype;
End <pack_name>;
ii. Package body:
it holds the code of sub program.
Syntax:
Create or replace package body Package_name
As
Procedure <proc_name>(arg’s datatype)
Is
<exec stmts>;
End <proc_name>;
Functions <fun_name>(arg’s datatype) return datatype
Is
<exe stmts>;
End <fun_name>;
End <pack_name>;
Ex-1:
Create or replace package pack1
as
result number(12)
procedure add_num( a number, b number);
function mul_num(x number, y number);
end pack1;
create or replace package body pack1
as
procedure add_num(a number, b number)
is
begin
result := a+b;
Page 34 of 54
35. PLSQL
dbms_output.put_line(‘sum of numbers is:’||result);
end add_num;
function mul_num(x number, y number) return number
is
begin
result := x*y;
return (round(result));
end mul_num;
end pack1;
/
Using package elements:
Exec pack1.add_num(2099, 8908);
Select pack1.mul_num(200,22) from dual;
Select ename, job, pack1.mul_num(sal,.15) pf,
pack1.mul_num(sal, 2) bonus from emp;
EX-2: LOCAL sub program are valid in package body only.
Create or replace package epack
As
Function gross(vsal number) return number;
Function experience(doj date) return number;
End epack;
Create or replace package epack
As
Function pf(vbasic number) return number is
Begin
Return( round(vbasic*.15));
End if;
Function gross(vsal number) return number is
Epf number(12);
Begin
Epf := pf(vsal);
Return (round(vsal+vsal * .25 + vsal*.35 – epf));
End gross;
Function experience (doj date) return number is
Begin
Return (round(months_between(sysdate, doj))/12);
End experience;
End epack;
/
Sub-program not
defined in
specification are local
sub programs. We
can’t call this pgm’s
from outside of
package.
Select empno, ename, job, round(epack.experience(hiredate) experience,
epack.gross(sal) “Gross pay” from emp;
Select ename, epack.pf(sal) “PF” from emp;
Page 35 of 54
36. PLSQL
--ERROR, you can’t call local subprogram.
Package with function overloading feature:
Create or replace package load_pack
As
Function add_data(a number, b number) return number;
Function add_data(a varchar2, b varchar2) return varchar2;
End load pack;
/
Create or replace package load_pack body
As
Function add_data(a number, b number) return number
Is
Begin
Return (a+b);
End add_data;
Function add_data(a varchar2, b varchar2) return number
Is Begin
Return(a||’ ‘||b);
End add_data;
End load_pack;
/
Removing Pack:
Desc load_pack;
Select load_pack.add_data(5,6) total,
load_pack.add_data(‘Satya’, ‘M’) name from dual;
Drop package <pack_name>;
Sharing Pack:
Grant execute on load_pack to user1;
To view existing package body:
Select text from user_source wehre name = ‘pack1’;
Page 36 of 54
37. PLSQL
8.0 Features:
Returning into clause:
o Used to return the values through “DML” stms.
o Used with update and delete stmts.
Ex:
Var a varchar2(20)
Var b number
Update emp set sal = sal+3000 where empno = 7900
Returning ename, sal, into :a, :b;
Print a b
Delete from emp where mepno= 7920
Returning ename, sal into :a, :b;
Print a b
Bulk Collect:
o Used to return bulk data into Plsql variables
o Variables must be of Plsql table type only
o Improves performance while retrieving data.
o Used with select, update, delete, fetch stmts.
Examples:
Using in select stmt:
Declare
Type names table of emp.ename%type
Index by binary_integer;
Type pays table of emp.sal%type
Index by bindary_integer;
N names;
P pays;
Begin
--Retrieving all emp’s in 1 transaction
Select ename, sal bulk collect into N, P from emp;
--Printing table contents
Dbms_output.put_line(‘Employ details are’);
For I in 1..n loop
Dbms_output.put_line(n(i)||’’||p(i));
End loop;
End;
Using in update stmt:
Update emp set sal=sal+3000 where deptno = 30
Returning ename, sal bulk colleck into n,p;
Using in delete stmt:
Delete form emp where job = ‘CLERK’
Returning ename, sal bulk collect into n,p;
Page 37 of 54
38. PLSQL
Using in fetch stmt:
Declare
Type names is table of emp.ename%type
Index by binary_integer;
Type names is table of emp.sal%type
Index by binary_integer;
N names;
P pays;
Cursor c1
is
Select ename, sal into n, p from emp;
Begin
Open c1;
Fetch c1 bulk collect into n,p;
--printing table contents
For I in 1..n count Loop
Dbms_output.put_line(n(i)||’’||p(i));
End loop;
End;
/
Dynamic SQL:
o Supports to execute DDL commands in Plsql block.
Execute immediate(‘DDL stmt’);
EX:
Begin
Execute immediate(‘create table employ(ecode number, ename varchar2(90), sal number));
End;
Begin
Execute immediate(‘drop table employ1’);
End;
NOTE:
Table can’t be manipulated
in same Plsql block.
Using Long and Raw data types:
Long:
o Used to represent numbers or character values
o Maximum limit is 2GB.
o But only once it can be used in table.
Raw(n):
o Used to represent images
o Max limit is 256 bytes(7.0)/2000 bytes (8.0)
Long Raw:
o Used to represent images upto 2 GB.
o Raw and long raw can be manipulated by GUI tools only
Page 38 of 54
39. PLSQL
Ex:
Create table emp(ecode number(3), ename varchar2(20), sal number(12,2), description long,
deptno number(2));
Create table ephoto(ecode number(4), photo long raw);
Create table customer(cust_id number(4), cname varchar2(20), addr varchar2(50), photo
longraw);
File input & output (8.0):
Used to transfer oracle table contents to OS file and OS file content to oracle table.
Standard package holds all functions (arthematic, date, general);
UTL_FILE Built in package supports file operations.
Sub-Programs in UTL_FILE pkg:
Fopen:
Used to open the file in the specified mode and returns the address of the file.
Mode R Read, W Write, A Append
Fclose: Used to close the file
Get_line: Used to read a line from file to Plsql variable.
Put: Used to write a line into file but in New line.
Put_line: Used to write a line into file but in new line.
Fflush: Writes the file content from temporary buffer to physical memory (saving file
into OS)
File_type: Data type
Used to define the variable to hold the address of file.
Invalid_file_handle, Read_error:
Pre-defined exception automatically activated while working with files.
Plsql block transfers data from oracle table to OS file.
Ex: Plsql procedure transfer data from OS file to database table.
Create or replace procedure load_student(pdir varchar2, pfile varchar2)
Is
Vfile utl_file.file_type;
Vtext varchar2(200);
Vname varchar2(20);
Vcourse varchar2(20);
Vfee number(5);
Fcomma number(3);
Scomma number(4);
Begin
Vfile:= utl_file.fopen(pdir, pfile, ‘R’);
Page 39 of 54
40. PLSQL
Loop
Begin
Utl_file.get_line(vfile, vtext);
Exception
When no_data_found then
Exit;
End;
Fcomma := instr(vtext, ‘,’,1,1);
Scomma := instr(vtext, ‘,’, 1,2);
Vname := substr(vtext,1,fcomma,-1);
Vcourse:=substr(vtext, fcomma+1, soma-fcomma);
Vfee := substr(vtext, scomma+1);
Insert into student values(s1.nextval, vname, vcourse, vfee);
End loop;
Commit;
Exception
When utl_fjile.read_error then
Dbms_output.put_line(‘unable to read the file….’);
End;
Exec load_student(‘c:’, ‘student.txt’):
Note: Provide the below parameter in “init.ora” file
(open in notepad)
UTL_FILE_DIR = ‘C:Oracleora92Bin’
Init.ora --system parameter file.
Holds the parameter defined for oracle server.
Page 40 of 54
41. PLSQL
Object Technology(8.0):
Object is a collection of different datatypes stored at one location.
It will not hold data
It can have methods (functions) defined in it.
They are stored permanently in “user_types” system table
They support inheritance feature.
They can be shared with other users.
They are reusable components.
CDT: (composite data type)
Object ‘C’ structure
Object with methods ‘C++’ class
Nested tables
Varying arrays
EX: Plsql records
Plsql tables
Syntax:
Create type <obj name> as object
(element1 <datatype>,
ele 2 <datatype>,
------
Element N <datatype>);
Object types:
2 types…
1. Column object:
Only few columns of table represent objects.
2. Row Object:
Entire table structure depends on object.
Create type etype as object( eid number(9), ename varchar2(90), sal number, deptno
number(9));
Create table etab of etype; Row object
Desc etab = desc etype
Insert into etab values(1001, ‘RAM’, 210,10);
Select * rom etab;
Select eid, ename, sal from etab;
Create table employ(einfo etype, job varchar2(90), hiredate date); Column object
Ex:
Create type addr_type as object (hno varchar2(90), street varchar2(90), city varchar2(90), pin
number(6));
Create type Pf_type as object (pfno number(5), amt number(4));
Desc addr_type;
Desc pf_type;
Select * form user_types;
Page 41 of 54
42. PLSQL
Naming object:
Create table student(roll number(3), sname varchar2(20), address addr_type, course
varchar2(90), fee number(5));
Desc student;
Insert into student values(101, ‘SAI’, addr_type(’12-A’, ‘ameerpet’, ‘Hyd’, 500038), ‘oracle
9i’, 2500);
Select * from student;
Select sname, address from student;
Select sname, s.address.city, s.address.pin from student s;
Update student s set s.address.hno = ‘308A’ where roll=101;
Delete from student s where s.address.city = ‘hyd’;
Objects will not support constraints.
Trigger check for null values in city.
Create trigger city_chk before insert on emp
for each row
begin
if :new.address.hno is null then
Raise_aplication_error(-20100, ‘Student hno can’t be null’);
End if;
End;
Sharing object:
Scott: Grant execute on addr_type to user1;
User1:
Create table supplier(sid number, sname varchar2(90), saddr scott.addr_type);
Select sname s.saddr.city from supplier s
Nested objects: [Max 32 levels]
Create type person_type as object(pname vachar2(20), paddr addr_type);
Desc person_type;
Create table customer(cid number, cinfo person_type);
Select cid, c.cinfo.paddr.city, c.cinfo.paddr.pin from customer c;
Desc customer;
Drop type <obj_name>;
Drop type addr_type;
Drop type pf_type;
Purity level test:
Checks for member functions are having DML stmts or not.
DML are not valid in member functions.
Page 42 of 54
43. PLSQL
Restrict_references: Built-in sub program used to check
for DML stmts in methods
WNDS: Write no database state
Pragma: Instruction to Plsql supports to execute sub
program in declaration section
Object with methods:
Create or replace type etype as object(ecode number, name varchar2(90), basic number(90),
job varchar2(4), hiredate date,
member function gross(vbasic number) return number,
pragma restrict_references(gross, WNDS),
member function experience(doj date) return number,
Pragma restrict_references(experience, WNDS));
Create or replace type body etype as
Member function gross(vbasic number) return number
Is
Begin
End;
Return(round(vbasic+vbasic*.25+vbasic*.35-vbasic*.15));
Member function experience(doj date) return number
Is
Begin
End;
End;
Return(round(months_between(sysdate, doj))/12);
Create table etab of etype; Row object
Insert into etab values(1001, ‘RAM’ 3000, ‘Analyst’, ’10-dec-01’);
Select ecode, name, job, basic, e.gross(basic) “gross”, e.experience(hiredate) “exp in years”
from etab e;
Page 43 of 54
44. PLSQL
Collections(8.0):
A group of similar rows stored at one location.
2 types…
1. Nested table:
Table with in a table
A column holds a table of contents in it.
Ex:
Create type book_type as object (bookid number(4), title varchar2(90), doi date, dor
datae);
Object representing table of books
Create type books is table of book_type;
Create table stu_lib(roll number, name varchar2(90), course varchar2(90), binfo books)
nested table binfo store as book_table;
Desc book_type;
Desc books;
Desc stu_lib;
Insert into stu_lib values(101, ‘RAM’, ‘Oracle 9i’,
books(book_type(11, ‘sql’, sysdate, sysdate+10),
book_type(12, ‘plsql’, sysdate, sysdate+11),
book_type(13, ‘dba’, sysdate, sysdate+15)));
Select * from stu_lib;
Select name, binfo from stu_lib;
Roll Name Course Binfo
101
102
Book id Title Doi Dor
11
12
13
2. Varrying arrays examples:
It is an array of elements stored in a column.
EX:
i. Create type blist is varray(5) of varchar2(25);
--Object representing array of books.
ii. Create table items(itno number, name varchar2(90), brands blist);
iii. Insert into items values(102, ‘Micro-oven’,
blist(‘LG’, ‘ONIDA’, ‘IFB’));
iv. desc blist
desc items
Page 44 of 54
45. PLSQL
v. update items set brands = blist(‘LG’, ‘ONIDA’, ‘IFB’, ‘KENSTAR’,
‘SAMSUNG’) where itno = 102;
vi. select name, brands from items;
BINFO
Roll Name Course Bid Title Doi dor
101 11
12
13
102
Nested table Varray
Stored outside the table Stored with in the table
DML is allowed DML is not allowed
Stores unlimited data stores limited data.
Note:
Collections will not support constraints
Long, raw, lob data types are not valid in
collections.
Collections will not support dev-6i, VB (GUI
tools)
Java supports collections.
DML on nested tables:
THE: Operator is used to perform DML on nested table.
EX:
Inserting a book(only 1 book allowed)
Insert into
THE(select binfo from stud_lib where roll=101)
Values(book_type(15, ‘DBA’, sysdate, sysdate+10));
Changing a book details
Update
Update
THE(select binfo from stu_lib where roll = 101)
Set dor=sysdate+3 where book_id = 12;
THE(select binfo from stu_lib where roll=101)
Set title=’Tuning’ where book_id = 15;
Removing a book info
Delete from
THE(select binfo from stu_lib where roll=101)
Where book_id =12;
Page 45 of 54
46. PLSQL
LOBS – Large Objects(8.0):
Used to represent huge loads of fdata
Max limit is 4 GB
N columns allowed per table
4 types…
1. CLOB – Char Large Object
Used to represent char information upto 4 GB.
2. NCLOB – Native char large object
Used to represent other language text.
*Nchar, Nvarchar2 -- Represents other language test.
3. BLOB – Binary large object
Used to represent images upto 4GB.
4. BFILE – Binary File
Used to hold the address of OS file.
Representing Null values:
CLOB - Empty_CLOB( )
NCLOB- Empty_NCLOB( )
BLOB - Empty_BLOB( )
BFILE - Skip the column while inserting
EX: Create table emp_lob(ecode number, name varchar(90), description CLOB, sal number,
photo BLOB, edocs BFILE);
Making logical dir to insert Bfile value:
DBA > Grant create any directory to scott;
SCOTT > Create directory emp_dir as ‘C:employbonds’;
> Insert into emp_lob values (101, ;’RAM’, ‘………’, 2100, empty_BLOB( ),
Bfilename(emp_dir, ‘e101.doc’));
Built in subprogram
used to represent OS
file details into bfile
> Select ecode, ename, sal, description from emp_lob;
Page 46 of 54
47. PLSQL
Temparary Tables(8i):
Used to hold the information in logical memory but not in physical memory.
They hold the data for a particular period of time but not permanently.
EX-1:
Create global temporary table temp(c1 date) on commit delete rows;
Insert into temp values(sysdate);
Select * from temp; --28-Mar-2012
Commit;
Select * from temp; -- No rows.
EX-2:
Create global temporary table(c1 date) on commit preserve rows;
Insert into temp values(sysdate);
Select * from temp; --28-Mar-2012
Commit;
Select * from temp; --28-Mar-2012
Exit;
Select * from temp; --No rows.
Autonomous Transactions:
Defines the trigger as an independent transaction
Allows TCL commands in triggers.
Syntax:
Create trigger add-incr before insert on incr
For each row
Declare
Pragma autonomous transaction;
Update emp set sal = sal+ :new.amt
Where empno = :new.empno;
Commit;
End;
Select empno, sal from emp;
Insert into incr values(7900, 4000);
Select empno, sal from emp;
--7900 8000
--7900 12000
Select empno, amt from incr;
Rollback;
Select empno, amt from incr;
--7900 4000
--No rows
Select empno, sal from emp; --7900 12000
Page 47 of 54
48. PLSQL
REF CURSORS:
Dynamic Cursors:
Supports to define the cursor without select stmt.
Select stmt will be provided while opening cursor.
Used to send cursor as an parameter in sub programs.
Made easy to transfer huge data through sub programs.
Syntax:
Type <ref cursor name> is ref cursor;
Create Package pack1
as
Type rear is ref cursor;
End pack1;
Procedure returning multiple rows through OUT parameter.
Create or replace procedure get_rows(vdept in number, vcur out pack1.rear)
Is
Begin
Open vcur for select empno, ename, sal, job from emp where deptno = vdept;
End;
Using Procedure:
Declare
scur pack1.rear; vroll
number(9); vname
varchar2(90); vfee
number;
Begin
Open scur for select roll, name, fee from student
Where course = ‘&course’;
Loop
Fetch when scur%not found;
DOPL(vroll||’’||vname||’||vfee);
End loop;
Close scur;
End;
Page 48 of 54
49. PLSQL
9i Features:
9i Joins:
Supports ANSI/ISO standard sql 1999 syntax.
Modularity for application sw tools to understand sql queries.
1. Natural Join
2. Join with using Equi Join (giving same output)
3. Join with ON
4. Inner Join
5. Left Outer Join
6. Right Outer Join
7. Full Outer Join Left outer join union right outer join
8. Cross Join
Select empno, ename, sal, deptno, dname, loc from emp Natural join dept;
Select empno, ename, sal, job, deptno, dname, loc from emp join dept using (deptno);
Select e.empno, e.ename, e.sal, e.job, e.deptno, d.dname, d.loc from emp e join dept d on
(e.deptno = d.deptno);
Select e.empno, e.ename, e.sal, e.job, e.deptno, d.dname, d.loc from emp e Inner join dept d
on (e.deptno = d.deptno);
Select e.empno, e.ename, e.sal, e.job, e.deptno, d.dname, d.loc from emp e left outer join
dept d on (e.deptno = d.deptno);
Select e.empno, e.ename, e.sal, e.job, e.deptno, d.dname, d.loc from emp e right outer join
dept d on (e.deptno = d.depno);
Select e.empno, e.ename, e.sal, e.job, e.deptno, d.dname, d.loc from emp e full outer join
dept don (e.deptno = d.deptno);
Select empno, ename, sal, job, deptno, dname, loc from emp cross join dept;
Date functions:
Systimestamp:
Gives date and time including rational seconds in SERVER time zone.
Current_timestamp:
Gives date and time including fractional seconds in CLIENT time zone.
Sysdate:
Gives only date in server time zone.
Current_date:
Gives only date in client time zone.
Extract:
Used to retrieve a particular value from the given date (day/month/year)
To_timestamp(d):
Converts given date into date and time info with am/pm.
Dbtimezone:
Gives server time zone value
Timestamp: Datatype
Automatically stores date and time information with am/pm
Page 49 of 54
50. PLSQL
Select systimestamp, current_timestamp from dual;
Select sysdate, current_date from dual;
Select dbtimezone from dual;
28-Mar-12 6:50:23 PM
Select extract(day from sysdate),
Extract(month from sysdate),
Extract(year from sysdate) from dual
Create table temp(c1 timestamp);
Insert into temp values(sysdate);
Select * from temp;
28-Mar-12 6:55:29 PM
NVL:
1. NVL(exp1, exp2):
NVL is used to fill Null value with known value.
If exp1 is NULL value then it will take exp2
If(exp1 = null)
Then expr2
Else
Endif;
Expr1;
2. NVL2(exp1, exp2, exp3):
If expr1 is null it manipulates exp3, if exp1 is not null it manipulates expr2
If(exp1 = null)
Then
Expr3
Else
Endif;
Expr2
Page 50 of 54
51. PLSQL
MULTIPLE INSERTS:
Supports to insert into more than 1 table at a time but input must be retrieved from existing
table.
EX: Make 3 empty tables same as dept table.
create table D1 as select * from dept where rownum is null;
create table D2 as select * from dept where rownum is null;
create table D3 as select * from dept where rownum is null;
insert all into D1 values(deptno, dname, loc)
into D2 values(deptno, dname, loc)
into D3 values(deptno, dname, loc)
Select * from dept;
Conditional Insert:
EX-1: Insert all
When (deptno <40) then
Into D1 values(deptno, dname, loc)
When (deptno<90) then
Into D2 values(deptno, dname, loc)
Else
Into D3 values(deptno, dname, loc)
Select * from dept;
EX-2: Insert all
When course = ‘oracle 9i’ then
Into Stu_ora(roll, name, fee)
When course = ‘java’ then
Into stu_java(roll, name, fee)
When course = ‘unix’ then
Into stu_unix values(roll, name, fee)
Select * from student;
MERGE:
Used to compare the 2 table contents them equal.
It supports only update & insert operations.
Ex:
Merge
Into temp t
Using emp e
On (t.tno = e.empno)
When matched then
Update set t.sal = e.sal,
t.comm = e.comm,
t.mgr = e.mgr,
t.deptno = e.deptno
Page 51 of 54
52. PLSQL
when not matched then
insert values(e.empno, e.ename, e.sal, e.com,…
Clauses:
Into --Target
Using --Source
On --join condition
Emp --1 crore rows
Temp --copy of emp -1 crore rows
Emp --5000 inserts & 1000 performed.
Partition Tables:
Supports to divide the huge tables into multiple partitions logically.
This will improve the performance while retrieving or updating the data.
Ex:
Create table emp(empno number(4) primary key,----
---------)
Partition by range(empno)
(partition p1 values less than (101),
Partition p2 values less than (201),
Partition p3 values less than (maxvalue));
Insert into emp values(10, ….); P1 P1 -- 1-100
“ “ (110….); P2 P2 -- 101-200
“ “ (210….); P3 P3 -- 201 – N
“ “ (310,…); P3
Select * from emp;
Update emp partition p2 set sal = sal+3000;
Select * from emp partition p3 where sal > 10000;
Alter table emp merge partitions (p1, p2);
Alter table emp drop partition p3;
Alter table emp add partition p3 values less than (401);
Alter table emp add partition p4 values less than <maxvalue);
Page 52 of 54
53. PLSQL
Oracle Utilities:
Performed by the DBA on the dos-Prompt of Server.
3 utilitites….
1. Export:
Used to translate information from database format to OS file format.
EX:
CD:> EXP
Enter username & pwd : scott/tiger
Enter export buffer size(default): Press “enter” key.
Enter export file name: mydata.dmp
Export user(u), table(t) database : T
Export table data : Y
Compress the contents while exporting : Y
Enter table1:emp
Enter table 2:dept
Enter table3: Press “enter” key
2. Import:
Used to translate information from OS file format to database format.
EX:
CD:> IMP
Enter username & pwd : scott/tiger
Enter import buffer size(default): Press “enter” key.
Enter import file name: mydata.dmp
Export entire file : Y
Export table data : Y
List the contents while exporting : N
Ignore error due to object existence : N
3. Sql Loader:
Used to transfer data from OS file to database table.
Step-1:
Abc.txt
10, sales, Hyd
20, import, Pune
30, export, Chennai
40, researc, Bgr
Page 53 of 54
54. PLSQL
Step-2:
abc.ctl (control file)
Load data
infile abc.txt
insert into table dept
fields terminated by ‘,’
(deptno, dname, loc)
Step-3:
C:>SQLLDR Userid = scott/Tiger control = abc.ctl
NOTE:
Insert (Default option): Supports
only if table is empty.
Append: Allows to add the rows
to existing table with data.
To avoid the abc.ctl.txt(.txt). we
need to put file in “”.
Oracle 10g: [ G Grid]
Supports “Grid” technology
It is an DBA version
It supports to store “EJB” components directly into database without translation.
It supports with “regular expr’s” to search character data.
It provides high performance compared to other versions.
<<<<<<<<<<<<<<<<<<<<<<<<<<<<< All the Best >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Don’t Judge a book, by its cover
Page 54 of 54