Saturday, August 31, 2019

Hackers: Outlaws and Angels Essay

Outlaws and Angels is a very interesting documentary that outlines the technology and intelligence that has permeated the hacker community. Hackers is someone who breaks into computers and computer networks, either for profit or motivated by the challenge. The subculture that has evolved around hackers is often referred to as the computer underground but is now an open community. Ian Murphy, also known as Captain Zap, is said to have done the ‘greatest hack ever’. Was the first cracker to be tried and convicted as a felon. Murphy broke into AT&T’s computers in 1981 and changed the internal clocks that metered billing rates. People were getting late-night discount rates when they called at midday. Of course, the bargain-seekers who waited until midnight to call long distance were hit with high bills. Murphy, now the chairman of IAM/Secure Data System, was the inspiration for the movie â€Å"Sneakers.† Another story about hacking is when the famous movie Star Wars first came out, hundreds and thousands of people have to wait in line for hours to watch it. But a group of hackers have watched it and spreads it in the internet for about a week before the premiere. They successfully hacked the Star Wars database and took the movie data. So at first the term hacker referred to just people who breaks computer security. But later ‘hacker’ splits to two main sides. The Black Hats and the White Hats. A white hat hacker breaks security for non-malicious reasons, for instance testing their own security system. This classification also includes individuals who perform penetration tests and vulnerability assessments within a contractual agreement. Often, this type of ‘white hat’ hacker is called an ethical hacker. The International Council of Electronic Commerce Consultants, also known as the EC-Council has developed certifications, courseware, classes, and online training covering the diverse arena of Ethical Hacking. A black hat is the villain or bad guy, especially in a western movie in which such a character would wear a black hat in contrast to the hero’s white hat. A black hat hacker, sometimes called â€Å"cracker,† is someone who breaks computer security without authorization or uses technology usually a computer, phone system or network for malicious reasons such as vandalism, credit card fraud, identity theft, piracy, or other types of illegal activity. After learning much about hackers and internet security, we now know that the internet isn’t the  safest place and that we need protection as much as we can. The least we can do right now is to keep our own system safe. Little things like keeping a strong password, not sharing any account with somebody else can help in improving our security.

Friday, August 30, 2019

Black People and African American Actors Essay

Stereotyping is the automatic/ exaggerated mental pictures that people hold about a particular racial group without taking individual differences into consideration. Examples of stereotyping would be the main characters of the movie Rio2, Jewel and Blue being voiced by white actors whilst their ‘wild’ relatives are voiced by ‘non-white’ actors implying sophistication as well as in the movie Despicable Me 2 where El Macho and his son are given a Spanish image portraying a smooth talker and an irresistible lover that is often stereotypes about Spanish people. [87] People seem oblivious to the racial content due to various distractions like visual stimuli such as 3D effects and the contrasting use of color, sound effects such as surround sound and the voices of the character and lastly the plot of the story. Most people are over stimulated by these ‘distractions’ that they rarely notice the stereotyping. Another factor would be that parents neglect the responsibility to screen the movies that their children are watching. In some instances the stereotyping may be instilled in some parents from birth resulting in children seeing stereotyping as normal behavior. [96] Subtle racial prejudices towards Hispanic and Black people in Rio2 were the implication that ‘wild’ Amazonian Macaws voiced by ‘non- white ‘actors are uncivilized. Songs sung by these Macaws are primarily voiced by African American actors accompanied by rhythmic beats and movements with catchy phrases primarily found in native song and dance. Roberto (wild Macaw) is voiced by the singer Bruno Mars who is from a mixture of Jewish and Hawaiian decent implying (help with that word). Pedro and Nico two rapping, gangster, music loving birds are voiced by two equally successful and famous rappers Will.I.Am and Jamie Foxx [99] From this passage I can conclude that even though warnings about stereotyping may be placed before animation movies, many parents would still allow their children to watch it. [31]

Thursday, August 29, 2019

Sql Study Matetial

