Oracle SQL. January 9, DaiMuHong

Size: px
Start display at page:

Download "Oracle SQL. January 9, DaiMuHong"

Transcription

1 Oracle SQL January 9, 2007 DaiMuHong 1

2 2. Basic Concepts and Commands Basic Concepts: Oracle Data Types 1. Number Number Any number Number(4) Integer, Max length 4, to 9999 Number(5,2) Decimal, such as Character Char(2) Length Fixed, such as PA, DC varchar2(30) Length Variable, such as Address 3. Date Date Regular Date, Minimum is 1 second Timestamp For time precision < 1 second 4. Long For any data with size > 4000 byte Such as photo, video clip 2

3 2. Basic Concepts and Commands Oracle database, SQL and SQL Plus SQL: Structured Query Language A 4 th Generation Language Used to access Database PL/SQL: SQL + Logic Control SQL Plus: An Oracle Database interface to execute SQL commands and PL/SQL programs 3

4 2. Basic Concepts and Commands Log on to SQL Plus Go to your Oracle Home directory, then bin/sqlplus.exe Logon to SQL Plus: User name: system, scott Password: tiger (default) To change password: Log on to SQL Plus, type command: SQL> password To Unlock Account: SQL> Alter user scott account unlock; For our example, password: tiger Leave Host String Empty To give SCOTT more power: Log on as SYSTEM SQL> grant DBA to scott; 4

5 2. Basic Concepts and Commands Running SQL commands in SQL Plus commands, Buffer, and Command file SQL> Select empno, ename, sal From Emp; 1. Not case sensitive 2. End with ; or / must be at the beginning of a new line 3. Can be written in more than 1 line 4. File can be saved to a file, called sql plus script 5. A file can contain multiple SQL SQL Plus command 5

6 2. Basic Concepts and Commands Basic SQL Command: Create table Drop table Alter table Select Insert Update Delete Commit: Save the modification made by Delete, insert or update Rollback: discard the modification 6

7 2. Basic Concepts and Commands Basic SQL Plus Commands: DESC, or DESCRIBE -- Used to find the table structure set pagesize 100 set linesize 80 set heading on/off -- Used to setup SQL Plus interface environment ed, or edit -- Used to edit a file spool /off -- Used to record all the text which shown in SQL Plus screen 7

8 3. SQL Syntax Create, Drop, Modify table Create table Customer ( id number, name varchar2(20), address varchar2(50), phone varchar2(20), birth_date date ); Alter table Customer add ( varchar2(30) ); Alter table account drop column ; Drop table Customer; 8

9 3. SQL Syntax Insert data into table Create table test1 ( id number, name varchar2(20), salary number); Insert into test1 values ( 5, Ming, 5000); -- values will mapping to the table columns accordingly Insert into test1 ( id, name, salary) values ( 8, Zhang, 8000); -- values will mapping to the columns specified above Insert into test1 (salary, id) values ( 7000, 6); -- Column NAME is not specified, will get a NULL value commit; rollback; Select * from test1; 9

10 3. SQL Syntax Delete data from table Select * from test1; Delete Test1 Where ID = 5; commit; Delete Test1; rollback; 10

11 3. SQL Syntax UPDATE data from table Select * from test1; Update Test1 set salary = 5588 where ID = 5; commit; Update Test1 set salary = 5588; rollback; 11

12 3. SQL Syntax Select data from table Select * from Emp; Select Empno, Ename, Job, Sal From Emp Where Sal > 2000 Order by Ename; 12

13 3. SQL Syntax Select data from table: Select Clause -- Display all column from data source Select * from Emp; Select Empno, ename, mgr, job, sal, comm from Emp; -- Display 1 column from data source Select Ename From Emp; -- Display 4 columns, column name separated by, Select Empno, Ename, Job, Sal From Emp; -- Display data from different tables. -- Put table name before column name to avoid confusion Select Emp. Ename, Dept.Loc From Emp, Dept where Emp.deptno = Dept.deptno; 13

14 3. SQL Syntax Select data from table: FROM Clause Select * From Emp; -- Separate table name with comma Select Emp. Ename, Dept.Loc From Emp, Dept where Emp.deptno = Dept.deptno; -- Separate table name with comma. Using table alias Select E.Ename, D.Loc From Emp E, Dept D where E.deptno = D.deptno; 14

15 3. SQL Syntax Select data from table: WHERE Clause Select * From Emp Where condition; ID = 5 ID >=5 ID < 10 Name = Zhang Name > Zhang Name <= Zhang ID in ( 5, 8, 10) ID NOT in ( 5, 8, 10) Name like Zh% -- % any number of character Name like _h% -- _ a single character Name between A and C ID between 5 and 10 Name in ( Zhang, Wang, Li ) ID NOT between 5 and 10 Birth_date > 01-JAN-2001 Between date1 and date2 15

16 3. SQL Syntax Select data from table: ORDER BY Clause -- You can sort the selected data by order of ANY column(s) in the source table(s). -- Columns are separated by comma (,) -- SORT can be ASC (Ascending) or DESC (descending) Default is ASC -- If sorted column is in the select clause, you can use 1 or 2.. To represent them Select Empno, Ename, Sal From Emp Where condition1 Order by 1,3, hire_date; Select Empno, Ename, Sal From Emp Where condition1 Order by sal desc; Select.. From Table_a, Table_b Where join_condition Order By table_a.column asc, table_b.column desc; 16

17 4. Pre-Defined Function Distinct Number Function Character Function Data Function Conversion Function Misc. Function 17

18 4. Pre-Defined Function Distinct, or Unique Select deptno from Dept; Select Distinct Deptno From Dept; 18

19 4. Pre-Defined Function Number Function Single Row Function + - x / abs power sign Round Trunc Mod greatest least Group Function Max Min Avg Sum count Using DUAL Table: Select Round(123.46, -1) From Dual; 19

20 4. Pre-Defined Function Character Function upper, Lower concat ltrim rtrim trim lpad rpad length substr instr replace 20

21 4. Pre-Defined Function Date Function to_char to_date round trunc add_month Sysdate Date Format: YYYY YY RRRR RR Month MM DD D DAY HH24 MI SS 21

22 4. Pre-Defined Function Conversion Function to_char to_date to_number 22

23 4. Pre-Defined Function Other Functions NVL Replace Decode Case 23

24 5. Advanced query Sub-query, Query with Group function Set operation Group and Set Examples Pseudo column Query using decode and case Using PL/SQL for complex query 24

25 5. Advanced query Sub-query, Query with Group function Select * From Emp; Select max(sal) from emp; Select ename, max(sal) from emp group by ename; Select ename, sal From emp Where sal = (select max(sal) from emp); Select a.ename, b.loc From emp a, dept b Where a.deptno = b.deptno; Select a.ename, (select loc from dept where deptno= a.deptno) Loc From emp a; 25

26 5. Advanced query Sub-query, Query with Group function Select ename, sal From emp Where sal = (select max(sal) from emp); 2 nd highest salary Select max( sal ) From emp Where sal! = (select max(sal) from emp); Select ename, sal From emp Where sal = ( Select max( sal ) From emp Where sal! = (select max(sal) from emp) ); 26

27 5. Advanced query Group Query Select sum(sal) From emp Where deptno = 10; Select deptno, sum(sal) from emp -- Group by deptno Order by deptno; Select deptno, sum(sal) from emp Where Group by deptno having sum(sal) > 1000 Order by deptno; 27

28 5. Advanced query Set operation Union All, Union, Minus, Intersect A = ( 1, 2, 5 ) B = ( 1, 4 ) A Union All B = ( 1, 2, 5, 1, 4 ) A Union B = ( 1, 2, 4, 5 ) A Minus B = ( 2, 5 ) B Minus A = ( 4 ) A Intersect B = ( 1 ) When do set operation with 2 tables: 1. The number of columns should be the same 2. Column data type must be the same. May need to use to_char function. Example: Find the change ( table_a and its backup) 28

