More SQL functions As usual,there is additional information in the speaker notes!

Slides:



Advertisements
Similar presentations
Creating an Oracle Database Table Additional information is available in speaker notes!
Advertisements

PL/SQL User Defined Types Record and Table Please use speaker notes for additional information!
Reports Using SQL Script Please check speaker notes for additional information!
Order Entry System Please use speaker notes for additional information!
Line Efficiency     Percentage Month Today’s Date
Group functions using SQL Additional information in speaker notes!
Relational example using donor, donation and drive tables For additional information see the speaker notes!
Using input variables Please use speaker notes for additional information!
PL/SQL - Using IF statements Please use speaker notes for additional information!
More on IF statements Use speaker notes for additional information!
Java Programming Working with TextPad. Using TextPad to Work with Java This text editor is designed for working with Java You can download a trial version.
Introduction to PL/SQL
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
SQL Use of Functions Character functions Please use speaker notes for additional information!
SQL functions - numeric and date Speaker notes contain additional information!
Cursors in PL/SQL Includes cursor example and continuation of first cursor example Please use speaker notes for additional information!
More on variables with Oracle’s SQL*Plus As always, speaker notes will contain additional information!
XML and DTD Please you speaker notes for additional information!
1 A Guide to SQL Chapter 2. 2 Introduction Mid-1970s: SQL developed under the name SEQUEL at IBM by San Jose research facilities to be the data manipulation.
Oracle 11g: SQL Chapter 10 Selected Single-Row Functions.
Intro to SQL| MIS 2502  Spacing not relevant › BUT… no spaces in an attribute name or table name  Oracle commands keywords, table names, and attribute.
More on views Please refer to speaker notes for additional information!
SQL and Conditions Speaker notes will provide additional information!
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
Functions Please use speaker notes for additional information!
Exceptions in PL/SQL Please use speaker notes for additional information!
Indexes in Oracle An Introduction Please check speaker notes for additional information!
Introduction to Oracle - SQL Additional information is available in speaker notes!
Working with Columns, Characters, and Rows. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Apply the concatenation.
More on Primary and Foreign Keys Please see speaker notes for additional information!
Introduction to PL/SQL As usual, use speaker notes for additional information!
This is an example text TIMELINE PROJECT PLANNING DecOctSepAugJulyJuneAprilMarchFebJanMayNov 12 Months Example text Go ahead and replace it with your own.
PHP with MYSQL Please use speaker notes for additional information!
More about maintaining a table Use speaker notes for additional information!
Jan 2016 Solar Lunar Data.
SQL and SQL*Plus Interaction

More on Oracle Scripts CSC 240 (Blum).
Introduction to Procedures
Q1 Jan Feb Mar ENTER TEXT HERE Notes
MySQL - Creating donorof database offline
Project timeline # 3 Step # 3 is about x, y and z # 2
Average Monthly Temperature and Rainfall

Timeline PowerPoint Template
Introduction to Views and Reports

Gantt Chart Enter Year Here Activities Jan Feb Mar Apr May Jun Jul Aug

Bringing up SQL plus at BCC.
Step 3 Step 2 Step 1 Put your text here Put your text here
MONTH CYCLE BEGINS CYCLE ENDS DUE TO FINANCE JUL /2/2015
2009 TIMELINE PROJECT PLANNING 12 Months Example text Jan Feb March

More and Still More on Procedures and Functions
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3

Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Project timeline # 3 Step # 3 is about x, y and z # 2

2009 TIMELINE PROJECT PLANNING 12 Months Example text Jan Feb March
Presentation transcript:

More SQL functions As usual,there is additional information in the speaker notes!

Decode function SQL> SELECT name, jobcode, salary, 2 DECODE(jobcode, 'CI', salary *1.03, 3 'IN', salary *1.025, 4 'AP', salary *1.02, 5 'CM', salary *1.015, 6 salary) 7 proposed_new_salary 8 FROM first_pay; NAME JO SALARY PROPOSED_NEW_SALARY Linda Costa CI John Davidson IN Susan Ash AP Stephen York CM Richard Jones CI Joanne Brown IN Donald Brown CI Paula Adams IN DECODE allows the implementation of a CASE or IF…THEN…ELSE structure. This command decodes the field jobcode and then performs a task. The results go in proposed_new_salary. In this case, if jobcode is CI then salary is multiplied by 1.03 and the result is stored in proposed_new_salary.