Oracle/SQL Tutorial1 Michael Gertz Database and Information Systems Group Department of Computer Science University of California, Davis [email  protected] ucdavis. edu http://www. db. cs. ucdavis. edu This Oracle/SQL tutorial provides a detailed introduction to the SQL query language and the Oracle Relational Database Management System. Further information about Oracle and SQL can be found on the web site www. db. cs. ucdavis. edu/dbs. Comments, corrections, or additions to these notes are welcome. Many thanks to Christina Chung for comments on the previous version. Recommended LiteratureGeorge Koch and Kevin Loney: Oracle8 The Complete Reference (The Single Most Comprehensive Sourcebook for Oracle Server, Includes CD with electronic version of the book), 1299 pages, McGraw-Hill/Osborne, 1997. Michael Abbey and Michael Corey: Oracle8 : A Beginner’s Guide [A Thorough Introduction for First-time Users], 767 pages, McGraw-Hill/Osborne, 1997. Steven Feuerstein, Bill Pribyl, Deb by Russell: Oracle PL/SQL Programming (2nd Edition), O’Reilly & Associates, 1028 pages, 1997. C. J. Date and Hugh Darwen: A Guide to the SQL Standard (4th Edition), Addison-Wesley, 1997. Jim Melton and Alan R.Simon: Understanding the New SQL: A Complete Guide (2nd Edition, Dec 2000), The Morgan Kaufmann Series in Data Management Systems, 2000. 1 revised Version 1. 01, January 2000, Michael Gertz, Copyright 2000. Contents 1. SQL – Structured Query Language 1. 1. Tables 1. 2. Queries (Part I) 1. 3. Data De? nition in SQL 1. 4. Data Modi? cations in SQL 1. 5. Queries (Part II) 1. 6. Views 1 3 6 9 11 19 2. SQL*Plus (Minimal User Guide, Editor Commands, Help System) 20 3. Oracle Data Dictionary 23 4. Application Programming 4. 1. PL/SQL 4. 1. 1 Introduction 4. 1. 2 Structure of PL/SQL Blocks 4. 1. Declarations 4. 1. 4 Language Elements 4. 1. 5 Exception Handling 4. 1. 6 Procedures and Functions 4. 1. 7 Packages 4. 1. 8 Programming in PL/SQL 4. 2. Embedded SQL and Pro*C 26 2 7 27 28 32 34 36 38 39 5. Integrity Constraints and Triggers 5. 1. Integrity Constraints 5. 1. 1 Check Constraints 5. 1. 2 Foreign Key Constraints 5. 1. 3 More About Column- and Table Constraints 5. 2. Triggers 5. 2. 1 Overview 5. 2. 2 Structure of Triggers 5. 2. 3 Example Triggers 5. 2. 4 Programming Triggers 6. System Architecture 6. 1. Storage Management and Processes 6. 2. Logical Database Structures 6. 3.Physical Database Structures 6. 4. Steps in Processing an SQL Statement 6. 5. Creating Database Objects 46 47 49 50 50 53 55 58 60 61 63 63 1 SQL – Structured Query Language 1. 1 Tables In relational database systems (DBS) data are represented using tables (relations ). A query issued against the DBS also results in a table. A table has the following structure: Column 1 Column 2 . . . Column n †¦ †¦ †¦ †¦ A table is uniquely identi? ed by its name and consists of rows that contain the stored information, each row containing exactly one tuple (or recor d ). A table can have one or more columns.A column is made up of a column name and a data type, and it describes an attribute of the tuples. The structure of a table, also called relation schema, thus is de? ned by its attributes. The type of information to be stored in a table is de? ned by the data types of the attributes at table creation time. SQL uses the terms table, row, and column for relation, tuple, and attribute, respectively. In this tutorial we will use the terms interchangeably. A table can have up to 254 columns which may have di? erent or same data types and sets of values (domains), respectively.Possible domains are alphanumeric data (strings), numbers and date formats. Oracle o? ers the following basic data types: †¢ char(n): Fixed-length character data (string), n characters long. The maximum size for n is 255 bytes (2000 in Oracle8). Note that a string of type char is always padded on right with blanks to full length of n. ( can be memory consuming). Exampl e: char(40) †¢ varchar2(n): Variable-length character string. The maximum size for n is 2000 (4000 in Oracle8). Only the bytes used for a string require storage. Example: varchar2(80) †¢ number(o, d): Numeric data type for integers and reals. = overall number of digits, d = number of digits to the right of the decimal point. Maximum values: o =38, d= ? 84 to +127. Examples: number(8), number(5,2) Note that, e. g. , number(5,2) cannot contain anything larger than 999. 99 without resulting in an error. Data types derived from number are int[eger], dec[imal], smallint and real. †¢ date: Date data type for storing date and time. The default format for a date is: DD-MMM-YY. Examples : ’13-OCT-94’, ’07-JAN-98’ 1 †¢ long: Character data up to a length of 2GB. Only one long column is allowed per table. Note: In Oracle-SQL there is no data type boolean.It can, however, be simulated by using either char(1) or number(1). As long as no constraint restricts the possible values of an attribute, it may have the special value null (for unknown). This value is di? erent from the number 0, and it is also di? erent from the empty string ’’. Further properties of tables are: †¢ the order in which tuples appear in a table is not relevant (unless a query requires an explicit sorting). †¢ a table has no duplicate tuples (depending on the query, however, duplicate tuples can appear in the query result). A database schema is a set of relation schemas.The extension of a database schema at database run-time is called a database instance or database, for short. 1. 1. 1 Example Database In the following discussions and examples we use an example database to manage information about employees, departments and salary scales. The corresponding tables can be created under the UNIX shell using the command demobld. The tables can be dropped by issuing the command demodrop under the UNIX shell. The table EMP is used to store information about employees: EMPNO ENAME JOB MGR HIREDATE SAL DEPTNO 7369 SMITH CLERK 7902 17-DEC-80 800 20 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 30 7521WARD SALESMAN 7698 22-FEB-81 1250 30 †¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦.. 7698 BLAKE MANAGER 01-MAY-81 3850 30 7902 FORD ANALYST 7566 03-DEC-81 3000 10 For the attributes, the following data types are de? ned: EMPNO:number(4), ENAME:varchar2(30), JOB:char(10), MGR:number(4), HIREDATE:date, SAL:number(7,2), DEPTNO:number(2) Each row (tuple) from the table is interpreted as follows: an employee has a number, a name, a job title and a salary. Furthermore, for each employee the number of his/her manager, the date he/she was hired, and the number of the department where he/she is working are stored. 2The table DEPT stores information about departments (number, name, and location): DEPTNO 10 20 30 40 DNAME STORE RESEARCH SALES MARKETING L OC CHICAGO DALLAS NEW YORK BOSTON Finally, the table SALGRADE contains all information about the salary scales, more precisely, the maximum and minimum salary of each scale. GRADE 1 2 3 4 5 1. 2 LOSAL 700 1201 1401 2001 3001 HISAL 1200 1400 2000 3000 9999 Queries (Part I) In order to retrieve the information stored in the database, the SQL query language is used. In the following we restrict our attention to simple SQL queries and defer the discussion of more complex queries to Section 1. In SQL a query has the following (simpli? ed) form (components in brackets [ ] are optional): select [distinct] from [ where ] [ order by ] 1. 2. 1 Selecting Columns The columns to be selected from a table are speci? ed after the keyword select. This operation is also called projection. For example, the query select LOC, DEPTNO from DEPT; lists only the number and the location for each tuple from the relation DEPT. If all columns should be selected, the asterisk symbol â€Å"? † can be used to denote all attributes. The query select ? from EMP; retrieves all tuples with all columns from the table EMP.Instead of an attribute name, the select clause may also contain arithmetic expressions involving arithmetic operators etc. select ENAME, DEPTNO, SAL ? 1. 55 from EMP; 3 For the di? erent data types supported in Oracle, several operators and functions are provided: †¢ for numbers: abs, cos, sin, exp, log, power, mod, sqrt, +, ? , ? , /, . . . †¢ for strings: chr, concat(string1, string2), lower, upper, replace(string, search string, replacement string), translate, substr(string, m, n), length, to date, . . . †¢ for the date data type: add month, month between, next day, to char, . . The usage of these operations is described in detail in the SQL*Plus help system (see also Section 2). Consider the query select DEPTNO from EMP; which retrieves the department number for each tuple. Typically, some numbers will appear more than only once in the query result, tha t is, duplicate result tuples are not automatically eliminated. Inserting the keyword distinct after the keyword select, however, forces the elimination of duplicates from the query result. It is also possible to specify a sorting order in which the result tuples of a query are displayed.For this the order by clause is used and which has one or more attributes listed in the select clause as parameter. desc speci? es a descending order and asc speci? es an ascending order (this is also the default order). For example, the query select ENAME, DEPTNO, HIREDATE from EMP; from EMP order by DEPTNO [asc], HIREDATE desc; displays the result in an ascending order by the attribute DEPTNO. If two tuples have the same attribute value for DEPTNO, the sorting criteria is a descending order by the attribute values of HIREDATE. For the above query, we would get the following output: ENAME DEPTNO HIREDATEFORD 10 03-DEC-81 SMITH 20 17-DEC-80 BLAKE 30 01-MAY-81 WARD 30 22-FEB-81 ALLEN 30 20-FEB-81 â⠂¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦ 1. 2. 2 Selection of Tuples Up to now we have only focused on selecting (some) attributes of all tuples from a table. If one is interested in tuples that satisfy certain conditions, the where clause is used. In a where clause simple conditions based on comparison operators can be combined using the logical connectives and, or, and not to form complex conditions. Conditions may also include pattern matching operations and even subqueries (Section 1. 5). 4 Example:List the job title and the salary of those employees whose manager has the number 7698 or 7566 and who earn more than 1500: select JOB, SAL from EMP where (MGR = 7698 or MGR = 7566) and SAL > 1500; For all data types, the comparison operators =, ! = or , , are allowed in the conditions of a where clause. Further comparison operators are: †¢ Set Conditions: [not] in () Example: select ? from DEPT where DEPTNO in (20,30); †¢ Null value: is [not] null, i. e. , for a tuple to be selected there must (not) exist a de? ned value for this column. Example: select ? from EMP where MGR is not null; Note: the operations = null and ! null are not de? ned! †¢ Domain conditions: [not] between and Example: †¢ select EMPNO, ENAME, SAL from EMP where SAL between 1500 and 2500; †¢ select ENAME from EMP where HIREDATE between ’02-APR-81’ and ’08-SEP-81’; 1. 2. 3 String Operations In order to compare an attribute with a string, it is required to surround the string by apostrophes, e. g. , where LOCATION = ’DALLAS’. A powerful operator for pattern matching is the like operator. Together with this operator, two special characters are used: the percent sign % (also called wild card), and the underline , also called position marker.For example, if one is interested in all tuples of the table DEPT that contain two C in the name of the department, the condition would be where DNAME like ’%C%C%â⠂¬â„¢. The percent sign means that any (sub)string is allowed there, even the empty string. In contrast, the underline stands for exactly one character. Thus the condition where DNAME like ’%C C%’ would require that exactly one character appears between the two Cs. To test for inequality, the not clause is used. Further string operations are: †¢ upper() takes a string and converts any letters in it to uppercase, e. g. DNAME = upper(DNAME) (The name of a department must consist only of upper case letters. ) †¢ lower() converts any letter to lowercase, †¢ initcap() converts the initial letter of every word in to uppercase. †¢ length() returns the length of the string. †¢ substr(, n [, m]) clips out a m character piece of , starting at position n. If m is not speci? ed, the end of the string is assumed. substr(’DATABASE SYSTEMS’, 10, 7) returns the string ’SYSTEMS’. 5 1. 2. 4 Aggregate Functions Aggregate functions are statistical functions such as count, min, max etc. They are used to compute a single value from a set of attribute values of a column: count ax min sum avg Note: 1. 3 1. 3. 1 Counting Rows Example: How many tuples are stored in the relation EMP? select count(? ) from EMP; Example: How many di? erent job titles are stored in the relation EMP? select count(distinct JOB) from EMP; Maximum value for a column Minimum value for a column Example: List the minimum and maximum salary. select min(SAL), max(SAL) from EMP; Example: Compute the di? erence between the minimum and maximum salary. select max(SAL) – min(SAL) from EMP; Computes the sum of values (only applicable to the data type number) Example: Sum of all salaries of employees working in the department 30. elect sum(SAL) from EMP where DEPTNO = 30; Computes average value for a column (only applicable to the data type number) avg, min and max ignore tuples that have a null value for the speci? ed attribute, but count considers null values. Data De? nition in SQL Creating Tables The SQL command for creating an empty table has the following form: create table ( [not null] [unique] [], †¦Ã¢â‚¬ ¦Ã¢â‚¬ ¦ [not null] [unique] [], [] ); For each column, a name and a data type must be speci? ed and the column name must be unique within the table de? nition. Column de? nitions are separated by colons. There is no di? rence between names in lower case letters and names in upper case letters. In fact, the only place where upper and lower case letters matter are strings comparisons. A not null 6 constraint is directly speci? ed after the data type of the column and the constraint requires de? ned attribute values for that column, di? erent from null. The keyword unique speci? es that no two tuples can have the same attribute value for this column. Unless the condition not null is also speci? ed for this column, the attribute value null is allowed and two tuples having the attribute value null for this column do not violate the constraint.Example: The create table statement for our EMP table has the form create table EMP ( EMPNO number(4) not null, ENAME varchar2(30) not null, JOB varchar2(10), MGR number(4), HIREDATE date, SAL number(7,2), DEPTNO number(2) ); Remark: Except for the columns EMPNO and ENAME null values are allowed. 1. 3. 2 Constraints The de? nition of a table may include the speci? cation of integrity constraints. Basically two types of constraints are provided: column constraints are associated with a single column whereas table constraints are typically associated with more than one column.However, any column constraint can also be formulated as a table constraint. In this section we consider only very simple constraints. More complex constraints will be discussed in Section 5. 1. The speci? cation of a (simple) constraint has the following form: [constraint ] primary key | unique | not null A constraint can be named. It is advisable to name a constraint in order to get m ore meaningful information when this constraint is violated due to, e. g. , an insertion of a tuple that violates the constraint. If no name is speci? ed for the constraint, Oracle automatically generates a name of the pattern SYS C.The two most simple types of constraints have already been discussed: not null and unique. Probably the most important type of integrity constraints in a database are primary key constraints. A primary key constraint enables a unique identi? cation of each tuple in a table. Based on a primary key, the database system ensures that no duplicates appear in a table. For example, for our EMP table, the speci? cation create table EMP ( EMPNO number(4) constraint pk emp primary key, . . . ); 7 de? nes the attribute EMPNO as the primary key for the table. Each value for the attribute EMPNO thus must appear only once in the table EMP.A table, of course, may only have one primary key. Note that in contrast to a unique constraint, null values are not allowed. Examp le: We want to create a table called PROJECT to store information about projects. For each project, we want to store the number and the name of the project, the employee number of the project’s manager, the budget and the number of persons working on the project, and the start date and end date of the project. Furthermore, we have the following conditions: – a project is identi? ed by its project number, – the name of a project must be unique, – the manager and the budget must be de? ed. Table de? nition: create table PROJECT ( PNO number(3) constraint prj pk primary key, PNAME varchar2(60) unique, PMGR number(4) not null, PERSONS number(5), BUDGET number(8,2) not null, PSTART date, PEND date); A unique constraint can include more than one attribute. In this case the pattern unique(, . . . , ) is used. If it is required, for example, that no two projects have the same start and end date, we have to add the table constraint constraint no same dates unique( PEND, PSTART) This constraint has to be de? ned in the create table command after both columns PEND and PSTART have been de? ed. A primary key constraint that includes more than only one column can be speci? ed in an analogous way. Instead of a not null constraint it is sometimes useful to specify a default value for an attribute if no value is given, e. g. , when a tuple is inserted. For this, we use the default clause. Example : If no start date is given when inserting a tuple into the table PROJECT, the project start date should be set to January 1st, 1995: PSTART date default(’01-JAN-95’) Note: Unlike integrity constraints, it is not possible to specify a name for a default. 8 1. 3. 3 Checklist for Creating TablesThe following provides a small checklist for the issues that need to be considered before creating a table. †¢ What are the attributes of the tuples to be stored? What are the data types of the attributes? Should varchar2 be used instead of char ? â⠂¬ ¢ Which columns build the primary key? †¢ Which columns do (not) allow null values? Which columns do (not) allow duplicates ? †¢ Are there default values for certain columns that allow null values ? 1. 4 Data Modi? cations in SQL After a table has been created using the create table command, tuples can be inserted into the table, or tuples can be deleted or modi? ed. 1. 4. 1Insertions The most simple way to insert a tuple into a table is to use the insert statement insert into [()] values (); For each of the listed columns, a corresponding (matching) value must be speci? ed. Thus an insertion does not necessarily have to follow the order of the attributes as speci? ed in the create table statement. If a column is omitted, the value null is inserted instead. If no column list is given, however, for each column as de? ned in the create table statement a value must be given. Examples: insert into PROJECT(PNO, PNAME, PERSONS, BUDGET, PSTART) values(313, ’DBS’, 4, 150000. 42, ’10-OCT-94’); r insert into PROJECT values(313, ’DBS’, 7411, null, 150000. 42, ’10-OCT-94’, null); If there are already some data in other tables, these data can be used for insertions into a new table. For this, we write a query whose result is a set of tuples to be inserted. Such an insert statement has the form insert into [()] Example: Suppose we have de? ned the following table: 9 create table OLDEMP ( ENO number(4) not null, HDATE date); We now can use the table EMP to insert tuples into this new relation: insert into OLDEMP (ENO, HDATE) select EMPNO, HIREDATE from EMP where HIREDATE < ’31-DEC-60’; 1. 4. 2 UpdatesFor modifying attribute values of (some) tuples in a table, we use the update statement: update set = , . . . , = [where ]; An expression consists of either a constant (new value), an arithmetic or string operation, or an SQL query. Note that the new value to assign to must a the matching data typ e. An update statement without a where clause results in changing respective attributes of all tuples in the speci? ed table. Typically, however, only a (small) portion of the table requires an update. Examples: †¢ The employee JONES is transfered to the department 20 as a manager and his salary is increased by 1000: pdate EMP set JOB = ’MANAGER’, DEPTNO = 20, SAL = SAL +1000 where ENAME = ’JONES’; †¢ All employees working in the departments 10 and 30 get a 15% salary increase. update EMP set SAL = SAL ? 1. 15 where DEPTNO in (10,30); Analogous to the insert statement, other tables can be used to retrieve data that are used as new values. In such a case we have a instead of an . Example: All salesmen working in the department 20 get the same salary as the manager who has the lowest salary among all managers. update EMP set SAL = (select min(SAL) from EMP where JOB = ’MANAGER’) where JOB = ’SALESMAN’ and DEPTNO = 20;Ex planation: The query retrieves the minimum salary of all managers. This value then is assigned to all salesmen working in department 20. 10 It is also possible to specify a query that retrieves more than only one value (but still only one tuple! ). In this case the set clause has the form set() = . It is important that the order of data types and values of the selected row exactly correspond to the list of columns in the set clause. 1. 4. 3 Deletions All or selected tuples can be deleted from a table using the delete command: delete from [where ]; If the where clause is omitted, all tuples are deleted from the table.An alternative command for deleting all tuples from a table is the truncate table command. However, in this case, the deletions cannot be undone (see subsequent Section 1. 4. 4). Example: Delete all projects (tuples) that have been ? nished before the actual date (system date): delete from PROJECT where PEND < sysdate; sysdate is a function in SQL that returns the system date. Another important SQL function is user, which returns the name of the user logged into the current Oracle session. 1. 4. 4 Commit and Rollback A sequence of database modi? cations, i. e. , a sequence of insert, update, and delete statements, is called a transaction.Modi? cations of tuples are temporarily stored in the database system. They become permanent only after the statement commit; has been issued. As long as the user has not issued the commit statement, it is possible to undo all modi? cations since the last commit. To undo modi? cations, one has to issue the statement rollback;. It is advisable to complete each modi? cation of the database with a commit (as long as the modi? cation has the expected e? ect). Note that any data de? nition command such as create table results in an internal commit. A commit is also implicitly executed when the user terminates an Oracle session. . 5 Queries (Part II) In Section 1. 2 we have only focused on queries that refer to exactly o ne table. Furthermore, conditions in a where were restricted to simple comparisons. A major feature of relational databases, however, is to combine (join) tuples stored in di? erent tables in order to display more meaningful and complete information. In SQL the select statement is used for this kind of queries joining relations: 11 select [distinct] [. ], . . . , [. ] from [], . . . , [] [where ] The speci? cation of table aliases in the from clause is necessary to refer to columns that have the same name in di? rent tables. For example, the column DEPTNO occurs in both EMP and DEPT. If we want to refer to either of these columns in the where or select clause, a table alias has to be speci? ed and put in the front of the column name. Instead of a table alias also the complete relation name can be put in front of the column such as DEPT. DEPTNO, but this sometimes can lead to rather lengthy query formulations. 1. 5. 1 Joining Relations Comparisons in the where clause are used to comb ine rows from the tables listed in the from clause. Example : In the table EMP only the numbers of the departments are stored, not their name.For each salesman, we now want to retrieve the name as well as the number and the name of the department where he is working: select ENAME, E. DEPTNO, DNAME from EMP E, DEPT D where E. DEPTNO = D. DEPTNO and JOB = ’SALESMAN’; Explanation: E and D are table aliases for EMP and DEPT, respectively. The computation of the query result occurs in the following manner (without optimization): 1. Each row from the table EMP is combined with each row from the table DEPT (this operation is called Cartesian product ). If EMP contains m rows and DEPT contains n rows, we thus get n ? m rows. 2.From these rows those that have the same department number are selected (where E. DEPTNO = D. DEPTNO). 3. From this result ? nally all rows are selected for which the condition JOB = ’SALESMAN’ holds. In this example the joining condition f or the two tables is based on the equality operator â€Å"=†. The columns compared by this operator are called join columns and the join operation is called an equijoin. Any number of tables can be combined in a select statement. Example: For each project, retrieve its name, the name of its manager, and the name of the department where the manager is working: select ENAME, DNAME, PNAME rom EMP E, DEPT D, PROJECT P where E. EMPNO = P. MGR and D. DEPTNO = E. DEPTNO; 12 It is even possible to join a table with itself: Example: List the names of all employees together with the name of their manager: select E1. ENAME, E2. ENAME from EMP E1, EMP E2 where E1. MGR = E2. EMPNO; Explanation: The join columns are MGR for the table E1 and EMPNO for the table E2. The equijoin comparison is E1. MGR = E2. EMPNO. 1. 5. 2 Subqueries Up to now we have only concentrated on simple comparison conditions in a where clause, i. e. , we have compared a column with a constant or we have compared two c olumns.As we have already seen for the insert statement, queries can be used for assignments to columns. A query result can also be used in a condition of a where clause. In such a case the query is called a subquery and the complete select statement is called a nested query. A respective condition in the where clause then can have one of the following forms: 1. Set-valued subqueries [not] in () [any|all] () An can either be a column or a computed value. 2. Test for (non)existence [not] exists () In a where clause conditions using subqueries can be combined arbitrarily by using the logical connectives and and or.Example: List the name and salary of employees of the department 20 who are leading a project that started before December 31, 1990: select ENAME, SAL from EMP where EMPNO in (select PMGR from PROJECT where PSTART < ’31-DEC-90’) and DEPTNO =20; Explanation: The subquery retrieves the set of those employees who manage a project that started before December 31, 1 990. If the employee working in department 20 is contained in this set (in operator), this tuple belongs to the query result set. Example: List all employees who are working in a department located in BOSTON: 13 select ? from EMP where DEPTNO in select DEPTNO from DEPT where LOC = ’BOSTON’); The subquery retrieves only one value (the number of the department located in Boston). Thus it is possible to use â€Å"=† instead of in. As long as the result of a subquery is not known in advance, i. e. , whether it is a single value or a set, it is advisable to use the in operator. A subquery may use again a subquery in its where clause. Thus conditions can be nested arbitrarily. An important class of subqueries are those that refer to its surrounding (sub)query and the tables listed in the from clause, respectively. Such type of queries is called correlated subqueries.Example: List all those employees who are working in the same department as their manager (note that co mponents in [ ] are optional: select ? from EMP E1 where DEPTNO in (select DEPTNO from EMP [E] where [E. ]EMPNO = E1. MGR); Explanation: The subquery in this example is related to its surrounding query since it refers to the column E1. MGR. A tuple is selected from the table EMP (E1) for the query result if the value for the column DEPTNO occurs in the set of values select in the subquery. One can think of the evaluation of this query as follows: For each tuple in the table E1, the subquery is evaluated individually.If the condition where DEPTNO in . . . evaluates to true, this tuple is selected. Note that an alias for the table EMP in the subquery is not necessary since columns without a preceding alias listed there always refer to the innermost query and tables. Conditions of the form [any|all] are used to compare a given with each value selected by . †¢ For the clause any, the condition evaluates to true if there exists at least on row selected by the subquery for which the comparison holds. If the subquery yields an empty result set, the condition is not satis? ed. For the clause all, in contrast, the condition evaluates to true if for all rows selected by the subquery the comparison holds. In this case the condition evaluates to true if the subquery does not yield any row or value. Example: Retrieve all employees who are working in department 10 and who earn at least as much as any (i. e. , at least one) employee working in department 30: select ? from EMP where SAL >= any (select SAL from EMP where DEPTNO = 30) and DEPTNO = 10; 14 Note: Also in this subquery no aliases are necessary since the columns refer to the innermost from clause.Example: List all employees who are not working in department 30 and who earn more than all employees working in department 30: select ? from EMP where SAL > all (select SAL from EMP where DEPTNO = 30) and DEPTNO 30; For all and any, the following equivalences hold: in ? = any not in ? all or ! = all Often a query resu lt depends on whether certain rows do (not) exist in (other) tables. Such type of queries is formulated using the exists operator. Example: List all departments that have no employees: select ? from DEPT where not exists (select ? from EMP where DEPTNO = DEPT.DEPTNO); Explanation: For each tuple from the table DEPT, the condition is checked whether there exists a tuple in the table EMP that has the same department number (DEPT. DEPTNO). In case no such tuple exists, the condition is satis? ed for the tuple under consideration and it is selected. If there exists a corresponding tuple in the table EMP, the tuple is not selected. 1. 5. 3 Operations on Result Sets Sometimes it is useful to combine query results from two or more queries into a single result. SQL supports three set operators which have the pattern: The set operators are: union [all] returns a table consisting of all rows either appearing in the result of or in the result of . Duplicates are automatically eliminated unless the clause all is used. †¢ intersect returns all rows that appear in both results and . †¢ minus returns those rows that appear in the result of but not in the result of . 15 Example: Assume that we have a table EMP2 that has the same structure and columns as the table EMP: †¢ All employee numbers and names from both tables: select EMPNO, ENAME from EMP union select EMPNO, ENAME from EMP2; †¢ Employees who are listed in both EMP and EMP2: select ? from EMP intersect select ? from EMP2; Employees who are only listed in EMP: select ? from EMP minus select ? from EMP2; Each operator requires that both tables have the same data types for the columns to which the operator is applied. 1. 5. 4 Grouping In Section 1. 2. 4 we have seen how aggregate functions can be used to compute a single value for a column. Often applications require grouping rows that have certain properties and then applying an aggregate function on one column for each group separately. For this, SQ L provides the clause group by . This clause appears after the where clause and must refer to columns of tables listed in the from clause. select from here group by [having ]; Those rows retrieved by the selected clause that have the same value(s) for are grouped. Aggregations speci? ed in the select clause are then applied to each group separately. It is important that only those columns that appear in the clause can be listed without an aggregate function in the select clause ! Example: For each department, we want to retrieve the minimum and maximum salary. select DEPTNO, min(SAL), max(SAL) from EMP group by DEPTNO; Rows from the table EMP are grouped such that all rows in a group have the same department number. The aggregate functions are then applied to each such group.We thus get the following query result: 16 DEPTNO 10 20 30 MIN(SAL) 1300 800 950 MAX(SAL) 5000 3000 2850 Rows to form a group can be restricted in the where clause. For example, if we add the condition where JOB = ’CLERK’, only respective rows build a group. The query then would retrieve the minimum and maximum salary of all clerks for each department. Note that is not allowed to specify any other column than DEPTNO without an aggregate function in the select clause since this is the only column listed in the group by clause (is it also easy to see that other columns would not make any sense).Once groups have been formed, certain groups can be eliminated based on their properties, e. g. , if a group contains less than three rows. This type of condition is speci? ed using the having clause. As for the select clause also in a having clause only and aggregations can be used. Example: Retrieve the minimum and maximum salary of clerks for each department having more than three clerks. select DEPTNO, min(SAL), max(SAL) from EMP where JOB = ’CLERK’ group by DEPTNO having count(? ) > 3; Note that it is even possible to specify a subquery in a having clause.In the above query, for example, instead of the constant 3, a subquery can be speci? ed. A query containing a group by clause is processed in the following way: 1. Select all rows that satisfy the condition speci? ed in the where clause. 2. From these rows form groups according to the group by clause. 3. Discard all groups that do not satisfy the condition in the having clause. 4. Apply aggregate functions to each group. 5. Retrieve values for the columns and aggregations listed in the select clause. 1. 5. 5 Some Comments on Tables Accessing tables of other usersProvided that a user has the privilege to access tables of other users (see also Section 3), she/he can refer to these tables in her/his queries. Let be a user in the Oracle system and a table of this user. This table can be accessed by other (privileged) users using the command select ? from . ; 17 In case that one often refers to tables of other users, it is useful to use a synonym instead of .. In Oracle-SQL a synonym can be created u sing the command create synonym for . ; It is then possible to use simply in a from clause. Synonyms can also be created for one’s own tables. Adding Comments to De? nitionsFor applications that include numerous tables, it is useful to add comments on table de? nitions or to add comments on columns. A comment on a table can be created using the command comment on table is ’’; A comment on a column can be created using the command comment on column . is ’’; Comments on tables and columns are stored in the data dictionary. They can be accessed using the data dictionary views USER TAB COMMENTS and USER COL COMMENTS (see also Section 3). Modifying Table- and Column De? nitions It is possible to modify the structure of a table (the relation schema) even if rows have already been inserted into this table.A column can be added using the alter table command alter table add( [default ] []); If more than only one column should be added at one time, respectiv e add clauses need to be separated by colons. A table constraint can be added to a table using alter table add (); Note that a column constraint is a table constraint, too. not null and primary key constraints can only be added to a table if none of the speci? ed columns contains a null value. Table de? nitions can be modi? ed in an analogous way. This is useful, e. g. , when the size of strings that can be stored needs to be increased.The syntax of the command for modifying a column is alter table modify( [] [default ] []); Note: In earlier versions of Oracle it is not possible to delete single columns from a table de? nition. A workaround is to create a temporary table and to copy respective columns and rows into this new table. Furthermore, it is not possible to rename tables or columns. In the most recent version (9i), using the alter table command, it is possible to rename a table, columns, and constraints. In this version, there also exists a drop column clause as part of the alter table statement. Deleting a TableA table and its rows can be deleted by issuing the command drop table [cascade constraints];. 18 1. 6 Views In Oracle the SQL command to create a view (virtual table) has the form create [or replace] view [()] as [with check option [constraint ]]; The optional clause or replace re-creates the view if it already exists. names the columns of the view. If is not speci? ed in the view de? nition, the columns of the view get the same names as the attributes listed in the select statement (if possible). Example: The following view contains the name, job title and the annual salary of employees working in the department 20: create view DEPT20 as elect ENAME, JOB, SAL? 12 ANNUAL SALARY from EMP where DEPTNO = 20; In the select statement the column alias ANNUAL SALARY is speci? ed for the expression SAL? 12 and this alias is taken by the view. An alternative formulation of the above view de? nition is create view DEPT20 (ENAME, JOB, ANNUAL SALARY) as se lect ENAME, JOB, SAL ? 12 from EMP where DEPTNO = 20; A view can be used in the same way as a table, that is, rows can be retrieved from a view (also respective rows are not physically stored, but derived on basis of the select statement in the view de? ition), or rows can even be modi? ed. A view is evaluated again each time it is accessed. In Oracle SQL no insert, update, or delete modi? cations on views are allowed that use one of the following constructs in the view de? nition: †¢ Joins †¢ Aggregate function such as sum, min, max etc. †¢ set-valued subqueries (in, any, all) or test for existence (exists) †¢ group by clause or distinct clause In combination with the clause with check option any update or insertion of a row into the view is rejected if the new/modi? ed row does not meet the view de? nition, i. e. these rows would not be selected based on the select statement. A with check option can be named using the constraint clause. A view can be deleted us ing the command delete . 19 2 SQL*Plus Introduction SQL*Plus is the interactive (low-level) user interface to the Oracle database management system. Typically, SQL*Plus is used to issue ad-hoc queries and to view the query result on the screen. Some of the features of SQL*Plus are: †¢ A built-in command line editor can be used to edit (incorrect) SQL queries. Instead of this line editor any editor installed on the computer can be invoked. There are numerous commands to format the output of a query. †¢ SQL*Plus provides an online-help. †¢ Query results can be stored in ? les which then can be printed. Queries that are frequently issued can be saved to a ? le and invoked later. Queries can be parameterized such that it is possible to invoke a saved query with a parameter. A Minimal User Guide Before you start SQL*Plus make sure that the following UNIX shell variables are properly set (shell variables can be checked using the env command, e. g. , env | grep ORACLE): â₠¬ ¢ ORACLE HOME, e. g. , ORACLE HOME=/usr/pkg/oracle/734 †¢ ORACLE SID, e. , ORACLE SID=prod In order to invoke SQL*Plus from a UNIX shell, the command sqlplus has to be issued. SQL*Plus then displays some information about the product, and prompts you for your user name and password for the Oracle system. gertz(catbert)54: sqlplus SQL*Plus: Release 3. 3. 4. 0. 1 – Production on Sun Dec 20 19:16:52 1998 Copyright (c) Oracle Corporation 1979, 1996. All rights reserved. Enter user-name: scott Enter password: Connected to: Oracle7 Server Release 7. 3. 4. 0. 1 – Production Release With the distributed option PL/SQL Release 2. 3. 4. 0. 0 – Production SQL> 20SQL> is the prompt you get when you are connected to the Oracle database system. In SQL*Plus you can divide a statement into separate lines, each continuing line is indicated by a prompt such 2>, 3> etc. An SQL statement must always be terminated by a semicolon (;). In addition to the SQL statements discussed in the previous section, SQL*Plus provides some special SQL*Plus commands. These commands need not be terminated by a semicolon. Upper and lower case letters are only important for string comparisons. An SQL query can always be interrupted by using C. To exit SQL*Plus you can either type exit or quit.Editor Commands The most recently issued SQL statement is stored in the SQL bu? er, independent of whether the statement has a correct syntax or not. You can edit the bu? er using the following commands: †¢ l[ist] lists all lines in the SQL bu? er and sets the current line (marked with an †? †) to the last line in the bu? er. †¢ l sets the actual line to †¢ c[hange]// replaces the ? rst occurrence of by (for the actual line) †¢ a[ppend] appends to the current line †¢ del deletes the current line †¢ r[un] executes the current bu? er contents †¢ get reads the data from the ? le into the bu? er †¢ save writes the current bu? r into the ? le †¢ edit invokes an editor and loads the current bu? er into the editor. After exiting the editor the modi? ed SQL statement is stored in the bu? er and can be executed (command r). The editor can be de? ned in the SQL*Plus shell by typing the command de? ne editor = , where can be any editor such as emacs, vi, joe, or jove. SQL*Plus Help System and Other Useful Commands †¢ To get the online help in SQL*Plus just type help , or just help to get information about how to use the help command. In Oracle Version 7 one can get the complete list of possible commands by typing help command. To change the password, in Oracle Version 7 the command alter user identi? ed by ; is used. In Oracle Version 8 the command passw prompts the user for the old/new password. †¢ The command desc[ribe] lists all columns of the given table together with their data types and information about whether null values are allowed or not. †¢ You can invoke a UNIX command from the SQL*Plus she ll by using host . For example, host ls -la *. sql lists all SQL ? les in the current directory. 21 †¢ You can log your SQL*Plus session and thus queries and query results by using the command spool .All information displayed on screen is then stored in which automatically gets the extension . lst. The command spool o? turns spooling o?. †¢ The command copy can be used to copy a complete table. For example, the command copy from scott/tiger create EMPL using select ? from EMP; copies the table EMP of the user scott with password tiger into the relation EMPL. The relation EMP is automatically created and its structure is derived based on the attributes listed in the select clause. †¢ SQL commands saved in a ? le . sql can be loaded into SQL*Plus and executed using the command @. Comments are introduced by the clause rem[ark] (only allowed between SQL statements), or – – (allowed within SQL statements). Formatting the Output SQL*Plus provides numerous comm ands to format query results and to build simple reports. For this, format variables are set and these settings are only valid during the SQL*Plus session. They get lost after terminating SQL*Plus. It is, however, possible to save settings in a ? le named login. sql in your home directory. Each time you invoke SQL*Plus this ? le is automatically loaded. The command column . . . is used to format columns of your query result.The most frequently used options are: †¢ format A For alphanumeric data, this option sets the length of to . For columns having the data type number, the format command can be used to specify the format before and after the decimal point. For example, format 99,999. 99 speci? es that if a value has more than three digits in front of the decimal point, digits are separated by a colon, and only two digits are displayed after the decimal point. †¢ The option heading relabels and gives it a new heading. †¢ null is used to specify the output of null val ues (typically, null values are not displayed). column clear deletes the format de? nitions for . The command set linesize can be used to set the maximum length of a single line that can be displayed on screen. set pagesize sets the total number of lines SQL*Plus displays before printing the column names and headings, respectively, of the selected rows. Several other formatting features can be enabled by setting SQL*Plus variables. The command show all displays all variables and their current values. To set a variable, type set . For example, set timing on causes SQL*Plus to display timing statistics for each SQL command that is executed. et pause on [] makes SQL*Plus wait for you to press Return after the number of lines de? ned by set pagesize has been displayed. is the message SQL*Plus will display at the bottom of the screen as it waits for you to hit Return. 22 3 Oracle Data Dictionary The Oracle data dictionary is one of the most important components of the Oracle DBMS. It con tains all information about the structures and objects of the database such as tables, columns, users, data ? les etc. The data stored in the data dictionary are also often called metadata.Although it is usually the domain of database administrators (DBAs), the data dictionary is a valuable source of information for end users and developers. The data dictionary consists of two levels: the internal level contains all base tables that are used by the various DBMS software components and they are normally not accessible by end users. The external level provides numerous views on these base tables to access information about objects and structures at di? erent levels of detail. 3. 1 Data Dictionary Tables An installation of an Oracle database always includes the creation of three standard Oracle users: SYS: This is the owner of all data dictionary tables and views. This user has the highest privileges to manage objects and structures of an Oracle database such as creating new users. â⠂¬ ¢ SYSTEM: is the owner of tables used by di? erent tools such SQL*Forms, SQL*Reports etc. This user has less privileges than SYS. †¢ PUBLIC: This is a â€Å"dummy† user in an Oracle database. All privileges assigned to this user are automatically assigned to all users known in the database. The tables and views provided by the data dictionary contain information about †¢ users and their privileges, tables, table columns and their data types, integrity constraints, indexes, †¢ statistics about tables and indexes used by the optimizer, †¢ privileges granted on database objects, †¢ storage structures of the database. The SQL command select ? from DICT[IONARY]; lists all tables and views of the data dictionary that are accessible to the user. The selected information includes the name and a short description of each table and view. Before issuing this query, check the column de? nitions of DICT[IONARY] using desc DICT[IONARY] and set the appropriate va lues for column using the format command. The query select ? from TAB; etrieves the names of all tables owned by the user who issues this command. The query select ? from COL; 23 returns all information about the columns of one’s own tables. Each SQL query requires various internal accesses to the tables and views of the data dictionary. Since the data dictionary itself consists of tables, Oracle has to generate numerous SQL statements to check whether the SQL command issued by a user is correct and can be executed. Example: The SQL query select ? from EMP where SAL > 2000; requires a veri? cation whether (1) the table EMP exists, (2) the user has the privilege to access this table, (3) the column SAL is de? ed for this table etc. 3. 2 Data Dictionary Views The external level of the data dictionary provides users a front end to access information relevant to the users. This level provides numerous views (in Oracle7 approximately 540) that represent (a portion of the) data fro m the base tables in a readable and understandable manner. These views can be used in SQL queries just like normal tables. The views provided by the data dictionary are divided into three groups: USER, ALL, and DBA. The group name builds the pre? x for each view name. For some views, there are associated synonyms as given in brackets below. USER : Tuples in the USER views contain information about objects owned by the account performing the SQL query (current user) USER TABLES USER USER USER USER USER USER CATALOG COL COMMENTS CONSTRAINTS INDEXES OBJECTS TAB COLUMNS USER USER USER USER TAB COMMENTS TRIGGERS USERS VIEWS all tables with their name, number of columns, storage information, statistical information etc. (TABS) tables, views, and synonyms (CAT) comments on columns constraint de? nitions for tables all information about indexes created for tables (IND) all database objects owned by the user (OBJ) columns of the tables and views owned by the user COLS) comments on tables and views triggers de? ned by the user information about the current user views de? ned by the user †¢ ALL : Rows in the ALL views include rows of the USER views and all information about objects that are accessible to the current user. The structure of these views is analogous to the structure of the USER views. 24 ALL CATALOG owner, name and type of all accessible tables, views, and synonyms ALL TABLES owner and name of all accessible tables ALL OBJECTS owner, type, and name of accessible database objects ALL TRIGGERS . . . ALL USERS †¦ ALL VIEWS †¦ DBA : The DBA views encompass information about all database objects, regardless of the owner. Only users with DBA privileges can access these views. DBA DBA DBA DBA DBA TABLES CATALOG OBJECTS DATA FILES USERS tables of all users in the database tables, views, and synonyms de? ned in the database object of all users information about data ? les information about all users known in the database 25 4 Application Programming 4 . 1 4. 1. 1 PL/SQL Introduction The development of database applications typically requires language constructs similar to those that can be found in programming languages such as C, C++, or Pascal.These constructs are necessary in order to implement complex data structures and algorithms. A major restriction of the database language SQL, however, is that many tasks cannot be accomplished by using only the provided language elements. PL/SQL (Procedural Language/SQL) is a procedural extension of Oracle-SQL that o? ers language constructs similar to those in imperative programming languages. PL/SQL allows users and designers to develop complex database applications that require the usage of control structures and procedural elements such as procedures, functions, and modules. The basic construct in PL/SQL is a block.Blocks allow designers to combine logically related (SQL-) statements into units. In a block, constants and variables can be declared, and variables can be used to store q uery results. Statements in a PL/SQL block include SQL statements, control structures (loops), condition statements (if-then-else), exception handling, and calls of other PL/SQL blocks. PL/SQL blocks that specify procedures and functions can be grouped into packages. A package is similar to a module and has an interface and an implementation part. Oracle o? ers several prede? ned packages, for example, input/output routines, ? le handling, job scheduling etc. see directory $ORACLE HOME/rdbms/admin). Another important feature of PL/SQL is that it o? ers a mechanism to process query results in a tuple-oriented way, that is, one tuple at a time. For this, cursors are used. A cursor basically is a pointer to a query result and is used to read attribute values of selected tuples into variables. A cursor typically is used in combination with a loop construct such that each tuple read by the cursor can be processed individually. In summary, the major goals of PL/SQL are to †¢ increase the expressiveness of SQL, †¢ process query results in a tuple-oriented way, †¢ optimize combined SQL statements, develop modular database application programs, †¢ reuse program code, and †¢ reduce the cost for maintaining and changing applications. 26 4. 1. 2 Structure of PL/SQL-Blocks PL/SQL is a block-structured language. Each block builds a (named) program unit, and blocks can be nested. Blocks that build a procedure, a function, or a package must be named. A PL/SQL block has an optional declare section, a part containing PL/SQL statements, and an optional exception-handling part. Thus the structure of a PL/SQL looks as follows (brackets [ ] enclose optional parts): [] [declare ] begin [exception ] end; The block header speci? s whether the PL/SQL block is a procedure, a function, or a package. If no header is speci? ed, the block is said to be an anonymous PL/SQL block. Each PL/SQL block again builds a PL/SQL statement. Thus blocks can be nested like blocks in conventional programming languages. The scope of declared variables (i. e. , the part of the program in which one can refer to the variable) is analogous to the scope of variables in programming languages such as C or Pascal. 4. 1. 3 Declarations Constants, variables, cursors, and exceptions used in a PL/SQL block must be declared in the declare section of that block.Variables and constants can be declared as follows: [constant] [not null] [:= ]; Valid data types are SQL data types (see Section 1. 1) and the data type boolean. Boolean data may only be true, false, or null. The not null clause requires that the declared variable must always have a value di? erent from null. is used to initialize a variable. If no expression is speci? ed, the value null is assigned to the variable. The clause constant states that once a value has been assigned to the variable, the value cannot be changed (thus the variable becomes a constant). Example: declare hire date job title mp found salary i ncr †¦ begin . . . end; date; /* implicit initialization with null */ varchar2(80) := ’Salesman’; boolean; /* implicit initialization with null */ constant number(3,2) := 1. 5; /* constant */ 27 Instead of specifying a data type, one can also refer to the data type of a table column (so-called anchored declaration). For example, EMP. Empno%TYPE refers to the data type of the column Empno in the relation EMP. Instead of a single variable, a record can be declared that can store a complete tuple from a given table (or query result). For example, the data type DEPT%ROWTYPE speci? s a record suitable to store all attribute values of a complete row from the table DEPT. Such records are typically used in combination with a cursor. A ? eld in a record can be accessed using . , for example, DEPT. Deptno. A cursor declaration speci? es a set of tuples (as a query result) such that the tuples can be processed in a tuple-oriented way (i. e. , one tuple at a time) using the f etch statement. A cursor declaration has the form cursor [()] is ; The cursor name is an undeclared identi? er, not the name of any PL/SQL variable. A parameter has the form . Possible parameter types are char, archar2, number, date and boolean as well as corresponding subtypes such as integer. Parameters are used to assign values to the variables that are given in the select statement. Example: We want to retrieve the following attribute values from the table EMP in a tupleoriented way: the job title and name of those employees who have been hired after a given date, and who have a manager working in a given department. cursor employee cur (start date date, dno number) is select JOB, ENAME from EMP E where HIREDATE > start date and exists (select ? from EMP where E. MGR = EMPNO and DEPTNO = dno);If (some) tuples selected by the cursor will be modi? ed in the PL/SQL block, the clause for update[()] has to be added at the end of the cursor declaration. In this case selected tuples ar e locked and cannot be accessed by other users until a commit has been issued. Before a declared cursor can be used in PL/SQL statements, the cursor must be opened, and after processing the selected tuples the cursor must be closed. We discuss the usage of cursors in more detail below. Exceptions are used to process errors and warnings that occur during the execution of PL/SQL statements in a controlled manner.Some exceptions are internally de? ned, such as ZERO DIVIDE. Other exceptions can be speci? ed by the user at the end of a PL/SQL block. User de? ned exceptions need to be declared using exception. We will discuss exception handling in more detail in Section 4. 1. 5 4. 1. 4 Language Elements In addition to the declaration of variables, constants, and cursors, PL/SQL o? ers various language constructs such as variable assignments, control structures (loops, if-then-else), procedure and function calls, etc. However, PL/SQL does not allow commands of the SQL data de? nition langu age such as the create table statement.For this, PL/SQL provides special packages. 28 Furthermore, PL/SQL uses a modi? ed select statement that requires each selected tuple to be assigned to a record (or a list of variables). There are several alternatives in PL/SQL to a assign a value to a variable. The most simple way to assign a value to a variable is declare counter integer := 0; †¦ begin counter := counter + 1; Values to assign to a variable can also be retrieved from the database using a select statement select into from where ; It is important to ensure that the select statement retrieves at most one tuple !Otherwise it is not possible to assign the attribute values to the speci? ed list of variables and a runtime error occurs. If the select statement retrieves more than one tuple, a cursor must be used instead. Furthermore, the data types of the speci? ed variables must match those of the retrieved attribute values. For most data types, PL/SQL performs an automatic type conversion (e. g. , from integer to real). Instead of a list of single variables, a record can be given after the keyword into. Also in this case, the select statement must retrieve at most one tuple ! declare mployee rec EMP%ROWTYPE; max sal EMP. SAL%TYPE; begin select EMPNO, ENAME, JOB, MGR, SAL, COMM, HIREDATE, DEPTNO into employee rec from EMP where EMPNO = 5698; select max(SAL) into max sal from EMP; †¦ end; PL/SQL provides while-loops, two types of for-loops, and continuous loops. Latter ones are used in combination with cursors. All types of loops are used to execute a sequence of statements multiple times. The speci? cation of loops occurs in the same way as known from imperative programming languages such as C or Pascal. A while-loop has the pattern [>] while loop ; end loop [] ; 9 A loop can be named. Naming a loop is useful whenever loops are nested and inner loops are completed unconditionally using the exit ; statement. Whereas the number of iterations through a w hile loop is unknown until the loop completes, the number of iterations through the for loop can be speci? ed using two integers. [>] for in [reverse] .. loop end loop [] ; The loop counter is declared implicitly. The scope of the loop counter is only the for loop. It overrides the scope of any variable having the same name outside the loop. Inside the for loop, can be referenced like a constant. ay appear in expressions, but one cannot assign a value to . Using the keyword reverse causes the iteration to proceed downwards from the higher bound to the lower bound. Processing Cursors: Before a cursor can be used, it must be opened using the open statement open [()] ; The associated select statement then is processed and the cursor references the ? rst selected tuple. Selected tuples then can be processed one tuple at a time using the fetch command fetch into ; The fetch command assigns the selected attribute values of the current tuple to the list of variables.After the fetch command , the cursor advances to the next tuple in the result set. Note that the variables in the list must have the same data types as the selected values. After all tuples have been processed, the close command is used to disable the cursor. close ; The example below illustrates how a cursor is used together with a continuous loop: declare cursor emp cur is select ? from EMP; emp rec EMP%ROWTYPE; emp sal EMP. SAL%TYPE; begin open emp cur; loop fetch emp cur into emp rec; exit when emp cur%NOTFOUND; emp sal := emp rec. sal; end loop; close emp cur; †¦ end; 30Each loop can be completed unconditionally using the exit clause: exit [] [when ] Using exit without a block label causes the completion of the loop that contains the exit statement. A condition can be a simple comparison of values. In most cases, however, the condition refers to a cursor. In the example above, %NOTFOUND is a predicate that evaluates to false if the most recent fetch command has read a tuple. The value of %NOTFOUN D is null before the ? rst tuple is fetched. The predicate evaluates to true if the most recent fetch failed to return a tuple, and false otherwise. FOUND is the logical opposite of %NOTFOUND. Cursor for loops can be used to simplify the usage of a cursor: [>] for in [()] loop end loop []; A record suitable to store a tuple fetched by the cursor is implicitly declared. Furthermore, this loop implicitly performs a fetch at each iteration as well as an open before the loop is entered and a close after the loop is left. If at an iteration no tuple has been fetched, the loop is automatically terminated without an exit. It is even possible to specify a query instead of in a for loop: for in () loop end loop; That is, a cursor needs not be speci? d before the loop is entered, but is de? ned in the select statement. Example: for sal rec in (select SAL + COMM total from EMP) loop †¦ ; end loop; total is an alias for the expression computed in the select statement. Thus, at each iterati on only one tuple is fetched. The record sal rec, which is implicitly de? ned, then contains only one entry which can be accessed using sal rec. total. Aliases, of course, are not necessary if only attributes are selected, that is, if the select statement contains no arithmetic operators or aggregate functions. For conditional control, PL/SQL o? rs if-then-else