29 5. Advanced query Some Examples -- Top n Select * From ( select * from emp order by sal) a where rownum <= 5; 29

30 5. Advanced query Pseudo column (1): Rownum Select * from emp where rownum < 3; Select * from emp where rownum < 3 order by 1; Select * from emp where rownum = 3; Select * from emp where rownum <= 3 Minus Select * from emp where rownum <= 2; Select b.* from ( Select rownum xx, a.* from emp a ) b where b.xx =5; 30

31 5. Advanced query Pseudo column (2): Rowid Every record in every table has its own address - ROWID Select ename, sal from dept; Select rowid, ename, sal from emp; 31

32 5. Advanced query Pseudo column (2): Rowid Example: Duplicate records 1. How you know there is a duplicate count(id) diff from count(distinct id) 2. How to identify which one have duplicate having count(id) > 1 3. Delete duplicate records from table. Insert into dept Select * from dept ; Select Distinct * from dept; Delete Dept a Where rowid!= ( select max(rowid) from dept where deptno = a.deptno); 32

33 5. Advanced query Query using decode Create table exam_score ( Name varchar2(30), Grade number -- 1 to 5 ); Insert into exam_score values ('Zhang', 5); Insert into exam_score values ('Li', 4); Insert into exam_score values ('wang', 2); COMMIT; Select name, grade, decode(grade, 5, 'Excellent', 4, 'Very Good', 3, 'Good', 2, 'Work harder', 1, 'Go home') Suggestion From Exam_Score; 33

34 5. Advanced query Query using case Delete Exam_Score; Commit; Insert into Exam_Score values ('Zhang', 95); Insert into Exam_Score values ('Li', 88); Insert into Exam_Score values ('Wang', 55); Select name, grade, case when grade >= 90 then 'Excellent' when grade between 80 and 89 then 'Very Good' when grade between 70 and 79 then 'Good' when grade < 70 End comments From Exam_Score then 'be careful' 34

35 6. Join Where the Join comes from Database design Relation between tables ERD Types of Join Equijoin Non-equijoin Inner join Outer join Self join 35

