Lecture 2 21/1/16. Putting the output in order Oracle can sort a column, or multiple columns select emp_no, emp_name from employee order by emp_name;

Embed Size (px)

DESCRIPTION

Where Select emp_name, sal, dept_no from employee Where job= 'ANALYST'; emp_name sal dept_no HEARNE8004 Select * from customer where name='CIARA'; NAME ADDRESS PHONE CIARA CORK

Citation preview

Lecture 2 21/1/16 Putting the output in order Oracle can sort a column, or multiple columns select emp_no, emp_name from employee order by emp_name; emp_no emp_name 4BYRNE 8HARTE 3HEARNE 6WALSH select * from customer order by name; Name phone address CHARLES KERRY CIARA CORK MARY CORK Where Select emp_name, sal, dept_no from employee Where job= 'ANALYST'; emp_name sal dept_no HEARNE8004 Select * from customer where name='CIARA'; NAME ADDRESS PHONE CIARA CORK More Select emp_name, sal from employee where job='CLERK'; emp_name sal BYRNE100 4 Operator Precedence select emp_name, sal, 12*(sal+100) from employee; 5 Null Values NULL values represent unavailable, unassigned, unknown or inapplicable data A NULL is not the same as a zero or a blank space. 6 Null Values Name Null Type EMP_NO NOT NULL NUMBER(4) EMP_NAME VARCHAR2(20) JOB VARCHAR2(20) DEPT_NO NUMBER(2) SAL VARCHAR2(20) COMM VARCHAR2(20) 7 Note VARCHAR2 is a data type used to store variable-length character data. A varchar2 value can contain up to 4000 bytes of data (limit in Oracle 7 was 2000 bytes). The NUMBER datatype stores fixed and floating-point numbers. Numbers of virtually any magnitude can be stored and are guaranteed portable among different systems operating Oracle Database, up to 38 digits of precision.atype.htm#CNCPT313 Null Values 3HEARNEANALYST BYRNECLERK3100 6WALSHMANAGER4350 8HARTEACCOUNTANT DOHERTYCLERK MARTINMANAGER Null Values select COMM from employee where emp_name='DOHERTY'; 10 COMM commission awarded to employees Concatenation Operator Concatenation means to join, or link together In Oracle we use two bars|| This joins two, or more, columns together select EMP_NAME || ' IS A '|| JOB from EMPLOYEE; 11 12 select NAME || ' CONTACT DETAILS '|| PHONE from CUSTOMER; 13 Literal Character Strings Character, number or date that is included in a SELECT Date and character literals must be enclosed by single quotes Each string is output once for each row Example select EMP_NAME || ' IS A '|| JOB from EMPLOYEE; 14 Note A string is a sequence of bytes or characters, enclosed within either single quote (') or double quote (") characters. Examples: 'a string' "another string https://docs.oracle.com/cd/E17952_01/refman-5.5-en/string- literals.html Comparison Operators OperatorMeaning = (Equals)Equal to > (Greater Than)Greater than < (Less Than)Less than >= (Greater Than or Equal To)Greater than or equal to (Not Greater Than)Not greater than (not ISO standard) 16 Comparison Operators select * from customer where name ='CIARA'; select emp_name, sal from employee where sal >300 order by emp_name; select emp_name, sal from employee where sal =4 order by emp_name; 17 What if? select * from customer where name ='ciara'; Comparison Operators select * from employee where dept_no