Voluntarily Assuming Liability under the Law of Contract Case Study

Voluntarily Assuming Liability under the Law of Contract - Case Study Example The classic test for the imposition of a duty of care was articulated in Caparo Industries v Dickman. Accordingly, a duty of care will exist only where there is foreseeability, proximity and if the imposition of a duty of care is fair and reasonable in the circumstances.   Norris argues that in applying the test articulated in Caparo, it is necessary to determine whether or not a duty of care was assumed by the defendant and whether or not it was reasonable for the plaintiff to rely on the defendant’s assumption. It is important to note, however, that the assumption of responsibility and reliance on the duty are not conclusive evidence of the existence of a duty of care, but maybe â€Å"one of the ways in which the necessary degree of proximity may arise.† On the facts of the case for discussion, Alan asked John to take his keys from him if he drank too much that night at John’s house. The two proceed to drink two bottles of wine followed by brandy coffee.   It was stated how the wines were proportioned out between them and whether or not Alan drank too much throughout the evening.   Regardless, Alan indicated that he felt able to drive and nothing was made of it.   In any event, it does not appear that the consumption of alcohol had anything to do with the accident.   The fallen tree was the cause of the accident and the main question is whether or not, John’s call to Allan caused him to collide with the fallen tree and whether or not John assumed responsibility for preventing personal injury to John when he placed that telephone call.