36 6. Join: Type Cartesian Products (No join condition) Select a.ename, b.loc From Emp a, Dept b; Equijoin ( using equal to join) Select a.ename, b.loc From Emp a, Dept b Where a.deptno = b.deptno and a.sal between 1000 and 4000; Non-equijoin ( Using non-equal to join) Select a.ename, b.loc From Emp a, Dept b Where a.deptno = b.deptno and a.f1 > b.f2; Insert into DEPT ( 88, 'East', HuNan'); Commit; Inner join Return a row only join value is not null Select b.loc, a.ename From emp a, dept b Where b.deptno = a.deptno; Outer join Return a row even the value is null Select b.loc, a.ename From emp a, dept b Where b.deptno(+) = a.deptno; Self Join Select a.ename, b.ename manager From Emp a, emp b Where a.mgr = b.empno; 36

37 7. Create table, Insert, Delete, Update Create table with constraints Create from query Insert Truncate and Delete Update 37

38 7. Create table, Insert, Delete, Update Create table with constraints Constraints: Not Null, Null, Primary Key Forein Key Check Create Table Account ( Account_No number primary key, Cust_name varchar2(30) Not null, Phone varchar2(20), Sex varchar2(1) check ( sex in ('F', 'M') ) ); Create table from query Useful to create backup, and temp table Create table Emp2 as select * from emp; Create table Emp2 as select * from emp where 1=2; Create table Emp_Loc as Select a.ename, b.loc From emp a, dept b where a.deptno = b.deptno; Drop Table Account; Alter table account add varchar2(20); Alter table account drop column ; Select constraint_name, constraint_type from user_constraints where table_name = 'ACCOUNT'; Select constraint_name, column_name from user_cons_columns where table_name = 'ACCOUNT'; 38

39 7. Create table, Insert, Delete, Update Insert Create table Emp_Loc ( employee_name varchar2(20), Work_Location varchar2(20) ); Insert into Emp_Loc Select a.ename, b.loc From emp a, dept b where a.deptno = b.deptno; 39

40 7. Create table, Insert, Delete, Update Truncate and Delete 1. Delete is the opposite of insert 2. How insert, delete, and truncate work Create table emp2 as select * from emp; Delete emp2 where deptno = 10; Delete emp2; Rollback; Truncate table emp2; -- No chance to rollback 40

41 7. Create table, Insert, Delete, Update Update Create table Loc_Change ( dept_no number, new_loc varchar2(20) ); Insert into Loc_Change values ( 10, 'Wuhan'); Insert into Loc_Change values ( 20, 'Jinan'); Insert into Loc_Change values ( 30, 'Beijing'); Insert into Loc_Change values ( 40, 'Hunan'); Commit; Create table Dept2 as Select * from Dept; Select * from dept2; Update Dept2 Set Loc = 'ChangSha' Where Deptno = 40; Update Dept2 D Set D.Loc = ( select L.new_loc from Loc_Change L where L.dept_no = D.deptno ) where D.deptno in (select dept_no from loc_change) 41

42 8. Create view, sequence and synonym Create View Syntax Create or replace view Emp_v1 As Select a.ename, a.job, b.loc From emp a, Dept b where a.deptno = b.deptno; Create or replace view Emp_v2 As Select a.ename, a.sal, a.hiredate From emp a; Select * from emp_v1 where ename = 'Mike'; Select * from emp_v2 where ename = 'Mike'; Why View 1. For the data safety View itself is a SELECT statement with all the necessary join conditions. By using view, user can still do the query, but not directly access the source table. 2. For the convenience of user The Complex selection or business rules are hided under the view, Sequence Create sequence Order_Seq start with increment by 1; Insert into Order (order_no, amount) Values ( order_seq.nextval, 500); 42

43 8. Create view, sequence and synonym Synonym User Demo owns table Test_Table, but other users want to access it. Create user demo, logon as demo, create a table, and insert some data -- Log on as scott -- To access other's table, need to put owner's name before table name Select * from demo.test_table; -- Logon as Demo Grant select on test_table to scott; -- Log on as scott select * from demo.test_table; Create synonym test_table for demo.test_table; select * from demo.test_table; 43

44 9. Performance issue How to improve performance How index works Index rearranged the data in order, along with the rowid Use or not use the index Select * From Emp Where ename = 'MIKE'; Create index, composite index Create index emp_ind1 on Emp ( ename ); Create index emp_ind2 on Emp ( ename, Sal ); Select Ename, Sal From Emp Where ename = 'MIKe'; Select Ename, Sal From Emp Where UPPER(ename) = 'MIKE'; 44

45 10. Security and safety Security Account management Create user Demo identified by 1234; Grant connect, resource to demo; Alter user account lock/unlock; Grant/Revoke privilege Create user Demo identified by 1234; Grant connect, resource to demo; Grant select on emp to demo; Grant ALL on Dept to demo; Using view Create a view for a specific table, then grant the select privilege of the view, instead the table, to some users. So by controlling the columns in the view, we control what user can see. Using PL/SQL trigger Write a PL/SQL trigger, when user insert, or update, or delete, raise an error, or tracking what user doing. 45

46 10. Security and safety Safety Work on temp tables or backup the source data. Loosing data by accident, such as unwanted delete or update, or drop table,may cause lots of trouble for you, big lose for the company. You may put your job at risk. To prevent this kind of accident, you may work on temp table ( copy from real table); Or work on the real table, but back up the table first. To grantee the database safety, usually we have 3 Databases: 1. DVLP Database: For developing new program 2. TEST Database: For testing program, including performance 3. PROD Database: For Real Business only. 46

47 12. Data Dictionary 3 Prefixes: USER_, ALL_, DBA_ For example, USER_TABLES store info for tables which the log on user is the OWNER ALL_TABLES store info for tables of ALL users DBA_TABLES store info for tables of ALL users AND database internal tables DICT, User_objects User_tables, User_tab_columns User_Index, User_ind_columns User_Views User_Sequence 47

48 12. Data Dictionary DICT, or Dictionary All the data dictionary names DESC DICT Select table_name from Dict; User_objects A good habit to query an unknown table is do DESC and select count(*) first Select owner, object_type, object_name, created, last_ddl_time From ALL_Objects where object_name = 'EMP'; 48

49 12. Data Dictionary User_tables, User_tab_columns Select table_name, column_id, column_name, data_type From User_tab_columns Where table_name = 'DEPT' order by column_id; DESC does the same thing User_Index, User_ind_columns Select index_name, column_position, column_name From User_ind_columns where table_name = 'EMP' Knowing which column is indexed and its index position is very important to understand the performance of a query. 49

50 12. Data Dictionary User_Views DESC User_view -- Don't forget following command -- when query data with -- LONG data type Set Long Select text from All_view where view_name = 'EMP_V'; User_Sequence Create Sequence ss1 Start with increment by 1 select sequence_name, min_value, max_value, increment_by from User_sequences 50

51 13. SQL Plus command and Script Using SQL Plus script to generate SQL script Select Ename from Emp; Select Ename ' is my friend.' from Emp; Select ' Select count(*) from ' table_name ';' From User_tables; Spool new_script.txt Select ' Select count(*) from ' table_name ';' From User_tables; Spool off Spool new_script.txt Select ' Select ' ' '' ' table_name ' '' ' ',' count(*) from ' table_name ';' From User_tables; Spool off 51

52 Oracle PL/SQL January 9, 2007 Dai Mu-Hong Copyright

53 1. Introduction SQL vs. PL/SQL SQL: A command or statement to 1. Query ( select ) 2. DML. Manipulate ( insert, update, delete ) 3. DDL. Create database objects ( table, view, index,..) PL/SQL: Procedural programming extention of SQL Developed and used by Oracle only PL/SQL = SQL + Loop, Condition, Error handling 53

54 1. Introduction SQL vs. PL/SQL 3 Basic Types of PL/SQL program: Procedure: Return none or multiple values Function: Return one value Trigger: An event driven program Package is a group of procedures and functions organized together for easier management and higher performance 54

55 2. Components of PL/SQL program 1. Declare - Use this part to declare all the variables with their datatype and default values used in the program. If no variables used in the program, this section can be omitted. 2. Begin - Start of the execution part 3. Exception - In case of run time errors occured, program enter this section automatically. You can write codes here to handle the errors. This section may be omitted. In this case, the program will stop to run and error out when there is a run time error. 4. End - End of Program - Do not forget to put a dash / at the begining of next line, as the final end of the program. 55

56 Why need a - / - at the end of the program? Declare Begin For Loop Declare Begin Exception End; End Loop; Exception End; / 56

57 2. Components of PL/SQL program A Sample Program CITY table has 2 coumns, ID and Name. For ID (5) and name (changsha), the program: 1. Query the table with ID 5 2. If ID already exists, do Update Else, do a insert DECLARE v_cnt number; v_id number; v_name varchar2(10); BEGIN v_id := 5; v_status := 'changsha'; IF v_cnt > 0 Then ELSE UPDATE CITY SET name = v_name WHERE id = v_id; INSERT INTO CITY ( id, name ) values (v_id, v_name); END IF; COMMIT; Exception when others then null; END; / SELECT count(*) INTO v_cnt FROM CITY WHERE ID = v_id; test21.sql 57

58 2. Components of PL/SQL program Varable datatype in Declare Section 1. Number Number(4) Number(5,2) Integer Binary_integer v_id number; char(5) varchar2(20) v_name varchar2(30); Date v_entry_date Date; Boolean v_pass Boolean; 2. %type v_emp_name EMP.ename%type; %rowtype v_emp_rec EMP%rowtype; 3. Cursor Cursor c_emp is select * from emp; 4. Exception E_1 Exception; 5. Self defined type Record or array 58

59 2. Components of PL/SQL program Assignment V_ID := 5; V_Name := 'Chang Sha'; V_Phone := ' '; V_Phone_area_code := substr ( v_phone, 1, 4); V_Start_Date := Sysdate; V_Start_date := to_date('1/2/2007','mm/dd/yyyy'); V_Full_Name := v_last_name v_first_name; V_Pass := TRUE; 1. Select count(*) Into v_cnt From emp Where deptno = v_deptno; 2. Select * Into R_Emp From emp where deptno = v_deptno; v_empno := R_Emp.empno; For direct asignment, using := For asignment with Select, using INTO For comparism, equal =, Not Eaqual!= or <> 59

60 2. Components of PL/SQL program Logic Control IF IF x=5 Then Insert.. Elsif... Else Update. End If; WHILE X := 1; While x < 5 Loop Do something; X := X + 1; End Loop; GOTO IF x=5 Then GOTO some_where; End If;... <<some_where>> At least one line here... CASE A. Case X when 5 then y := 50; B. when 8 then y := 1000; else y := 0; End case; Case when x=5 then y := 50; when x>5 then y := 1000; Else y := 0; End case; 60

61 2. Components of PL/SQL program LOOP 1. LOOP... Exit when... End Loop; 3. While x < 5 LOOP... x := x + 1; End Loop; 2. For k in 1..5 LOOP... End Loop; c_emp is a cursor For v_emp in c_emp Loop Insert Into... values ( v_emp.sal,...); End Loop; 61

62 2. Components of PL/SQL program Exception Declare v_ename emp.ename%type; v_sal number; -- e1 exception; -- e2 exception; Begin select ename into v_ename from emp where enmno = '123456'; select sal into v_sal from emp where deptno = 10; 1. Without exception part 2. With exception part use when others syntax in exception handling. 3. Handle exception for each select statement 4. Raise exception in the select, then pass the exception to the main Exception part --Exception End; / 62

63 Exception When no_data_found then V_msg := 'no company for id ' TO_CHAR (v_id); V_err := SQLCODE; V_prog := 'fixdebt'; INSERT INTO errlog VALUES (V_err,v_msg,v_prog,SYSDATE,user); When others then V_err := SQLCODE; V_msg := SQLERRM; V_prog := 'fixdebt'; INSERT INTO errlog VALUES (V_err,v_msg,v_prog,SYSDATE,user); Raise; 63

64 3. Procedure and Function Anonymous Procedure 1. Declare... Begin... Exception... End; / Save above codes as Test.sql This file is saved in the client hard drive, not in the Database. Runing this file is running the code inside the file. Stored Procedure 2. Create or replace procedure T1 as... Begin... Exception... End; / Save above codes as Test.sql, in the hard drive. Runing this file only compile and create a procedure named T1 in the database, NOT running the code inside the file. To run the codes, we need to execute the procedure T1. SQL> Exec T1 64

65 3. Procedure and Function Pass Parameters Anonymous Procedure 1. Declare Begin x number; x := &1;... Exception... End; / Save above codes as Test.sql Stored Procedure 2. Create or replace procedure T1 ( p1 in number, p2 in varchar2 ) as... Begin... Exception... End; / Save above codes as Test.sql SQL> Exec T1(5, 'Mike') 65

66 3. Procedure and Function Run/Call Stored procedure Procedure T1: Create or replace procedure T1 ( p1 in number, p2 in number, p3 out number ) as Begin End; / p3 := p1 + p2; Save above codes as P_Test1.sql to create T1 SQL> Exec T1(5, 'Mike') Procedure T2: Create or replace procedure T2 (x number, y number) as Z number; Begin T1(X, Y, Z); dbms_output.put_line ('The sum of ' x ' and ' Y ' is ' Z); End; / Save above codes as P_Test2.sql to create T2 SQL> Exec T2(5, 8) 66

67 3. Procedure and Function Run/Call Stored function Procedure T1: Create or replace function T1 ( p1 in number, p2 in number -- p3 out number ) Return number as Begin End; / return( p1 + p2); Save above codes as P_Test1.sql to create T1 SQL> select T1(3,5) from dual; Procedure T2: Create or replace procedure T2 (x number, y number) as Z number; Begin Z := T1(x,y); dbms_output.put_line ('The sum of ' x ' and ' Y ' is ' Z); End; / Save above codes as P_Test2.sql to create T2 SQL> Exec T2(5, 8) 67

68 3. Procedure and Function Run/Call Stored Function Function F1: Create or replace function F1 (p1 in varchar2) Return varchar2 as v_in varchar2(30) := p1; v_out varchar2(30); Begin while length(v_in) > 0 Loop v_out := v_out substr(v_in, length(v_in),1); v_in := substr(v_in, 1, length(v_in)-1); End Loop; Return v_out; End; / Save as F_Test1.sql, to create function F1 After Function F1 created, we may use it in SQL or programs. Run/Call Function F1 A. In SQL statement SQL> select f1('abcd') from dual; SQL> select dname, substr(f1(dname),1,20) from dept; B. Call from procedure or function Set serveroutput on Declare Z varchar2(20); Begin Z:= F1('HuNan University'); dbms_output.put_line( Z); End; / Save above codes as Test3.sql 68

69 3. Procedure and Function Using Cursor Procedure T5: Set serveroutput on size Declare Cursor c1 is select * from Emp; Begin For v1 in c1 loop End; / dbms_output.put_line (v1.ename ' makes a salary of ' v1.sal); Save above codes as P_Test3.sql 69

70 3. Procedure and Function Exception Declare Begin v_ename emp.ename%type; v_sal number; -- e1 exception; -- e2 exception; select ename into v_ename from emp where enmno = '123456'; 1. Without exception part 2. With exception part use when others syntax in exception handling. 3. Handle exception for each select statement 4. Raise exception in the select, then pass the exception to the main Exception part select sal into v_sal from emp where deptno = 10; --Exception End; / 70

71 3. Procedure and Function Exception Procedure T6: handle exception while continue to process Declare Begin For Loop Declare Begin Exception End; End Loop; Exception End; / 71

72 3. Procedure and Function Examples: 1a. Single For Loop Create or Replace procedure P1 (p_in number) as v_line varchar2(20):= '*'; Begin For i in 1..p_in Loop End; / v_line := Rpad(v_line, i, '*'); DBMS_Output.put_line(v_line); End Loop; SQL> Set Serveroutput on SQL> Exec p1(6) 72

73 3. Procedure and Function Examples: 1b. Double For Loop Create or Replace procedure P99 as v_line varchar2(150); z varchar2(20); Begin For i in 1..9 Loop v_line := NULL; For j in 1..9 Loop End; / z := i '*' j '=' i*j; z := rpad(z, 7); v_line := v_line ' ' z; End Loop; -- j loop DBMS_output.put_line(v_line); End Loop; -- i loop SQL> Set Serveroutput on SQL> Exec p99 73

74 3. Procedure and Function Examples: 2. Prime Number Create or Replace function Is_Prime (p_in number) Return Boolean as v_prime boolean := true; Begin If P_in in (1,2,3) Then v_prime := true; goto print_section; End if; For i in 2.. round(p_in/2) Loop if mod(p_in, i) = 0 Then v_prime := false; exit; end if; End Loop; <<print_section>> return v_prime; End; / Create or Replace procedure G_Guess (p_in number) as j number; v_result varchar2(100) := null; Begin If is_prime(p_in) then v_result := P_in ' itself is a prime'; goto print_result; End If; For i in 1..p_in/2 Loop j := p_in - i; if is_prime(i) and is_prime(j) Then v_result :=p_in ' = ' i ' + ' j; Exit; End if; End Loop; <<print_result>> If v_result is not null Then dbms_output.put_line (v_result); else dbms_output.put_line ('G Guess fail.'); end if; End; / 74

75 3. Procedure and Function Tracing and Debugging Find/Correct Compiling Syntax errors SQL> show error Find/Correct Run time error Using a loc variable, then Display loc at exception section Using GOTO to bypass some parts of the program 75

76 4. Trigger A unique Implementation of PL/SQL Stored in DB, but not stored procedure or functions Event Driven Perform some kind of action in the database Purpose of Trigger Maintain complex integrity constraints Auditing Automatically signaling other programs when changes are made to a table 76

77 4. Trigger Types of Triggers A. System Trigger on system events, such as Logon and logoff on DDL, such as create database objects B. Database Trigger Fired by a DML statement, such as Insert, update, or delete 77

78 4. Trigger Example of System Trigger Create table Test9 ( User_name varchar2(20), Log_Time date ); Create or replace trigger T9 after logon on schema -- Before logoff on schema when (user = 'SCOTT') Begin Insert into Test9 values (user, sysdate); End; / 78

79 4. Trigger Example of Database Trigger (1) Create Table Test_10 (Greeting varchar2(30)); Create or Replace Trigger T_10 Before Insert on Test_10 For Each Row Declare Begin IF upper(:new.greeting) like '%BAD%' then :new.greeting := replace(upper(:new.greeting), 'BAD', 'GOOD'); :new.greeting := initcap(:new.greeting); End IF; End; / 79

80 4. Trigger Example of Database Trigger (1B) Create Table test_10 (Greeting varchar2(30)); Create Table Good_Bad (B_Word varchar2(20), G_Word varchar2(20)); Insert into Good_Bad values ('BAD', 'GOOD' ); Insert into Good_Bad values ('HATE', 'LOVE' ); Insert into Good_Bad values ('SAD', 'HAPPY'); COMMIT; Create or Replace Trigger T_10B Before Insert on Test_10 For Each Row Declare Cursor c1 is select * from Good_Bad; Begin For v1 in c1 Loop :new.greeting := replace(upper(:new.greeting), v1.b_word, v1.g_word); :new.greeting := initcap(:new.greeting); End Loop; End; / 80

81 4. Trigger Example of Database Trigger (2) Create Table test_10 (Greeting varchar2(30)); Create Table test_11 (username varchar2(10), insert_time date, comment varchar2(50)); Create or Replace Trigger T_11 After Insert on Test_10 For Each Row Begin Insert into Test_11 values (user, sysdate, 'Inserted value is: ' :new.greeting); End; / 81

82 4. Trigger Example of Database Trigger (3) Create Table Account ( Cust_name varchar2(20), account# varchar2(10), balance number, interest number ); Create Table Account_Audit ( account# varchar2(10), username varchar2(10), upd_time date, old_balance number, new_balance number, old_interest number, new_interest number ); Create or Replace Trigger T_12 After Update on Account For Each Row Begin Insert into Account_Audit values ( :old.account#, user, sysdate, :old.balance, :new.balance, :old.interest, :new.interest ); End; / 82

@vmahawar. Agenda Topics Quiz Useful Links

@vmahawar. Agenda Topics Quiz Useful Links @vmahawar Agenda Topics Quiz Useful Links Agenda Introduction Stakeholders, data classification, Rows/Columns DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE CONSTRAINTS, DATA TYPES DML Data

More information

Course Outline and Objectives: Database Programming with SQL

Course Outline and Objectives: Database Programming with SQL Introduction to Computer Science and Business Course Outline and Objectives: Database Programming with SQL This is the second portion of the Database Design and Programming with SQL course. In this portion,

More information

Introduction to Computer Science and Business

Introduction to Computer Science and Business Introduction to Computer Science and Business This is the second portion of the Database Design and Programming with SQL course. In this portion, students implement their database design by creating a

More information

Topics Fundamentals of PL/SQL, Integration with PROIV SuperLayer and use within Glovia

Topics Fundamentals of PL/SQL, Integration with PROIV SuperLayer and use within Glovia Topics Fundamentals of PL/SQL, Integration with PROIV SuperLayer and use within Glovia 1. Creating a Database Alias 2. Introduction to SQL Relational Database Concept Definition of Relational Database

More information

Table of Contents. PDF created with FinePrint pdffactory Pro trial version

Table of Contents. PDF created with FinePrint pdffactory Pro trial version Table of Contents Course Description The SQL Course covers relational database principles and Oracle concepts, writing basic SQL statements, restricting and sorting data, and using single-row functions.

More information

Oracle Syllabus Course code-r10605 SQL

Oracle Syllabus Course code-r10605 SQL Oracle Syllabus Course code-r10605 SQL Writing Basic SQL SELECT Statements Basic SELECT Statement Selecting All Columns Selecting Specific Columns Writing SQL Statements Column Heading Defaults Arithmetic

More information

ORACLE VIEWS ORACLE VIEWS. Techgoeasy.com

ORACLE VIEWS ORACLE VIEWS. Techgoeasy.com ORACLE VIEWS ORACLE VIEWS Techgoeasy.com 1 Oracle VIEWS WHAT IS ORACLE VIEWS? -A view is a representation of data from one or more tables or views. -A view is a named and validated SQL query which is stored

More information

Oracle Database 11g: SQL and PL/SQL Fundamentals

Oracle Database 11g: SQL and PL/SQL Fundamentals Oracle University Contact Us: +33 (0) 1 57 60 20 81 Oracle Database 11g: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn In this course, students learn the fundamentals of SQL and PL/SQL

More information

5. Single-row function

5. Single-row function 1. 2. Introduction Oracle 11g Oracle 11g Application Server Oracle database Relational and Object Relational Database Management system Oracle internet platform System Development Life cycle 3. Writing

More information

PL/SQL. Exception. When the PL/SQL engine cannot execute the PLSQL block it raise an error. Every Oracle error has an error number

PL/SQL. Exception. When the PL/SQL engine cannot execute the PLSQL block it raise an error. Every Oracle error has an error number PL/SQL Exception When the PL/SQL engine cannot execute the PLSQL block it raise an error. Every Oracle error has an error number Exceptions must be handled by name. PL/SQL predefines some common Oracle

More information

SQL is an English like language consisting of commands to store, retrieve, maintain & regulate access to your database.

SQL is an English like language consisting of commands to store, retrieve, maintain & regulate access to your database. SQL SQL is an English like language consisting of commands to store, retrieve, maintain & regulate access to your database. SQL*Plus SQL*Plus is an application that recognizes & executes SQL commands &

More information

Creating and Managing Tables Schedule: Timing Topic

Creating and Managing Tables Schedule: Timing Topic 9 Creating and Managing Tables Schedule: Timing Topic 30 minutes Lecture 20 minutes Practice 50 minutes Total Objectives After completing this lesson, you should be able to do the following: Describe the

More information

Oracle Database: SQL and PL/SQL Fundamentals Ed 2

Oracle Database: SQL and PL/SQL Fundamentals Ed 2 Oracle University Contact Us: Local: 1800 103 4775 Intl: +91 80 67863102 Oracle Database: SQL and PL/SQL Fundamentals Ed 2 Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals

More information

Overview of PL/SQL. About PL/SQL. PL/SQL Environment. Benefits of PL/SQL. Integration

Overview of PL/SQL. About PL/SQL. PL/SQL Environment. Benefits of PL/SQL. Integration About PL/ Overview of PL/ PL/ is an extension to with design features of programming languages. Data manipulation and query statements of are included within procedural units of code. PL/ Environment Benefits

More information

1 SQL Structured Query Language

1 SQL Structured Query Language 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

More information

Oracle Database 12c SQL Fundamentals

Oracle Database 12c SQL Fundamentals Course Overview This course takes a unique approach to SQL training in that it incorporates data modeling theory, relational database theory, graphical depictions of theoretical concepts and numerous examples

More information

Oracle Database: SQL and PL/SQL Fundamentals NEW

Oracle Database: SQL and PL/SQL Fundamentals NEW Oracle Database: SQL and PL/SQL Fundamentals NEW Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals training delivers the fundamentals of SQL and PL/SQL along with the

More information

Real-World Performance Training SQL Introduction

Real-World Performance Training SQL Introduction Real-World Performance Training SQL Introduction Real-World Performance Team Basics SQL Structured Query Language Declarative You express what you want to do, not how to do it Despite the name, provides

More information

1 SQL Structured Query Language

1 SQL Structured Query Language 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

More information

1 Writing Basic SQL SELECT Statements 2 Restricting and Sorting Data

1 Writing Basic SQL SELECT Statements 2 Restricting and Sorting Data 1 Writing Basic SQL SELECT Statements Objectives 1-2 Capabilities of SQL SELECT Statements 1-3 Basic SELECT Statement 1-4 Selecting All Columns 1-5 Selecting Specific Columns 1-6 Writing SQL Statements

More information

Chapter 14 Data Dictionary and Scripting

Chapter 14 Data Dictionary and Scripting Chapter 14 Data Dictionary and Scripting Tables in the Oracle Database User Tables Collection of tables to store data Data Dictionary Tables Collection of tables created and maintained by Oracle server

More information

SQL Structured Query Language Introduction

SQL Structured Query Language Introduction SQL Structured Query Language Introduction Rifat Shahriyar Dept of CSE, BUET Tables In relational database systems data are represented using tables (relations). A query issued against the database also

More information

normalization are being violated o Apply the rule of Third Normal Form to resolve a violation in the model

normalization are being violated o Apply the rule of Third Normal Form to resolve a violation in the model Database Design Section1 - Introduction 1-1 Introduction to the Oracle Academy o Give examples of jobs, salaries, and opportunities that are possible by participating in the Academy. o Explain how your

More information

What are temporary tables? When are they useful?

What are temporary tables? When are they useful? What are temporary tables? When are they useful? Temporary tables exists solely for a particular session, or whose data persists for the duration of the transaction. The temporary tables are generally

More information

AO3 - Version: 2. Oracle Database 11g SQL

AO3 - Version: 2. Oracle Database 11g SQL AO3 - Version: 2 Oracle Database 11g SQL Oracle Database 11g SQL AO3 - Version: 2 3 days Course Description: This course provides the essential SQL skills that allow developers to write queries against

More information

D a t a b a s e M a n a g e m e n t S y s t e m L a b Institute of Engineering and Management

D a t a b a s e M a n a g e m e n t S y s t e m L a b Institute of Engineering and Management Institute of Engineering and Management Department of Computer Science and Engineering Database Management Laboratory (CS 691) Lab Manual Syllabus: Database Management System Lab Code: CS691 Contact: 3P

More information

Oracle Database: Introduction to SQL/PLSQL Accelerated

Oracle Database: Introduction to SQL/PLSQL Accelerated Oracle University Contact Us: Landline: +91 80 67863899 Toll Free: 0008004401672 Oracle Database: Introduction to SQL/PLSQL Accelerated Duration: 5 Days What you will learn This Introduction to SQL/PLSQL

More information

Oracle Database: SQL and PL/SQL Fundamentals

Oracle Database: SQL and PL/SQL Fundamentals Oracle University Contact Us: 001-855-844-3881 & 001-800-514-06-9 7 Oracle Database: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals training

More information

Oracle Class VII More on Exception Sequence Triggers RowID & Rownum Views

Oracle Class VII More on Exception Sequence Triggers RowID & Rownum Views Oracle Class VII More on Exception Sequence Triggers RowID & Rownum Views Sequence An Oracle sequence is an Oracle database object that can be used to generate unique numbers. You can use sequences to

More information

Chapter-14 SQL COMMANDS

Chapter-14 SQL COMMANDS Chapter-14 SQL COMMANDS What is SQL? Structured Query Language and it helps to make practice on SQL commands which provides immediate results. SQL is Structured Query Language, which is a computer language

More information

SQL. Char (30) can store ram, ramji007 or 80- b

SQL. Char (30) can store ram, ramji007 or 80- b SQL In Relational database Model all the information is stored on Tables, these tables are divided into rows and columns. A collection on related tables are called DATABASE. A named table in a database

More information

Index. Boolean expression, , Business rules enforcement. see Declarative constraints table with Oracle constraints and,

Index. Boolean expression, , Business rules enforcement. see Declarative constraints table with Oracle constraints and, Index ABS numeric function, 355 Active State Perl, SQL*Plus with, 61 ADD_MONTHS, 360 AFTER DELETE ROW trigger, 202 AFTER DELETE STATEMENT trigger, 202 AFTER-INSERT-ROW (AIR) trigger, 172 174, 177, 179

More information

Introduction to SQL/PLSQL Accelerated Ed 2

Introduction to SQL/PLSQL Accelerated Ed 2 Oracle University Contact Us: Local: 1800 103 4775 Intl: +91 80 67863102 Introduction to SQL/PLSQL Accelerated Ed 2 Duration: 5 Days What you will learn This Introduction to SQL/PLSQL Accelerated course

More information

Table of Contents. Oracle SQL PL/SQL Training Courses

Table of Contents. Oracle SQL PL/SQL Training Courses Table of Contents Overview... 7 About DBA University, Inc.... 7 Eligibility... 8 Pricing... 8 Course Topics... 8 Relational database design... 8 1.1. Computer Database Concepts... 9 1.2. Relational Database

More information

Oracle Database SQL Basics

Oracle Database SQL Basics Oracle Database SQL Basics Kerepes Tamás, Webváltó Kft. tamas.kerepes@webvalto.hu 2015. február 26. Copyright 2004, Oracle. All rights reserved. SQL a history in brief The relational database stores data

More information

Database Foundations. 6-3 Data Definition Language (DDL) Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Database Foundations. 6-3 Data Definition Language (DDL) Copyright 2015, Oracle and/or its affiliates. All rights reserved. Database Foundations 6-3 Roadmap You are here Introduction to Oracle Application Express Structured Query Language (SQL) Data Definition Language (DDL) Data Manipulation Language (DML) Transaction Control

More information

Databases - 4. Other relational operations and DDL. How to write RA expressions for dummies

Databases - 4. Other relational operations and DDL. How to write RA expressions for dummies Databases - 4 Other relational operations and DDL How to write RA expressions for dummies Step 1: Identify the relations required and CP them together Step 2: Add required selections to make the CP Step

More information

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables INDEX Exercise No Title 1 Basic SQL Statements 2 Restricting and Sorting Data 3 Single Row Functions 4 Displaying data from multiple tables 5 Creating and Managing Tables 6 Including Constraints 7 Manipulating

More information

SQL Interview Questions

SQL Interview Questions SQL Interview Questions SQL stands for Structured Query Language. It is used as a programming language for querying Relational Database Management Systems. In this tutorial, we shall go through the basic

More information

5 Integrity Constraints and Triggers

5 Integrity Constraints and Triggers 5 Integrity Constraints and Triggers 5.1 Integrity Constraints In Section 1 we have discussed three types of integrity constraints: not null constraints, primary keys, and unique constraints. In this section

More information

Oracle Database 10g: Introduction to SQL

Oracle Database 10g: Introduction to SQL ORACLE UNIVERSITY CONTACT US: 00 9714 390 9000 Oracle Database 10g: Introduction to SQL Duration: 5 Days What you will learn This course offers students an introduction to Oracle Database 10g database

More information

Topics - System Administration for Glovia

Topics - System Administration for Glovia Topics - System Administration for Glovia 1. Network Architecture Sample Network 2. glovia.com Technology Architecture Application Server Database Server Web Server 3. Operating System Architecture High

More information

Writing PL/SQL Executable Statements. Copyright 2007, Oracle. All rights reserved.

Writing PL/SQL Executable Statements. Copyright 2007, Oracle. All rights reserved. What Will I Learn? In this lesson, you will learn to: Construct accurate variable assignment statements in PL/SQL Construct accurate statements using built-in SQL functions in PL/SQL Differentiate between

More information

ORACLE TRAINING. ORACLE Training Course syllabus ORACLE SQL ORACLE PLSQL. Oracle SQL Training Syllabus

ORACLE TRAINING. ORACLE Training Course syllabus ORACLE SQL ORACLE PLSQL. Oracle SQL Training Syllabus ORACLE TRAINING ORACLE Training Course syllabus ORACLE SQL ORACLE PLSQL Oracle SQL Training Syllabus Introduction to Oracle Database List the features of Oracle Database 11g Discuss the basic design, theoretical,

More information

GIFT Department of Computing Science Data Selection and Filtering using the SELECT Statement

GIFT Department of Computing Science Data Selection and Filtering using the SELECT Statement GIFT Department of Computing Science [Spring 2013] CS-217: Database Systems Lab-2 Manual Data Selection and Filtering using the SELECT Statement V1.0 4/12/2016 Introduction to Lab-2 This lab reinforces

More information

Oracle Database: Introduction to SQL

Oracle Database: Introduction to SQL Oracle University Contact Us: (+202) 35 35 02 54 Oracle Database: Introduction to SQL Duration: 5 Days What you will learn View a newer version of this course This Oracle Database: Introduction to SQL

More information

Oracle Introduction to PL/SQL

Oracle Introduction to PL/SQL Oracle Introduction to PL/SQL 1. For which column would you create an index? a. a column that is small b. a column that is updated frequently c. a column containing a wide range of values d. a column with

More information

SQL. - single row functions - Database Design ( 데이터베이스설계 ) JUNG, Ki-Hyun ( 정기현 )

SQL. - single row functions - Database Design ( 데이터베이스설계 ) JUNG, Ki-Hyun ( 정기현 ) SQL Database Design ( 데이터베이스설계 ) - single row functions - JUNG, Ki-Hyun ( 정기현 ) 1 SQL Functions Input Function Output Function performs action that defined already before execution 2 Two Types of SQL Functions

More information

Oracle Database: Introduction to SQL

Oracle Database: Introduction to SQL Oracle Database: Introduction to SQL What you will learn Understanding the basic concepts of relational databases ensure refined code by developers. This course helps the participants to write subqueries,

More information

Oracle Database: Introduction to SQL

Oracle Database: Introduction to SQL Oracle University Contact Us: +27 (0)11 319-4111 Oracle Database: Introduction to SQL Duration: 5 Days What you will learn This Oracle Database: Introduction to SQL training helps you write subqueries,

More information

CS6312 DATABASE MANAGEMENT SYSTEMS LABORATORY L T P C

CS6312 DATABASE MANAGEMENT SYSTEMS LABORATORY L T P C CS6312 DATABASE MANAGEMENT SYSTEMS LABORATORY L T P C 0 0 3 2 LIST OF EXPERIMENTS: 1. Creation of a database and writing SQL queries to retrieve information from the database. 2. Performing Insertion,

More information

Objectives. After completing this lesson, you should be able to do the following:

Objectives. After completing this lesson, you should be able to do the following: Objectives After completing this lesson, you should be able to do the following: Write SELECT statements to access data from more than one table using equality and nonequality joins View data that generally

More information

Indexes (continued) Customer table with record numbers. Source: Concepts of Database Management

Indexes (continued) Customer table with record numbers. Source: Concepts of Database Management 12 Advanced Topics Objectives Use indexes to improve database performance Examine the security features of a DBMS Discuss entity, referential, and legal-values integrity Make changes to the structure of

More information

Relational Database Language

Relational Database Language DATA BASE MANAGEMENT SYSTEMS Unit IV Relational Database Language: Data definition in SQL, Queries in SQL, Insert, Delete and Update Statements in SQL, Views in SQL, Specifying General Constraints as Assertions,

More information

Oracle Database: Introduction to SQL Ed 2

Oracle Database: Introduction to SQL Ed 2 Oracle University Contact Us: +40 21 3678820 Oracle Database: Introduction to SQL Ed 2 Duration: 5 Days What you will learn This Oracle Database 12c: Introduction to SQL training helps you write subqueries,

More information

1Z Oracle Database 11g - SQL Fundamentals I Exam Summary Syllabus Questions

1Z Oracle Database 11g - SQL Fundamentals I Exam Summary Syllabus Questions 1Z0-051 Oracle Database 11g - SQL Fundamentals I Exam Summary Syllabus Questions Table of Contents Introduction to 1Z0-051 Exam on Oracle Database 11g - SQL Fundamentals I 2 Oracle 1Z0-051 Certification

More information

Introduction to Computer Science and Business

Introduction to Computer Science and Business Introduction to Computer Science and Business The Database Programming with PL/SQL course introduces students to the procedural language used to extend SQL in a programatic manner. This course outline

More information

Database design process

Database design process Database technology Lecture 2: Relational databases and SQL Jose M. Peña jose.m.pena@liu.se Database design process 1 Relational model concepts... Attributes... EMPLOYEE FNAME M LNAME SSN BDATE ADDRESS

More information

Appendix A Practices and Solutions

Appendix A Practices and Solutions Appendix A Practices and Solutions Table of Contents Practices and Solutions for Lesson I... 3 Practice I-1: Accessing SQL Developer Resources... 4 Practice I-2: Using SQL Developer... 5 Practice Solutions

More information

Introduction p. 1 The Logical and Physical View of Tables p. 1 Database Types p. 4 NULLs p. 6 DDL and DML Statements p. 7 Column and Table Constraint

Introduction p. 1 The Logical and Physical View of Tables p. 1 Database Types p. 4 NULLs p. 6 DDL and DML Statements p. 7 Column and Table Constraint Preface p. xv Introduction p. 1 The Logical and Physical View of Tables p. 1 Database Types p. 4 NULLs p. 6 DDL and DML Statements p. 7 Column and Table Constraint Clauses p. 7 Sample Database p. 9 A Quick

More information

Practical Workbook Database Management Systems

Practical Workbook Database Management Systems Practical Workbook Database Management Systems Name : Year : Batch : Roll No : Department: Third Edition Reviewed in 2014 Department of Computer & Information Systems Engineering NED University of Engineering

More information

DB2 SQL Class Outline

DB2 SQL Class Outline DB2 SQL Class Outline The Basics of SQL Introduction Finding Your Current Schema Setting Your Default SCHEMA SELECT * (All Columns) in a Table SELECT Specific Columns in a Table Commas in the Front or

More information

Oracle Tables TECHGOEASY.COM

Oracle Tables TECHGOEASY.COM Oracle Tables TECHGOEASY.COM 1 Oracle Tables WHAT IS ORACLE DATABASE TABLE? -Tables are the basic unit of data storage in an Oracle Database. Data is stored in rows and columns. -A table holds all the

More information

SQL FUNCTIONS. Prepared By:Dr. Vipul Vekariya.

SQL FUNCTIONS. Prepared By:Dr. Vipul Vekariya. SQL FUNCTIONS Prepared By:Dr. Vipul Vekariya. SQL FUNCTIONS Definition of Function Types of SQL Function Numeric Function String Function Conversion Function Date Function SQL Function Sub program of SQL

More information

Oracle SQL & PL SQL Course

Oracle SQL & PL SQL Course Oracle SQL & PL SQL Course Complete Practical & Real-time Training Job Support Complete Practical Real-Time Scenarios Resume Preparation Lab Access Training Highlights Placement Support Support Certification

More information

UNIT III INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL)

UNIT III INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) UNIT III INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) 3.1Data types 3.2Database language. Data Definition Language: CREATE,ALTER,TRUNCATE, DROP 3.3 Database language. Data Manipulation Language: INSERT,SELECT,UPDATE,DELETE