Decode function 1 SELECT name, jobcode, salary, 2 DECODE(salary, 45000, salary * 1.03, , salary * 1.035, , salary * 1.05, 5 salary * 1.025) 6 proposed_new_salary 7 FROM first_pay; DECODE of salary resulting in proposed_new_salary. Three salaries get specific raises all the rest are handled with salary * NAME JO SALARY PROPOSED_NEW_SALARY Linda Costa CI John Davidson IN Susan Ash AP Stephen York CM Richard Jones CI Joanne Brown IN Donald Brown CI Paula Adams IN

Fixing problems with coding errors SQL> SELECT name, jobcode, salary 2 DECODE(salary, 45000, salary * 1.03, , salary * 1.035, , salary * 1.05, 5 salary *.025) 6 proposed_new_salary 7 FROM first_pay; DECODE(salary, 45000, salary * 1.03, * ERROR at line 2: ORA-00923: FROM keyword not found where expected SQL> 1 1* SELECT name, jobcode, salary SQL> c/salary/salary, 1* SELECT name, jobcode, salary, SQL> / NAME JO SALARY PROPOSED_NEW_SALARY Linda Costa CI John Davidson IN Susan Ash AP Stephen York CM Richard Jones CI Joanne Brown IN Donald Brown CI Paula Adams IN When I keyed this in, I forgot the comma after salary on the first line. This is the error that I got. To correct it, I first entered 1 to bring up line 1. Then I did a c of salary to salary, using c/salary/salary, Looking at the results I still have a problem. This time it is a logic problem. The default salary is multiplied by.025 instead of

Fixing logic problem SQL> 5 5* salary *.025) SQL> c/.025/1.025 SQL> / NAME JO SALARY PROPOSED_NEW_SALARY Linda Costa CI John Davidson IN Susan Ash AP Stephen York CM Richard Jones CI Joanne Brown IN Donald Brown CI Paula Adams IN rows selected. SQL> ; 1 SELECT name, jobcode, salary, 2 DECODE(salary, 45000, salary * 1.03, , salary * 1.035, , salary * 1.05, 5 salary * 1.025) 6 proposed_new_salary 7* FROM first_pay To fix the logic problem, I brought up line 5 where the error occurred and made the change. / executes the code ; shows the code

Editor SQL> edit Keying edit at the SQL prompt brings up notepad as a text editor. I made both of the changes in the editor. The comma was added and the.025 was changed to I then save and close the editor. The code in Oracle is shown below. Wrote file afiedt.buf 1 SELECT name, jobcode, salary, 2 DECODE(salary, 45000, salary * 1.03, , salary * 1.035, , salary * 1.05, 5 salary * 1.025) 6 proposed_new_salary 7* FROM first_pay

Nesting functions SQL> SELECT * FROM first_pay; PAY_ NAME JO STARTDATE SALARY BONUS Linda Costa CI 15-JAN John Davidson IN 25-SEP Susan Ash AP 05-FEB Stephen York CM 03-JUL Richard Jones CI 30-OCT Joanne Brown IN 18-AUG Donald Brown CI 05-NOV Paula Adams IN 12-DEC SQL> SELECT LOWER(SUBSTR(startdate,4,3)) || LOWER(jobcode) 2 FROM first_pay; LOWER janci sepin febap julcm octci augin novci decin First I will find the substr of the date field starting with character 4 and going for 3 characters. This finds the month. Then I convert it to lower case. The next function converts jobcode to lower case. These are concatenated together

Nested functions SQL> SELECT SUBSTR(stadr,(INSTR(stadr, ' '))) || ', ' || city 2 FROM donor; SUBSTR(STADR,(INSTR(STADR,' Elm St, Seekonk Benefit St, Providence Main St, Fall River Oak St, Fall River Pine St, Fall River SUBSTR is operating on stadr. It needs a start point which is determined by using the INSTR operating on stadr to find the first space in stadr. This location gives SUBSTR its start point. I provide no end point so it takes the rest of the characters in substr. I then concatenate with a comma followed by a space and concatenate that with city. On the first example, the address is 123 Elm St. INSTR will find the space in position 4. Therefore, SUBSTR will start with the fourth character in stadr and go to the end.