Wednesday, August 28, 2019

Journalism, Mass Media and Communication Essay Example | Topics and Well Written Essays - 1000 words

Journalism, Mass Media and Communication - Essay Example Journalism is an activity that can be described as one that defines journalists. It is the system in which journalists get to engage the public, and this can be in terms of written, visual or audio material. Journalism is done with the intention of bringing the news to the public. It is about making the community aware of their surroundings. Through journalism, mass media and communication, the public is able to know how the world they live in operates. They have a sense of guidance and cause change in places is needed. The ongoing events in the day to day lives partly depend on the influence of journalists. This is the reason why mass media is a very important tool in any country. They are able to influence what people think, see and hear. They are able to make stories and events known within a short time. The media is an important tool, one which is used to inform on upcoming events that might directly affect the people. Over the years, the mass media has faced criticism, praise an d also ridicule because of the way they have handled themselves. In modern times, the press has been used to make false statements, show false news, hide some information and also reveal some of the worst known secrets. Journalists have been put in the spotlight over the various news that they have written. They have been charged with intimidation, violence and harassment, but all this is because of the temperament of their occupation. There are different forms of providing news to the public. They include broadcasting over the television and radio stations, newspapers, journals, magazines, and the other important one is the internet. In this essay, attention will be focused towards the newspaper section and its popularity and influence in the United States and China. The newspaper section takes up a lot of heat when it comes to the transmission of news to the public (Hallin & Mancini, 2004). A newspaper is a publication that is periodical and contains news that regard the current a tmosphere and events. It covers the diverse features, editorials, and the advertising bit of marketing. The newspaper can be termed as one of the greatest prominent mass media device that exists. This is because they are printed daily, and are relatively cheap and contain a lot of information regarding the current events and happenings of a place. There are millions of newspaper copies that are sold on a daily basis because they do cover a lot of published material. Some of the things published in a newspaper include editorial opinions about the writing, criticism of or for the writing, persuasion publishing and op-ed, obituaries, entertainment facilities and features that include things such as  crosswords,  Sudoku  and horoscopes (Hallin & Mancini, 2004). There are also news about the weather and  forecasts on certain areas and places. There are also the facilities of advice,  food  and other columns such as reviews of ‘radio’, ‘movies’, †˜television’, ‘plays’ and ‘restaurants’. The newspaper also has  classified advertisements that include the ‘radio’ and ‘television’ listings, inserts from ‘local merchants’,  cartoons and comics. These are just some of the facilities that a newspaper carries. It is because of the various facilities that it offers that it gets the popularity. Newspaper popularity in the United States is less pronounced and common than in the republic of China. When looking at the popularity of the newspaper in the United States, it is safe to say that the newspaper industry in the United States supplies fewer newspapers in a day than their Chinese counterparts. Looking at the average of the newspaper circulation between the United States and China, it is safe to say that newspapers are less popular in the United States than in China and Japan (Hallin & Mancini, 2004). There are many factors that can attribute to this. One i mportant factor is the factor that concerns

