Week 4&5
Week 4&5
Department number
DEPTNO NUMBER(2)
(foreign key).
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
•table_name: The name of the table where you want to insert data.
•column1, column2, ...: A list of the columns to insert data int
•
value1, value2, ...: The corresponding values for the columns.
Select statement
SELECT column1, column2, ...
FROM table_name
WHERE condition
ALTER TABLE EMP ADD CONSTRAINT PK_EMP
PRIMARY KEY (EMPNO);
TRIM Removes spaces from both sides SELECT TRIM(' Oracle ') FROM DUAL; → Oracle
2. Numeric Functions
Used for mathematical operations.
LAST_DAY Returns last day of the month SELECT LAST_DAY(SYSDATE) FROM DUAL;
Example:
SELECT ENAME, REGEXP_INSTR(ENAME, '[A-Z]') FROM EMP;
Finds the position of the first uppercase letter in the employee
name.
4. Using REGEXP_SUBSTR
REGEXP_SUBSTR returns the substring that matches the regular
expression.
Basic Syntax:
SELECT REGEXP_SUBSTR(column_name, 'pattern') FROM
table_name;
Example:
SELECT ENAME, REGEXP_SUBSTR(ENAME, 'A[AEIOU]') FROM
EMP;
Example:
SELECT ENAME, REGEXP_REPLACE(ENAME, '[AEIOU]', '*')
FROM EMP;
Replaces all vowels in the employee's name with '*'.