sql for beginer
sql for beginer
sql for beginer
SQL >
show pdbs
Create an schema .
_-------
PK need.
-----------------------------------------
2) Constraints
Check:
alter table test.student_info ADD CONSTRAINT Check_id check (phone is not null);
alter table test.student_info drop constraint check_id;
alter table test.student_info ADD CONSTRAINT Check_id check (phone is not null);
alter table test.student_info drop constraint check_id;
Foreign:
############################################################################
Operators:
operator operand
1) Arithmetic Operators
+ , _ , * , /
select * from test.emp;
select
2) Concatenation Operator
############################################################################
Set operators:
UNION
UNION ALL
MINUS
INTERSECT
EXCEPT
1) UNION
But looking at this, we can’t tell which record comes from each table. Often we
don’t need to know, but sometimes we do.
You don’t need to specify the column aliases on the second table. Oracle will know
that the first columns match and use the alias already provided in the first query.
SELECT e.first_name,
e.last_name,
c.first_name,
c.last_name
FROM employee e
INNER JOIN customer c
ON e.first_name = c.first_name AND e.last_name = c.last_name;
2) UNION ALL
The major difference between UNION ALL and UNION in SQL is that UNION removes any
duplicate results from the final result set, and UNION ALL does not.
3) MINUS
The MINUS set operator will return results that are found in the first query
specified that don’t exist in the second query.
find all names in the customer table that don’t exist in the employee table.
4) EXCEPT
EXCEPT is the same as MINUS – they both show results from one query that don’t
exist in another query.
However, MINUS is an Oracle-specific keyword, and EXCEPT is in other databases such
as SQL Server.
The difference between UNION and INTERSECT is that UNION gets results from both
queries and combines them,
while INTERSECT gets results that only exist in both queries.
############################################################################
e.g. 2
The following expression is an example of a more complex expression that uses both
functions and operators.
The expression adds seven days to the current date, removes the time component from
the sum, and converts the result to CHAR data type:
TO_CHAR(TRUNC(SYSDATE+7))
2) Compound Expressions
3) CASE Expressions
CASE expressions let you use IF ... THEN ... ELSE logic in SQL statements without
having to invoke procedures.
CREATE TABLE TEST.CUSTOMER_CREDIT(
cust_first_name varchar(50),
cust_last_name varchar(50),
credit_limit number
);
SQL>
SELECT cust_first_name,
CASE credit_limit WHEN 60 THEN 'Low'
WHEN 1500 THEN 'High'
ELSE 'Medium' END AS credit
FROM TEST.CUSTOMER_CREDIT
ORDER BY cust_first_name,credit;
SELECT cust_first_name,
CASE credit_limit WHEN 50 THEN 'Low'
WHEN 1500 THEN 'High'
ELSE 'Medium' END AS credit
FROM TEST.CUSTOMER_CREDIT
ORDER BY cust_first_name,credit;
3) Column Expressions
4) CURSOR Expressions
5) Datetime Expressions
6) Function Expressions
You can use any built-in SQL function or user-defined function as an expression.
Some valid built-in function expressions are:
LENGTH('BLAKE')
ROUND(1234.567*43)
SYSDATE
circle_area(radius)
payroll.tax_rate(empno)
hr.employees.comm_pct@remote(dependents, empno)
DBMS_LOB.getlength(column_name)
my_function(a_column)
7)
Interval Expressions
An interval expression yields a value of INTERVAL YEAR TO MONTH or INTERVAL DAY TO
SECOND.
commit;
SELECT po.po_document.PONumber
FROM j_purchaseorder po;
9) Placeholder Expressions
A placeholder expression provides a location in a SQL statement for which a third-
generation language bind variable will provide a value.
10 ) Expression Lists
An expression list is a combination of other expressions.
DELETE
SELECT
UPDATE
You can use a condition in any of these clauses of the SELECT statement:
WHERE
START WITH
CONNECT BY
HAVING
Logical conditions can combine multiple conditions into a single condition. For
example, you can use the AND condition to combine two conditions:
1 = 1) AND (5 < 7)
name = 'SMITH'
employees.department_id = departments.department_id
hire_date > '01-JAN-08'
job_id IN ('SA_MAN', 'SA_REP')
salary BETWEEN 5000 AND 10000
commission_pct IS NULL AND salary = 2100
name = 'SMITH'
employees.department_id = departments.department_id
hire_date > '01-JAN-08'
job_id IN ('SA_MAN', 'SA_REP')
salary BETWEEN 5000 AND 10000
commission_pct IS NULL AND salary = 2100