More information

SYSTEM CODE COURSE NAME DESCRIPTION SEM

SYSTEM CODE COURSE NAME DESCRIPTION SEM Course: CS691- Database Management System Lab PROGRAMME: COMPUTER SCIENCE & ENGINEERING DEGREE:B. TECH COURSE: Database Management System Lab SEMESTER: VI CREDITS: 2 COURSECODE: CS691 COURSE TYPE: Practical

More information

Sql Server Syllabus. Overview

Sql Server Syllabus. Overview Sql Server Syllabus Overview This SQL Server training teaches developers all the Transact-SQL skills they need to create database objects like Tables, Views, Stored procedures & Functions and triggers

More information

Vendor: Oracle. Exam Code: 1Z Exam Name: Oracle Database: SQL Fundamentals I. Q&As: 292

Vendor: Oracle. Exam Code: 1Z Exam Name: Oracle Database: SQL Fundamentals I. Q&As: 292 Vendor: Oracle Exam Code: 1Z1-051 Exam Name: Oracle Database: SQL Fundamentals I Q&As: 292 QUESTION 1 Evaluate the SQL statement: TRUNCATE TABLE DEPT; Which three are true about the SQL statement? (Choose

More information

Miguel Anjo (IT/ADC)

Miguel Anjo (IT/ADC) Database Workshop for LHC online/offline developers SQL (2/2) (IT/ADC) Miguel.Anjo@cern.ch http://cern.ch/it-adc (based on Andrea Valassi slides on Advanced SQL) 26 January 2005 Previous tutorials: Database

More information

SQL+PL/SQL. Introduction to SQL

SQL+PL/SQL. Introduction to SQL SQL+PL/SQL CURRICULUM Introduction to SQL Introduction to Oracle Database List the features of Oracle Database 12c Discuss the basic design, theoretical, and physical aspects of a relational database Categorize

More information

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL)

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management Tenth Edition Chapter 7 Introduction to Structured Query Language (SQL) Objectives In this chapter, students will learn: The basic commands and