Tuesday, August 27, 2019

Implementation of ecotourism principles in Pembrokeshire Coastal Research Paper

Implementation of ecotourism principles in Pembrokeshire Coastal National Park - Research Paper Example arch is carried out which discusses about the implementation of ecotourism in Pembrokeshire Coastal National Park (PCNP) and the reasons why it has been referred as an ecotourism site. The procedure thus followed in this project is mainly secondary and descriptive research followed by primary research.  (Visit Prembrokeshire 2009; Prembrokeshire coast National Park, n.d.; Stopher and Metcalf, 1996)    Primary data being a direct source of information is more reliable as it is collected directly by interviewing the relevant person or from government records. There is no possibility of the data being modified by a third party and this helps in deciding which analytical techniques to use and how to interpret the results. There cannot be a better way to study the tourism industry, which is formed by tourists from different cultural and emotional background, and whether they as well as the local people are aware of the importance of sustainable development and their views about the implementation of ecotourism. At times, much relevant information cannot be gathered from official sources. First- hand information hence can be more apt.   But one disadvantage of primary research is that, it may not be always possible for individuals to travel due to time and financial constraints. (Ithaca College library, August 2009) The secondary research done here is based on existing works in this field. The resources are gathered from government publications, books, journals and articles of the United Nations Environment Program and economic periodicals. This is the very essence of secondary research. Such a research is advantageous as it saves time and money incurred for the research with easy and fast  collection of data. Often secondary data is available for broad subjects about which it would be impossible to gather primary data. But the negatives lies in the fact that the quality of secondary research need to be scrutinized as the source is questionable and there is a