More information

Database implementation Further SQL

Database implementation Further SQL IRU SEMESTER 2 January 2010 Semester 1 Session 2 Database implementation Further SQL Objectives To be able to use more advanced SQL statements, including Renaming columns Order by clause Aggregate functions

More information

COURSE STUDENT LEARNING OUTCOMES: See attached or in course s learn.unm.edu

COURSE STUDENT LEARNING OUTCOMES: See attached or in course s learn.unm.edu Syllabus Online IT 222(CRN #43196) Data Base Management Systems Instructor: James Hart / hart56@unm.edu Office Room Number: B 123 Instructor's Campus Phone: 505.925.8720 / Mobile 505.239.3435 Office Hours:

More information

Oracle Class VI. Exception Block Cursors For Loops

Oracle Class VI. Exception Block Cursors For Loops Oracle Class VI Exception Block Cursors For Loops Pl/sql some more basics Loop through records, manipulating them one at a time. Keep code secure by offering encryption, and storing code permanently on

More information

UNIT-IV (Relational Database Language, PL/SQL)

UNIT-IV (Relational Database Language, PL/SQL) UNIT-IV (Relational Database Language, PL/SQL) Section-A (2 Marks) Important questions 1. Define (i) Primary Key (ii) Foreign Key (iii) unique key. (i)primary key:a primary key can consist of one or more

More information

Oracle Database 11g: SQL Fundamentals I

Oracle Database 11g: SQL Fundamentals I Oracle Database 11g: SQL Fundamentals I Volume I Student Guide D49996GC11 Edition 1.1 April 2009 D59980 Authors Puja Singh Brian Pottle Technical Contributors and Reviewers Claire Bennett Tom Best Purjanti

More information

Prepared by Manash Deb website: 1

Prepared by Manash Deb website:  1 S.Q.L. SQL means Structured Query Language. SQL is a database computer language designed for managing data in relational database management systems (RDBMS). RDBMS technology is based on the concept of

More information

Oracle Database 11g: Introduction to SQLRelease 2

Oracle Database 11g: Introduction to SQLRelease 2 Oracle University Contact Us: 0180 2000 526 / +49 89 14301200 Oracle Database 11g: Introduction to SQLRelease 2 Duration: 5 Days What you will learn In this course students learn the concepts of relational

More information

RDBMS Using Oracle. Use of IN OUT

RDBMS Using Oracle. Use of IN OUT RDBMS Using Oracle PL/SQL Procedural Language/Structural Query Language PL/SQL Procedures Kamran.Munir@niit.edu.pk Use of IN OUT Example: Format phone Procedure 1 Example: Format phone Procedure Input

More information

UNIT II PL / SQL AND TRIGGERS

UNIT II PL / SQL AND TRIGGERS UNIT II PL / SQL AND 1 TRIGGERS TOPIC TO BE COVERED.. 2.1 Basics of PL / SQL 2.2 Datatypes 2.3 Advantages 2.4 Control Structures : Conditional, Iterative, Sequential 2.5 Exceptions: Predefined Exceptions,User

More information

CSC Web Programming. Introduction to SQL

CSC Web Programming. Introduction to SQL CSC 242 - Web Programming Introduction to SQL SQL Statements Data Definition Language CREATE ALTER DROP Data Manipulation Language INSERT UPDATE DELETE Data Query Language SELECT SQL statements end with

More information

Suppose we need to get/retrieve the data from multiple columns which exists in multiple tables...then we use joins..

Suppose we need to get/retrieve the data from multiple columns which exists in multiple tables...then we use joins.. JOINS: why we need to join?? Suppose we need to get/retrieve the data from multiple columns which exists in multiple tables...then we use joins.. what is the condition for doing joins??...yes at least

More information

GIFT Department of Computing Science. [Spring 2016] CS-217: Database Systems. Lab-3 Manual. Single Row Functions in SQL

GIFT Department of Computing Science. [Spring 2016] CS-217: Database Systems. Lab-3 Manual. Single Row Functions in SQL GIFT Department of Computing Science [Spring 2016] CS-217: Database Systems Lab-3 Manual Single Row Functions in SQL V3.0 4/26/2016 Introduction to Lab-3 Functions make the basic query block more powerful,

More information

ORACLE Job Placement Paper. Paper Type : General - other

ORACLE Job Placement Paper. Paper Type : General - other ORACLE Job Placement Paper Paper Type : General - other 1. Tech + Aptitude written 2. Programming written ( main theme is to test our data structure knowledge, proficiency sorting searching algorithms

More information

Oracle PLSQL Study Material ORACLE & PL/SQL STUDY MATERIAL

Oracle PLSQL Study Material ORACLE & PL/SQL STUDY MATERIAL ORACLE & PL/SQL STUDY MATERIAL Table of Contents 1 OVERVIEW OF ORACLE... 5 1.1 THE DATABASE... 5 1.2 THE ORACLE INSTANCE... 8 2 BASIC ORACLE OBJECTS... 12 3 TRANSACTIONS IN ORACLE... 14 4 OVERVIEW OF PL/SQL...

More information

SQL STRUCTURED QUERY LANGUAGE

SQL STRUCTURED QUERY LANGUAGE STRUCTURED QUERY LANGUAGE SQL Structured Query Language 4.1 Introduction Originally, SQL was called SEQUEL (for Structured English QUery Language) and implemented at IBM Research as the interface for an

More information

SQL. Rodrigo García Carmona Universidad San Pablo-CEU Escuela Politécnica Superior

SQL. Rodrigo García Carmona Universidad San Pablo-CEU Escuela Politécnica Superior SQL Rodrigo García Carmona Universidad San Pablo-CEU Escuela Politécnica Superior 1 DDL 2 DATA TYPES All columns must have a data type. The most common data types in SQL are: Alphanumeric: Fixed length:

More information

Review -Chapter 4. Review -Chapter 5

Review -Chapter 4. Review -Chapter 5 Review -Chapter 4 Entity relationship (ER) model Steps for building a formal ERD Uses ER diagrams to represent conceptual database as viewed by the end user Three main components Entities Relationships

More information

Topic 8 Structured Query Language (SQL) : DML Part 2

Topic 8 Structured Query Language (SQL) : DML Part 2 FIT1004 Database Topic 8 Structured Query Language (SQL) : DML Part 2 Learning Objectives: Use SQL functions Manipulate sets of data Write subqueries Manipulate data in the database References: Rob, P.

More information

Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries

More information

Introduction to SQL. SQL is a standard language for accessing and manipulating databases. What is SQL?

Introduction to SQL. SQL is a standard language for accessing and manipulating databases. What is SQL? Introduction to SQL SQL is a standard language for accessing and manipulating databases. What is SQL? SQL (Structured Query Language) is a standard interactive and programming language for getting information

More information

SQL Structured Query Language (1/2)

SQL Structured Query Language (1/2) Oracle Tutorials SQL Structured Query Language (1/2) Giacomo Govi IT/ADC Overview Goal: Learn the basic for interacting with a RDBMS Outline SQL generalities Available statements Restricting, Sorting and

More information

MIS CURRICULUM. Advanced Excel Course - Working with Templates Designing the structure of a template Using templates for standardization of worksheets

MIS CURRICULUM. Advanced Excel Course - Working with Templates Designing the structure of a template Using templates for standardization of worksheets MIS CURRICULUM ADVANCE EXCEL Advanced Excel Course - Overview of the Basics of Excel Customizing common options in Excel Absolute and relative cells Protecting and un-protecting worksheets and cells Advanced

More information

CS2 Current Technologies Lecture 2: SQL Programming Basics

CS2 Current Technologies Lecture 2: SQL Programming Basics T E H U N I V E R S I T Y O H F R G E D I N B U CS2 Current Technologies Lecture 2: SQL Programming Basics Dr Chris Walton (cdw@dcs.ed.ac.uk) 4 February 2002 The SQL Language 1 Structured Query Language

More information

Advanced SQL Tribal Data Workshop Joe Nowinski

Advanced SQL Tribal Data Workshop Joe Nowinski Advanced SQL 2018 Tribal Data Workshop Joe Nowinski The Plan Live demo 1:00 PM 3:30 PM Follow along on GoToMeeting Optional practice session 3:45 PM 5:00 PM Laptops available What is SQL? Structured Query

More information

2. Programming written ( main theme is to test our data structure knowledge, proficiency

2. Programming written ( main theme is to test our data structure knowledge, proficiency ORACLE Job Placement Paper Paper Type : General - other 1. Tech + Aptitude written 2. Programming written ( main theme is to test our data structure knowledge, proficiency sorting searching algorithms

More information

II B.Sc(IT) [ BATCH] IV SEMESTER CORE: RELATIONAL DATABASE MANAGEMENT SYSTEM - 412A Multiple Choice Questions.

II B.Sc(IT) [ BATCH] IV SEMESTER CORE: RELATIONAL DATABASE MANAGEMENT SYSTEM - 412A Multiple Choice Questions. Dr.G.R.Damodaran College of Science (Autonomous, affiliated to the Bharathiar University, recognized by the UGC)Re-accredited at the 'A' Grade Level by the NAAC and ISO 9001:2008 Certified CRISL rated

More information

Learn Well Technocraft

Learn Well Technocraft Note: We are authorized partner and conduct global certifications for Oracle and Microsoft. The syllabus is designed based on global certification standards. This syllabus prepares you for Oracle global

More information

EDUVITZ TECHNOLOGIES

EDUVITZ TECHNOLOGIES EDUVITZ TECHNOLOGIES Oracle Course Overview Oracle Training Course Prerequisites Computer Fundamentals, Windows Operating System Basic knowledge of database can be much more useful Oracle Training Course

More information