Monday, August 26, 2019

Approaches of the Balance of Payment Essay Example | Topics and Well Written Essays - 500 words

Approaches of the Balance of Payment - Essay Example Balance of payment is an important section of the national economy of a country. It constitutes a major part. The report will primarily highlight the importance and relevance of balance of payment. Further it will emphasize on one of its approaches and will depict the importance of that approach in the present business environment. However in this respect, the elasticities approach will be highlighted. Similarly its relevance in the present business environment will be discussed. Nevertheless before getting into the discussion a brief overview of balance of payment is presented below:- The Balance of payment (BOP) can be referred to as one of the economic indicators which are mainly used to determine the political and economical stability of a country (Nayak 172). It takes into account the trade balance, financial transactions with the other countries for a specific period of time. Apart from this balance of payment distinguishes all the exports and imports, which embraces all the financial transactions, and it also differentiates monetary differences of the economic transactions. Now in the context of a country, if it has a positive BOP, then it signifies that a country has more funds coming in from the international trade than going out. While negative BOP illustrates that, a country has more funds flowing out than coming in. Elasticities approach is an approach of BOP that tries to predict the outcome after the impact of policy changes on BOP. In order to cite an example, elasticities approach primarily shed light on the impact of exchange rate on the balance. Furthermore, if the balance of payment is in equilibrium state, the elasticities approach assumes that the devaluation can certainly enhance BO (Gagnon, â€Å"Long-run supply effects and the elasticities approach to trade†). However devaluation to perform successfully, price elasticities of foreign demand of import and domestic demand has to

Sunday, August 25, 2019

Discussion for online Healthcare HRM Essay Example | Topics and Well Written Essays - 250 words

Discussion for online Healthcare HRM - Essay Example Human resource in the healthcare setting interacts with a group of people who are highly sensitive to the environment around them due to their respective health complications. On the same note, all the stakeholders in the health care setting work towards promoting patient welfare, and so should the attitude and perception exhibited in this setting. In this respect, the realized performance outcomes rely on the basis of interaction between healthcare practitioners and the patients, thus making attitude and perception direct influential variables on performance. The integration of attitude and perception into an evaluation process should account for the links and relations between the human resource and all the other parties present in the healthcare setting, especially the patients. While this would be a positive move, the legal aspect of the matter could be highly bureaucratic, thereby slowing down the integration process and challenging the basis of operation of the evaluation system. On the same note, the likelihood of discrimination issues against human resource arising could be relatively high (Flynn, Mathis, Jackson & Langan, 2007). Moreover, the need to set measurement variables for the purpose of undertaking the evaluation becomes

Saturday, August 24, 2019

Biotic Components Essay Example | Topics and Well Written Essays - 1000 words

Biotic Components - Essay Example The beginner of the pond ecosystem is sun. Producers use sunlight and convert carbon dioxide and water into organic compounds and oxygen through a process called photosynthesis. Other most important nutrition for plants is nitrogen and phosphorus. Wandering plants or the phytoplankton (Volvox, Oscillatoria, Diatoms, Spirogyra, Zygnema, Hydrodictyon, Desmids, etc) go through the process of photosynthesis and release oxygen in the water which can be used by bacteria and animals in the pond. Likewise, the Periphytic algae (attached to the rocks and other substances) carry out photosynthesis and provide oxygen in the bottom of the pond so the decomposers can use it. The submerged plants and the Floating plants (Nelumbium, Nymphea, Blixa, Eicchornia, Pistia etc) provide oxygen to the pond and the emergent plants, to the environment outside the pond. This is the first level. Herbivores and carnivorous belong to the second level and are called consumers. Herbivores feed on plants and get en ergy whereas the carnivores feed on herbivorous and get energy. But whenever an animal or a plant is not consumed by any other animal, that matter is decomposed by decomposers, which are on the 3rd level. The tissues are broken down into much simpler compounds which are again used by the plants for nutrients. As energy is converter, some of it is released in the form of heat in the water to maintain the inner functions of the cells in every organism. Nutrient cycle Carbon, nitrogen, and oxygen are really important for a cell. The process through which these substances pass from on organism to another or from on cell to the other is called nutrient cycle. Change over time The health of an ecosystem can be endangered by several changes over time. If specie is killed in the pond, it can be highly dangerous for other living in the pond as many animals might feed on that specie for nutrients and the whole system might crash. Due to the climate change, excessive heat in the environment, d rought can appear killing all the species living there. The growth of thick trees around the pond can block the passage of sunlight to the pond, resulting in death of plants and thus the animals. Besides this, natural succession can occur which can totally change the biotic community. It actually occurs due to the changes in the plants, animals or other a-biotic factors, and so a new eco cycle can begin How humans may have affected biogeochemical cycles in that ecosystem. There are many ways a human might affect the pond ecosystem. Nitrogen cycle affected: During transportation, ammonia is released in the atmosphere, which is absorbed in the pond. Fertilizers are highly harmful for the fishes as it contains nitrites and nitrates and thus can affect the nitrogen cycle. Ammonia is extremely toxic to fish and should be removed or converted into harmless matter. If the level of ammonia increases in the pond, fishes can die. New agricultural practices have highly disturbed the nitrogen c ycle of the pond. In order to fulfill the agricultural demands for food, there is an extensive usage of nitrogen gas in the green house which enters the pond through different means. Carbon cycle affected: Accumulation of Carbon dioxide in the pond is highly dangerous for the fish species living in it. If the carbon dioxide amount is high in the pond, it would be difficult for the fishes to remove their internal carbon dioxide in the water, resulting in accumulation in fish blood. This inhibits and endangers the ability of hemoglobin in the fish blood, and thus causes suffocation for fishes.

Friday, August 23, 2019

Modern World History Essay Example | Topics and Well Written Essays - 750 words

Modern World History - Essay Example Death-feud and antagonism between the states is one of the most dangerous evils which pressures mankind through all historical periods of time. In contrast to this confrontations, the primary goal of nation-states' policies is to ensure their survival. That is, states seek to preserve their independence or sovereignty in a hostile environment. During the XX centuries, two world wars showed that the world's fate hinged on the outcome of this massive effort to meet the Axis threat of world conquest and restore the balance of power. In this hostile environment, the United Nations became a strong force which balanced confrontations and peace. The significance of the UN can be explained by the fact that previous attempts to achieve the world order had failed, but the end of the WWII demanded a strong international organization to ensure global peace. In 1945, despite the emergent differences between the United States and the Soviet Union, World War II, like all previous great-power wars, paved the way for a new world order. The League of Nation had failed to meet new social and political landscape between the Second World War. In 1943, the Four Power Declaration advanced principles for allied collaboration in the period following the end of military confrontations (Hyde, 1960). The product of the Allies' determination to create a new international organization to manage the postwar international order was conceived in this and other wartime agreements. Consistent with the expectation that the great powers would cooperate to manage world affairs, China was promised a seat on the United Nations Security Council along with F rance and the Big Three. The purpose was to guarantee that all of the dominant states would share responsibility for keeping the peace (Mcwhinney, 1984). In 1945, the UN represented a supranational level - a political body that exerted influence upon several national governments. On the other hand, the UN was used as 'a silent tool' of competition between the USA and USSR. Both countries used the United Nations not to keep the peace, but to pursue their competition with one another. As the most recent great-power war of the twentieth century, it still casts its shadow over the post-Cold War geostrategic landscape. Perhaps the most certain feature of this otherwise uncertain environment was the ascendancy of the United States and the Soviet Union as its dominant powers (Debrix, 1999). Today, the UN has lost its strategic significance in contrast to 1945, and for this very reason many political leaders and scientist suppose that: "'the role of the United Nations as a whole in economic and social affairs, including its relationship to the Bretton Woods institutions needs to be re-thought and reinvigorated" (Murithi, 2003, p.3). The end of the Cold War and the War on Terror demonstrated that the USA can survive indefinitely. Russia has made the transition over the last ten years to an independent democratic nation state. The emergence of new economic centers the Triad and European Union, NAFTA and ASEAN reduce the role and impact of the UN on the global peace and foreign relations. At the beginning of the 21st century, the global regulatory environment consists of a variety of governmental and nongovernmental agencies that enforce laws or set guidelines for conducting business and political affairs (Graham, 2003, p. 5). A change process lies at the

Thursday, August 22, 2019

Essay on the Russian Revolution Essay Example for Free

Essay on the Russian Revolution Essay The Russo-Japanese War lasted from 1904 to 1905, and arose from both Japan and Russia’s desire for expansion and dominance in Korea and Manchuria. Russia suffered many great defeats in this war, against a nation that was considered inferior and was not one of the Great Powers. This humiliated the people of Russia, and caused them to lose confidence in Tsar Nicholas II, as well as causing great military, economic, and political problems for Russia. When the Russo-Japanese War erupted in 1904, Russia was not fully prepared to involve itself in a war. The Trans-Siberian Railway was not completed and would not be until 1905, so Russias army was not fully mobile. Russia’s inability efficiently mobilize caused them to lose battles to the Japanese and to eventually lose the war itself. The Russians were optimistic; as they were sure their vast superiority of numbers would easily defeat the tiny Japan, but this was not to be. Japan, with their advanced technology destroyed the Russian Army, armed with their primitive weapons as compared to the Asians. Huge military defeats were caused by the Russo-Japanese War, which highlighted the weakness of the military and caused national humiliation. Russia, all along had prided themselves on military excellence. An example of such a defeat was in January 1905 when the army had to surrender their Port Arthur naval base in Northern China, which they had possessed before the start of the war. Another example of a great failure of the military was at the Battle of Tsushima in May 1905. The Russian Baltic fleet consisting of the 35 warships had sailed from northern Europe to the Far East, only to lose 25 warships in a defeat by the Japanese navy. The crushing of Russian’s military added impetus to the 1905 Revolution, as it made the people of Russia aware of the weakness of their military and ashamed to be Russian. They were losing to a nation very few had heard of and it was humiliating,  this caused the opposition to autocratic rule by the Tsar Nicholas II. The Russo-Japanese War brought about economic problems for Russia, and this therefore meant there was a significant lack of money to solve any other problems present Russia. The war, as all wars do, cost an extreme amount of money. As it resulted in failure no money could be gained from the invaded territories. Russia had already had economic problems, and its economy was still far behind that of other Great Powers. Russia needed more money to invest in the economy to enlarge it, to make it more comparable to other Great Powers. The backwardness of Russia compared to these other Great Powers was another source of national humiliation for the people of Russia. Furthermore, the lack of money meant that the government could do nothing about the living and working conditions in towns and cities, or the problems in the rural areas of Russia. Consequently, the economic problems brought about a dent in national pride and Russia’s being unable to solve any of its other problems due to financial constraints. Both the peasants and the landowners were suffering. People were starving Agriculture was very behind that of other countries, as under the Witte system nothing had been done to improve it. Therefore the land was not cultivated properly, and famines occurred quite regularly such as the one in 1902 as well as the one in 1905, even with all this the peasants were still required to provide food for the Russian Army at war. There were also political implications of the Russo-Japanese War. The war was fought in the very far eastern reaches of the country, far away from where the majority of the population lived, and hence they must have felt removed from it, especially as news was still slow to travel. There was therefore little public enthusiasm for the war. Many people felt there was little justification for it: public opinion was not on the side of the war. Moreover, the military was very ill-equipped for the war. This showed to the people of Russia the government’s failings, and caused people to turn away from the Tsar as a leader, and look elsewhere, such as to political groups who were prepared to take radical action to achieve their aims, the people had lost faith in the Tsar. Political groups such as the Bolsheviks and Mensheviks took advantage of the peasant discontent and tried to turn the peasants against the Czar and more towards radicalism and liberalism. On Sunday, 22nd January 1905, more than 200 000 workers, led by a priest of the church by the n ame of Father Gapon, took  part in a peaceful demonstration in St. Petersburg (later known as Petrograd, and then Leningrad). They proceeded to the Winter Palace to present a petition to the Tsar. The petition, written by Gapon, made clear the problems and opinions of the workers and called for improved working conditions, fairer wages, and a reduction in the working day to eight hours and medical benefits. Other demands included an end to the Russo-Japanese War and the introduction of universal suffrage. They also wanted a parliament, or a Duma, to represent their views. The unarmed demonstrators were shot at by the Tsars troops (The Imperial Guard). This is referred to as the â€Å"Bloody Sunday†. There were many outbursts after that. Troops mutinied, peasants rose up and there were strikes and riots emerged. In the October Manifesto which was drafted by Sergei Witte, who became Russias first prime minister, Tsar Nicholas II was forced to : (1) Grant to the population the inviolable right of free citizenship, based on the principles of freedom of person, conscience, speech, assembly, and union. (2 ) Without postponing the intended elections for the State Duma and insofar as possible †¦ to include in the participation of the work of the Duma those classes of the population that have been until now entirely deprived of the right to vote, and to extend in the future, by the newly created legislative way, the principles of the general right of election. (3) To establish as an unbreakable rule that without its confirmation by the State Duma, no law shall go into force and that the persons elected by the people shall have the opportunity for actual participation in supervising the legality of the acts of authorities appointed by it† A Duma was elected in 1906, dominated by the middle-class Kadet party, the Duma was supposed to be able to enact legislation that would bind even the Tsar but even this proved too radical in its demands for the Tsar. The Tsar was determined to preserve his autocracy even in the context of reform and he restricted the Dumas authority in many ways. The Tsar issued the Fundamental Laws. It stated in part that Tsars ministers could not be appointed by, and were not responsible to, the Duma, thus denying responsible government at the executive level. Furthermore, the Tsar had the power to dismiss the Duma and announce new elections whenever he wished. He also restricted the franchise to the property-owning classes. The Tsar never allowed the Duma to be anything more than an advisory committee. This idealized vision of the  Romanov monarchy blinded him to the actual state of his country. With a firm belief that his power to rule was granted by Divine Right, Nicholas assumed that the Russian people were devoted to him with unquestioning loyalty. This ironclad belief rendered Nicholas unwilling to allow the progressive reforms that might have alleviated the suffering of the Russian people. Tsar Nicholas II tried to deal with the pressures for change by increasing police powers; there was brutal suppression of dissent and the civil rights granted in 1905 gradually restricted. Witte resigned and was replaced in July by Stolypin, who combined ruthlessness in dealing with unrest with a thoughtful programme of agrarian reform which tried to remove the legacy of debt and land hunger and create a class of peasant farmers loyal to the regi me. Stolypin had fallen out with the Tsar even before he was assassinated in 1911, and after this Nicholass ministers were of limited ability. Even before the start of the First World War unrest was breaking out again, but the onset of war, and the rapidity and magnitude of Russian defeats, greatly weakened the political and economic structure of the country. Alexis, Tsar Nicholas IIs son suffered from haemophilia, where his blood was unable to clot after bleeding due to a lack of platelets in the blood. Rasputin claimed to be a holy monk from the remote wastelands of Siberia, and was able to use his supernatural healing powers to heal Alexis. Granted, Rasputin could ease some of Alexis pain, but most of what he did seemed a scam .The Tsarina (the Tsars wife) doted on her son and thus naturally treated the monk better, since Grigori Rasputin did what doctors couldn’t do, which was to help her son with his sickness and to help stop his pain. In 1911 Stolypin ordered Rasputin out of St. Petersburg, and the order was obeyed. Stolypins minister of religion, Lukyanov, on the reports of the police, ordered an investigation that produced abundant evidence of Rasputins scandalous deeds. From this time on, the Tsarina detested Prime Minister Stolypin. After Stolypin was assassinated, the Tsarina brought Rasputin back to St. Petersburg. Rasputin abused his authority and replaced many ministers with his own family and friends, regardless of whether the previous ministers were good. Some of his decision in the countrys administration were also foolish and led to many problems. This naturally led to people disliking Rasputin severely and thus blaming the Tsar for his trust in this incompetent person. In 1915 Tsar Nicholas II unwisely chose to take direct command of field operations, personally overseeing Russia’s main theatre of war, leaving his German wife, Tsarina Alexandra as regent in charge of affairs in the capital. Alexandra was very unpopular with the Russian people, who accused her of collaboration with the Germans. Alexandra had no experience of government and under the influence of Rasputin constantly appointed and re-appointed incompetent new ministers, which meant the government was never stable or efficient. This was particularly dangerous in a war of attrition, as neither the troops nor the civilian population were ever adequately supplied; the country was plunged into further state of crisis. By 1917 the regime was in a parlous state with revolutionary unrest spreading among the troops and workers, peasants seizing the large estates and (a decisive new factor compared with the events of 1905) signs of disunity and disaffection amongst the ruling à ©lite and police, first shown in the murder of Rasputin by conservative nobles on Dec. 31, 1916. When Nicholas II entered the First World War, his desire was to restore the prestige that Russia had lost during the Russo-Japanese war. Nicholas wanted to galvanize the diverse people in his empire under a single banner by directing military force at a common enemy, namely Germany and the Central Powers. A common assumption among his critics is that he believed that by doing so he could distract the people from the ongoing issues of poverty, inequality and poor working conditions that were sources of discontent. Instead of restoring Russia’s political and military standing, World War I lead to horrifying military casualties on the Russian side and undermined it further. By 1915 (during World War I), there were manifold signs that the economy was breaking down under the heightened strain of wartime demand and the Tsar’s mis-management of the country’s funds. Over fifteen million men joined the army( due to conscription), which left an insufficient number of workers in the factories and on the farms. Conscription also stripped skilled workers from the cities and they had to be replaced with unskilled peasants. The result was widespread shortages of food and materials. Factory workers had to endure terrible working conditions, including twelve to fourteen hour days and low wages. Many riots  and strikes for better conditions and higher wages broke out. Although some factories agreed to the requests for higher wages, wartime inflation nullified the increase. Industrial workers went on strike and effectively paralyzed the railway and transportation networks. What few supplies were available could not be effectively transported. As goods became more and more scarce, prices skyrocketed. People were suffering, they began to turn to prostitution or crime( there was an increase in crime), people were begging, they were tearing down wooden fences to keep stoves heated for warmth. Also famine threatened many of the larger cities. The vast demand for factory production of war supplies and workers caused many more labor riots and strikes. In addition, because more factory workers were needed, peasants moved out of the country and into the cities, which soon became overpopulated, and living conditions rapidly grew worse. Furthermore, as more food was needed for the soldiers, the food supply behind the front grew scarce. Soldiers themselves, who were suffering from lack of equipment and protection from the elements, began to turn against the Tsar. This was mainly because as the war progressed, many of the officers who were loyal to the Tsar were killed and they were replaced with discontented conscripts from the major cities who were much less loyal to the Tsar. Russia’s first major battle was a disaster. In the 1914 Battle of Tannenberg, over 120, 000 Russian troops were killed, wounded or captured, while Germany suffered only 20,000 casualties. In 1915, things took a critical turn for the worse, when Germany shifted its focus of attack to the Eastern front. The superior German army destroyed the unequipped Russian forces. By the end of October 1916, Russia had lost between 1.6 and 1.8 million soldiers with an additional two million prisoners of war and one million missing. Soldiers went hungry and lacked shoes, ammunition and weapons. Rampant discontent lowered morale, only to be further undermined by a series of military defeats. The Tsar was blamed for all these crises and what little support he had left began to crumple. As this discontent grew, the State Duma issued a warning to Nicholas in November of 1916 stating that disaster would overtake the country unless a constitutional form of government was put in place. In typical fashion, Nicholas ignored them. The people were upset with the Tsar and his lack of care about his people. He was the reason they were suffering. The people were disgusted with his inept handing of the  country. Alexander Kerensky was a young and popular lawyer who gained a reputation for his work as a defense lawyer in a number of political trials of revolutionaries. Afterwards he gained a reputation for his work as a defence lawyer in a number of political trials of revolutionaries. He was elected to the Fourth Duma in 1912 as a member of the Trudoviks, a moderate labour party who were associated with the Socialist-Revolutionary Party. He was a brilliant orator and skilled parliamentary leader of the socialist opposition to the regime of the ruling Tsar, Nicholas II. When the February Revolution broke out in spring of 1917, Kerensky was one of its most prominent leaders: he was a member of the Provisional Committee of the State Duma and was elected vice-chairman of the Petrograd Soviet. He simultaneously became the first Minister of Justice in the newly formed Provisional Government. Kerensky became the Minister of War and the dominant figure in the newly formed government and in July of that same year he became Prime Minister. However, as Prime Minister he made two major errors. He ensured that Russia stayed in a war that was detested in the country itself. The overwhelming bulk of the population wanted Russia to withdraw from the war. There must have been few families, especially among the poor, who had not experienced personal tragedy between 1914 and 1917. His second mistake was not to offer the peasants land. Lenin did just this and immediately got the support he and the Bolsheviks needed at the expense of Kerensky. Kerensky also invited the Mensheviks to take part in the administration. To undermine the support of the Bolsheviks, Kerensky ordered that elections should take place for a constituent assembly. The elections were to be held in January 1918. Lenin had called for such elections earlier in 1917, so he could not object to this. As Kerensky argued, it was simply an extension of the democratic process denied to the people by the Romanovs. However, all the evidence indicated that the Bolsheviks would have done less well than other groups including the Mensheviks. On September 1st 1917, Kerensky declared Russia a republic. Vladimir Lenin was exiled in neutral Switzerland, when he heard of the revolution he made arrangements with the German government for permission to travel back to Russia. German officials agreed, evidently assuming that Lenin’s activities might weaken Russia, or if the Bolsheviks  came to power, lead to Russia withdrawing from the war with Germany. He arrived in Petrograd in April 1917. Lenin demanded that the Provisional Government give â€Å"All Powers to the Soviets† in addition to the speedy conclusion of the war without annexation, the renunciation of all secret diplomatic agreements, the control of factories by workers and the immediate seizure of land by peasants. He convinced his Bolshevik supporters that the seizure of power by the Soviets would be the signal for a European-wide socialist revolution. To prepare for the seizure of power, his Bolshevik supporters set out to win support from the masses in the soviets. Vladimir Lenin was the architect and first head of the USSR, led the October Revolution, which was effectively a coup detat. Lenin justified his violent seizure of power from the Provisional Government as merely a transfer of authority to the soviets, the popular councils elected by workers and soldiers that sprang up everywhere after the fall of the tsar. Lenin declared the formation of a Soviet government, withdrew Russia from World War I, and invited the peasants to take charge of the land that had formerly belonged to the nobles, state, and church. At the same time, Lenins government quickly moved to shut down opposition political parties and to censor the press, introduced conscription for the Red Army, and requisitioned grain from the peasants in order to fight the bloody Russian Civil War of 1918–1920. In January 1918, Lenin closed down the Constituent Assembly after the Bolsheviks won only 24 percent of the popular vote. In 1918, Lenin renamed the Bolshevik Party as the Communist Party. Although Lenin was ruthless, he was also pragmatic. When his efforts to transform the Russian economy to a socialist model stalled, he introduced the New Economic Policy, where a measure of private enterprise was again permitted, a policy that continued for several years after his death. In 1918, Lenin narrowly survived an assassination attempt, but was severely wounded. When Lenin was badly injured in a failed assassination attempt on August 30, 1918, his government quickly responded with the September 5, 1918, announcement of a policy of Red Terror that would take the form of arrests, imprisonments, and murders. Trotsky was a Marxist and for a long time worked as an independent  revolutionary in Russia. Before 1914 he had attempted to bring about great cooperation between the Mensheviks and the Bolsheviks but her failed. In 1917, after the March Revolution, he returned from exile in America. In July, he decided to join the Bolsheviks. Leon Trotsky was a Communist theorist, prolific writer, leader in the 1917 Russian Revolution, and the peoples commissar for foreign affairs under Lenin and then head of the Red Army as the peoples commissar of army and navy affairs. He was also elected as the President of Petrograd Soviet. Joseph Stalin was a Bolshevik leader who became prominent only after Lenin’s return to Petrograd in April 1917. Although Stalin was very much a secondary figure during the October Revolution, he did gain Lenin’s attention as a useful ally. Stalin had a very important, yet secretive job. He was to provide disguises and safe houses and to arrange safe passage out of Petrograd to Finland, with guides and bodyguards, for Lenin, had the revolution not worked out as planned. Following the October coup, Lenin gave him a position in the government as commissar of nationalities. As Stalin was a member of an ethnic minority as he was from the central Asian region of Georgia, not Russia. Lenin felt he would be an effective ambassador of sorts to the many ethnic minorities within the former Russian Empire. After the revolution, Stalin became increasingly powerful and eventually succeeded Lenin as leader of the Soviet Union upon Lenin’s death in 1924. Kerensky Provisional Government fell On October 25-26, 1917when Vladimir Lenin and his Bolshevik supporters overthrew it in the October Revolution (coup d etat). There are many reasons as to why the provisional government fell. The Provisional Government fell because they insisted to continue fighting in the First World War, although things were going so badly. Millions of soldiers were dead and injured, also the soldiers lacked proper equipment and weapons to fight effectively, and they also had little to no training in war tactics. Also the failure of the Brusilov offensive is an important factor. The Provisional Government also did not solve the economic problems that Russia was facing. There were stills strikes and riots. Shortages continued and the people saw now improvement. By this time there was subsequent unpopularity of Alexander Kerensky who the most prominent person off the Provisional Government (War Minister and Prime Minister). Also in October with the crisis building, the Bolsheviks saw the opportunity to seize important institutions in Petrograd  such as banks and railways. The Russian Civil War, which broke out in 1918 shortly after the revolution, brought death and suffering to millions of people regardless of their political orientation. The war was fought mainly between the Red Amy (Reds), consisting of radical communist and revolutionaries, and the Whites consisting of: the monarchist, conservatives, liberals and moderate socialist who opposed the drastic restructuring championed by the Bolsheviks. The Whites has backing from nations such as the UK, France, USA and Japan. Also during the Civil War, Nestor Makhno led a Ukrainian anarchist movement which generally cooperated with the Bolsheviks. However, a Bolshevik force under Mikkhail Frunze destroyed the Makhnovist movement, when the Makhnovists refused to merge into the Red Army. In addition the so-called â€Å"Green Army† (nationalist and anarchist played a secondary role in the war, mainly in Ukraine.