Sei sulla pagina 1di 19

Table is used to store data, basic unit View logically represent subsets of dta from one or

more tables Sequence used to generate Primary Key values Index it is used to improve the performance of some Queries Synonyms used to give alternate names to objects We have the following built-in data types of oracle are characterized as follows CHARACTER data type (char, nChar, varchar2 (it occupies only that space for which the data is supplied), nvchar2 (uni code data only, minsize1 max size 4000 bytes)) NUMBER data type(number(precision, scale),integer, long(max size 2gb,only one long column is valid for LONG and RAW data types (RAW it stores binary information like photos, signatures, thumb impressions) Date TIME tintypes (timestamp (extension of the DATE data type, it Stores *day *month *year *hour *minute *second Syntax: TIMESTAMP (Fractional-Seconds-precision)) Row Id data type: Long Raw: it can store more than binary data when compared to Raw Large Object (LOB) data types: built-in-LOB data types are (these data types stored inertly, Bfile is an LOB which is stored Externally, It can store text, image, video and special data, Lobs selection automatically returns the lob location) 1. BLOB (it stores unstructured binary large objects, they are bit streams with no character set semantics, they arte provide full transactional support) 2. CLOB (it dynamic data type, they provide full transitional support maximum size is 4 GB) 3. NCLOB Sysdate: is a pseudo-column, returns current date and time User: returns the user name of user who are logged in Substitution variables: these values are used to store values temporarily these values can be stored temporarily by using Single Ampersand (&) (apply for each instance when SQL statement is created or executed). Double Ampersand (&&) (apples for all instances) DEFINE and ACCEPT commands Run: used for executing the previous command (ex :> run (or) >/ Creating an .lst File: The list file is used top save the all information which performed in SQL*plus Navigation: File-->Spool-->Spool file

Creating an SQL Script File: The SAVE Command is used to store the current contents1 of the SQL Buffer. 1. At SQL prompt type the full name of the path where the file has to be created 2. Give the name of the file with .Sql extension 3. If the has to be replaced with the same existing name then use REPLACE ALL clause Ex: SAVE path (e:\bhadra) >save e:\bhadra REPLACE To GET the script "GET" is used: > Get path To Run Script: >RUN path to simple the script file >@ path

Select is used to retrieve data from one or more than table, view, object select-->identifies what columns, specified a list of column(one or more) From--->identifies which table distance--> Suppress duplicates 1. *(Projection operator) ---> select all columns 2. Columns/expressions ---> select named columns or the expressions 3. Alias --->Gives select columns different headings GENERAL: work with any data type ands pertain to using null values NVL: is used to convert a null value to an actual value Syntax: NVL (Expr1, Expr2); expr1: is the source value or expression that may contain null expr2: is the target value for converting NULL Ex: >select NVL (100,200) from dual; >select ename, (sal+500) + nvl (comm, 0) from emp; NULLIF (expr1, expr2): Compares two expressions and returns null if they are equal, or the first if there are not equal. it is possible when both the expressions are same data type COALESCE: Returns first not-null expression in the expression list. >select coalesce (100,600,200) from dual; >select ename, coalesce (comm, sal, 0) from dual;

create table dept(deptno number(2),dname varchar2(14),loc varchar2(13)) create table empl(empno number(4),deptno number(2),ename varchar2(14),job varchar2(9),mgr number(2),sal number(10),comm number(7,2),hiredate date) create table salgrade(garde number,losal number,hisal number) Insert into dept values(10,'accounting','newyork') Insert into dept values(20,'research','hyd') Insert into dept values(30,'sales','vja') Insert into dept values(40,'operations','jpt') Insert into salgrade values(1,700,1200) Insert into salgrade values(1,1200,1400) Insert into salgrade values(4,2000,3000) Insert into salgrade values(5,3000,5000) insert into empl values(5666,10,'bhadra','president',null,60000.00,null,'17-nov-1981') insert into empl values(5667,30,'raj','vice_pres',null,30000.00,null,'24-nov-1983') insert into empl values(5668,20,'suraj','salesman',null,15000,null,'24-nov-1993') insert into empl values(5667,30,'raju','acountnt',79,2000.00,50.50,'24-nov-1983') update salgrade set garde=2 where losal=1200 select * from empl
EMPNO DEPTNO EN AM E JOB MGR S AL COMM HIRED ATE

5666 5667 5668 5667

10 30 20 30

bhadra raj suraj raju

president vice_pres salesman acountnt

79

60000 30000 15000 2000

50.5

17-NOV-81 24-NOV-83 24-NOV-93 24-NOV-83

select * from salgrade


G ARDE LOS AL HIS AL

1 2 3 4 5

700 1200 1400 2000 3000

1200 1400 2000 3000 5000

/*examples for substring*/ select substr('bhadra',3,2) from empl select ename,job from emp where suubstr(job,6)=upper(man) select substr('bhadra',4) from empl /*example for Length*/ select length('bhadra'),length('suraj')from empl select length(ename)||' charcters exist in ---> '||Initcap(ename) from empl select initcap(ename),job from empl where length(ename)=5 select initcap(ename),job from empl where

substr(ename,4,length(substr(job,4,3)))='aj' LPAD: Pads the character value right-justified to total width of 'n' character positions. Syntax: LPAD (column/Expression, n, 'c') Fill extra spaces with char 'c'upto 'n' positions on left-side Ex: select lpad(ename,10,'@') from empl where deptno=10 Rpad: Ex: select rpad(ename,10,'@') from empl where deptno=30 select ename,lpad(rpad(ename,10,'*'),15,'*') from empl
EN AM E LP AD(RP AD(EN AM E,10,'*'),15,'*')

bhadra raj suraj raju

*****bhadra**** *****raj******* *****suraj***** *****raju******

Trim: Trim is for first and last characters are hidden Ex: select trim ('b' from 'bhadra') from empl
TRIM('B'FROM'BH ADR A')

hadra hadra hadra hadra

Replace: it replaces the every occurrence of search string Translate: Syntax: translate(char,from,to) Ex: select translate (ename,'bhadra','chanty') "bhadra-->chanty" from empl Concatenation operator: concatenates columns or character strings or expressions or constant to other values or columns represented by two vertical bars(||) the resultant column is a character Ex: > select empno||'--'||ename as empId from empl;

EMPID

5666--bhadra 5667--raj 5668--suraj 5667--raju

Literals: Select ename||':'||'month salary='||Sal as salary from empl Here :,month salary are literals,salaries is alias name for column header, the keyword 'AS' is optional for alias Duplicate Rows: To eliminate multiple duplicate rows in the result, the DISTINCT keyword is used We can specify multiple columns after DISTINCT qualifier Select DISTINCT job, num from empl; Filter of Records: The method restriction is based of the WHERE clause in sql. It contains the exact condition The where clause can be compared values in columns, Literal values Arithmetic expressions, Function Components of WHERE are column name, comparison operator, column name, constant. The character strings and dates should be enclosed in single Quotation marks Character values are case sensitive and dates values are format sensitive (DD-MM-YY) Comparison operator used in condition. Compare(expr1,expr2) Relational or comparison operators: **,<>,^=,!=,>,>==,<==,=,< Logical operators: Combines the result of two components conditions to produce a single result Three Logical operators are available AND, OR, NOT AND: Based on two or more conditions being met, It returns false if either is false, else return unknown EX >Select ename, Sal, job from empl where (sal>=1500 and sal<=5000) and job=clerk
EN AM E S AL JOB

suraj

15000

salesman

OR: It returns true if either component conditions is true. It returns false if both are false, else return unknown

Select * from empl where sal>=2000 or deptno=20


EMPNO DEPTNO EN AM E JOB MGR S AL COMM HIRED A TE

5668 5667

20 30

suraj raju

salesman acountnt

79

15000 2000

50.5

24-NOV-93 24-NOV-83

Between---And---; NOT BETWEEN---- and Between is used to display the rows based on range of values The declared range is inclusive Lower limit should be declared as first Ex: select * from empl where sal between 5000 and 80000;
EMPNO DEPTNO EN AM E JOB MGR S AL COMM HIRED ATE

5666 5667 5668

10 30 20

bhadra raj suraj

president vice_pres salesman

60000 30000 15000

17-NOV-81 24-NOV-83 24-NOV-93

Ex: select select * from empl where hiredate between '20-nov-1981' and sysdate
EMPNO DEPTNO EN AM E JOB MGR S AL COMM HIRED ATE

5667 5668 5667

30 20 30

raj suraj raju

vice_pres salesman acountnt

79

30000 15000 2000

50.5

24-NOV-83 24-NOV-93 24-NOV-83

IN operator and NOT IN operator: This is used to test values in specified list The oprerator can be used upon any datatype Ex: Select ename,sal,job from empl where deptno in(10,30)
EN AM E S AL JOB

bhadra raj raju

60000 30000 2000

president vice_pres acount

LIKE Operator: Like condition to perform wildcard Like searches of valid search string values The available wild are % --> represents any sequence of zero or more characters - --> represents any single character, only at that position / --> represents escape option Ex: Select * from empl where ename like bh%
EMPNO DEPTNO EN AM E JOB MGR S AL COMM HIRED ATE

5666

10

bhadra

president

60000

17-NOV-81

IS NULL and IS NOT NULL: Test for null values It is only operator that can be used to test for null Null values means the value is unavailable, unassigned, unknown, or in applicable

Select * from empl where comm is null;


EMPNO DEPTNO EN AM E JOB MGR S AL COMM HIRED ATE

5666 5667 5668

10 30 20

bhadra raj suraj

president vice_pres salesman

60000 30000 15000

17-NOV-81 24-NOV-83 24-NOV-93

Select * from empl where comm is not null


EMPNO DEPTNO EN AM E JOB MGR S AL COMM HIRED ATE

5667

30

raju

acountnt

79

2000

50.5

24-NOV-83

Character functions:
Lower (column/Expression):
It converts alpha character values to lower The return type has the same data type as argument char type(char or varchar) Syntax: LOWER(column/expression) Ex: select lower (ename) from empl;
LOWER(EN AME)

bhadra raj suraj raju

Upper (column/Expression)-

It converts into upper case

Syntax: Upper(column/expression) Ex: select upper (ename) from empl


UPPER( EN AM E)

BHADRA RAJ SURAJ RAJU

INITCAP
It returns a string with the first character of each word uppercase, keeping all other Ex: Select initcap (job)from empl
INITC AP(JOB)

President Vice_Pres Salesman Acountnt

CONCAT
---It is concate the first character value of the second character value,only the two parameters accept Syntax: concat (column/expr1, column2/expr2) Ex: select concat(empno,hiredate) from empl;
CONC AT(EM PNO,HI RED ATE)

566617-NOV-81 566724-NOV-83 566824-NOV-93 566724-NOV-83

SUBSTR
It returns specified characters from character value, string from a specified position m to n character long Syntax: substr(column/Expression),m,[n]) [n] Is optional parameter it indicate current location M indicate starting point of the string Ex: select substr(ename,3,2) from empl
SUBSTR(EN AME, 3,2)

ad j ra ju

It display from 3rd position to next 2 characters

Ex: select substr(bhadra3,6) from dual


SUBSTR('BH ADR A', 3,6)

adra

Real-time scenario: Length:


Returns the no. of characters in a value If the char has data type CHAR, the length include trailing blocks If character is null it returns null Syntax: Length (column/Expression) Ex: select ename, length(ename) from empl
EN AM E LENG TH(EN AME)

bhadra raj suraj Raju

6 3 5 4

Power:
It returns m raised to the nth power Syntax: power (m, n) Ex: select power (5, 2) from dual
POWER(5,2)

25

Square:
It returns square root of n as real number The value n cant be negative Syntax: sqrt(n) Ex: select SQRT (25) from dual;
SQRT(25)

Absolute:
Returns the absolute value of n Syntax: abs (n) Ex: select sal,comm,sal-comm,abs(sal-comm) from empl where ename='raju'
S AL COMM S AL- COMM ABS( S AL-COMM)

2000

50.5

1949.5

1949.5

Ex: select abs (-100) from dual


ABS(- 100)

100

Sign:
It returns the sign(+/-), specified column/number Syntax: sign(n) n--- expression or number or numeric column

Working with DATES:


Oracle stores dates in an internal numeric format Range from JANUARY 1, 4712 B.C TO DECEMBER 31, 9999 A.D Default display and input format for any date in DD-MM-YY *century * year *month *day *hours *minutes * seconds

Sysdate:
It is a date function that returns current system date and time Syntax: Select Sysdate from dual Ex: select Sysdate, sysdate+10 from dual
SYSD ATE SYSD ATE+10

30-MAR-12

09-APR-12

Ex: select Sysdate, Sysdate-10 from dual


SYSD ATE SYSD ATE-10

30-MAR-12

20-MAR-12

Ex: select ename,Sysdate,hiredate,round((sysdate-hiredate)/7) from empl


EN AM E SYSD ATE HIRED ATE ROUND((SYSD ATE- HIRED ATE)/7)per w eeks

bhadra raj suraj raju bhadra bhadra

30-MAR-12 30-MAR-12 30-MAR-12 30-MAR-12 30-MAR-12 30-MAR-12

17-NOV-81 24-NOV-83 24-NOV-93 24-NOV-83 25-MAR-12 29-MAR-12

1585 1479 957 1479 1 0

Ex: select ename,Sysdate,hiredate,round(sysdate-hiredate) from empl


EN AM E SYSD ATE HIRED ATE ROUND(SYSD ATE-HIRED ATE)

bhadra raj suraj raju bhadra bhadra

30-MAR-12 30-MAR-12 30-MAR-12 30-MAR-12 30-MAR-12 30-MAR-12

17-NOV-81 24-NOV-83 24-NOV-93 24-NOV-83 25-MAR-12 29-MAR-12

11092 10355 6702 10355 6 2

Add_months:
Syntax: add_month(d,+(or)- n) Adds n number of calendar months The value of n must be an integer and canbe negative Ex: Select Sysdate,add_months(Sysdate,2) from dual
SYSD ATE ADD_MONTHS(SYSD ATE,4)

30-MAR-12
EN AM E S AL

30-JUL-12
ADD_MONTHS(HI RED ATE,2)

Ex: select ename,sal,hiredate,add_months(hiredate,2) from empl where deptno=20


HIRED ATE

suraj

15000

24-NOV-93

24-JAN-94

Months_between:
Syntax: months_betweeen(d1,d2) Ex: Select round(months_between(Sysdate, hiredate)) from empl
ROUND(MONTHS_BETWEEN(SYSD ATE, HIRED ATE))

364 340 220 340 0 0

Next_day:
Syntax: next_day(d,char) Ex: select next_day(sysdate,monday) from dual
NEXT_D AY( SYSD ATE,'SUND AY')

01-APR-12

Last_day(d):
Syntax: Last_day(d) mostly used for to determine how many days are left in the current month Ex: select add_months(last_date(Sysdate),-1)+1 from dual
ADD_MONTHS(L AS T_D AY(SYSD ATE),- 1)+1

01-MAR-12

Rounding of dates:
Syntax: round(date, format) Returns date rounded to the unit specified by the format Ex: select round(sysdate,day) from dual
ROUND(SYSD ATE,'D AY')

01-APR-12

Truncating dates:
Sysdate: trunc(date, format) Return with the time portion of the day truncates to the specified unit. Ex: select round (Sysdate, day),trunc (Sysdate, day) from dual
ROUND(SYSD ATE,'D AY') TRUNC( SYSD ATE,'D AY')

01-APR-12
ROUND(SYSD ATE,'MONTH')

25-MAR-12
TRUNC( SYSD ATE,'MONTH')

Ex: select round (Sysdate, month),trunc (Sysdate, month) from dual


01-APR-12
ROUND(SYSD ATE,'YE AR')

01-MAR-12
TRUNC( SYSD ATE,'YE AR')

Ex: select round (Sysdate, year),trunc (Sysdate, year) from dual


01-JAN-12 01-JAN-12

=============================================================== To_char(number conversion)-To_char(number,fmt) (fmtoptional no. format) To_char(date conversion) to_char(date,fmt)

Decimal Indicator:
Returns the specified position of the decimal character The default decimal delimiter is period . Only one decimal indicator can be specified in a number format model Ex: Select 1234, to_char (1234,999D99) from dual
1234 TO_CH AR( 1234,'999D99')

1234

#######

Levels of Constraint:
Column level:

Used to define constraints next in column name Define with each column Composite key cant be defined
Table level:

Defining constraints after defining all columns NOT NULL cant be defined The constraint clause can appear in 1. Create table 2. Alter table 3. Create view Oracle doesnt support constraint on column or attribute whose types is 1. User defined object 2. Nested table 3. Varray 4. Ref 5. LOB

Viewing constraints:
To view all constraints on table by query the USER_CONSTRAINT table The code are revealed are 1. P-primary 2. U-unique 3. R-references 4. C-check and not checked Ex: select owner,constraint_name,constraint_type from user_constraints where table_name=FZ_SRV_ITEm

Domain integrity:
The data which is not obeying integrity constraints is called inconsistent data is generated. It allows entering only valid data. A domain means a set of permitted values These constraints set a range, enforcement of not null constraint in a table Three types of domain name constraints 1. Not null constraint 2. Check constraint 3. Default constraint

Entity Integrity:
Unique constraint Primary key constraint It defines a entity or column as a UNIQUE for a particular table Primary key constraints avoids duplicate and null values Note: The table containing the foreign key is called the child table and the table Containing the referenced key is called the parent key. As per oracle NOTNULL, unique, primary key, foreign key, check constraints are constraints

Not null constraint:


Allows duplicate values Define only at column level Ex: create table bh(name varchar(20) constraint nam NOTNULL);

Unique key constraint:


Suppres duplicate values in columns Accepts null values A table can have more than one unique key Restriction: unique key cant be implementing on columns having .LOB .LONG .Long Raw .Varray .Nested Table .Object .BFile .REF .Timestamp A composite unique key cant have more than 32 columns

Primary key: Not accepts null values and duplicate values. Only one primary key or
Composite primary key is allowed per table.

References: Identify the parent table and the column name or combination of columns
that make up the referenced key Foreign key: Identifies the column or combination of columns in the child table that makes up of the foreign key.

ON DELETE clause:
CASCADE option used to remove the child table record automatically, when parent record is removed Specify SET NULL if we want oracle to convert dependent foreign key values to null

Adding Constraints to a table: Syntax: Alter <table> <table name> add (<constraint name> <const variable> column-type (column-name) We can ADD, DROP, ENABLE or DISABLE a constraint NOTNULL, DEFAULT can be added to existing column by using the MODIFY Clause of the ALTER TABLE Statement. Ex: alter table empl add constraint bha foreign key (id), references emp (empno); Dropping Constraint: Syntax: Alter table <table name> Drop Primary Key/ Unique (column) [OR] Constraint <const variable> [cascade]; Ex: Alter table bhadra drop Primary key; Alter table bhadra drop unique (column name); Select index-name from user-indexes where table-name=employ;
Disabling Constraint: The constraint can be disabled with out dropping it or re creating it The ALTER TABLE statement is used with the DISABLE Clause. The cascade clause disables dependent integrity constraints Syntax: alter table <table name> disable Constraint <constraint name> [cascade]; Ex: alter table bhadra disable constraint emp-no cascade Enabling Constraint: Syntax: alter table <table name> enable constraint <constraint name> Ex: alter table bhadra enable Constraint empname;

Note: If there are already same data is in another table these data can be used for insertion into a new table. We use following query. Syntax: insert into <table> <columns> <query> Ex: insert into emp(eno, empid, sal, addr) select empno,empid,empsal, empaddr from empl where hiredate<31-dec-60; Transaction Control Language (TCL): Commit, save back, rollback Commit: Modifications on tuples are temporarily stored in database system. They become permanent only after the statement commit IT will erase all the save points and releasing transaction locks Save point: Syntax: save point <save point name> Rollback: it undoes the work done in the current transaction from starting or lost commit Syntax: rollback work;
================================================================== DATABASE SECURITY ==================================================================

ORACLE Data Dictionary contains all the information about the structures and objects of database such as tables, columns, users, data files etc. the data stored in data dictionary is called metadata. It is usually consists of two levels Internal level: contains all base tables that are used by various DBMS. S/w components and they are normally not accessible by end user. External level: provides numerous views on these base tables to access information about objects and structures at different levels of detail. ORACLE database always includes the creation of three standard ORACLE users: Sys: This is the owner of all data dictionary tables and views. That user has the highest privileges. To manage objects and structures of an Oracle database such as create new users. System: owner of tables used by different tools. Public: the tables and vies provided by the data dictionary contain information about users and their privileges All the tables and views of the data dictionary those are accessible by the user. The external level data provides users a front end to access information relevant to the users. The level provides numerous views. The views provided by data dictionary are divided into three parts. USER, All and DBA
The database user can cancel the permissions By using the Grant and Revoke statements to grant and revoke objects privileges Schemas: It is a collection of objects such as tables views and sequences. The schema is owned by a database user and has the same name as that user. Data Control Language (DCL): Grant: It is used to allow another schema access to a privilege. Command can be issued not only on table objects but also on views, Synonyms, tables, indexes, Sequences etc. The users are granted at time all four(insert, update, delete, select) by using All Syntax: Grant <privileges> on<object name> to <user name> Ex: Grant select, update on bhadra to bhadra The user only performs select and updates commands on table name. the grant table can be used with dot(.) notation Ex: select * from admin.emp_master Revoke: Revoke is used to withdraw the privileges that have been granted to a user Syntax: revoke <privileges> on <object name/table name> from <user name> Ex: revoke select, update on empl from system; Creating user: Syntax: create user <user name> Identified by <password> Grant connect, resource to<user name> Ex: create user bhadra identified by 8125789257;

=============================================================== JOINS Displaying data from multiple tables Equijoin: = join two columns, when two tables/columns are compared. This join operator is called equijoin Select ename, e.deptno, d.dname from empl e, dept d where e.deptno=d.deptno;
EN AM E DEPTNO DN AM E

bhadra raj suraj raju bhadra bhadra rohith

10 30 20 30 10 10 20

accounting sales research sales accounting accounting research

Outer joins: Select ename, e.deptno, d.dname from empl e, dept d where e.deptno(t)=d.deptno;
EN AM E DEPTNO DN AM E

bhadra raj suraj raju bhadra bhadra rohith -

10 30 20 30 10 10 20 -

accounting sales research sales accounting accounting research operations

8 rows returned in 0.00 seconds

Non equijoins: Columns are not match ex: sal, sal grade table Oracle Joins SQL equijoins =================================== Equijoins cross joins Non equijoins normal joins Outer joins using clause Self joining full outer joining (left, right) Join table on Cross joins: These are used for testing purpose Ex: Select e.ename, e.deptno, d.dname from emp e, dept d Natural joining: Joining based on common columns
Full outer join (left, right): Natural/inner:

Grouping
Grouping function are max, min, count, avg, sum, distinct Ex: Select sum (sal) from empl where dept in (20, 30)
SUM(S AL)

50000
1 rows returned in 0.00 seconds

Select ename, sum (sal) from empl where dept in (20, 30) It gives the error message. Because sum is adding the all column values and display result in single statement
ORA-00937: not a single-group group function

Select deptno,sum(sal) from empl group by deptno It will display the sum of the groups having the same group values
DEPTNO SUM(S AL)

30 20 10

32000 18000 200000

3 rows returned in 0.05 seconds

Select max (sal) from empl It display who are having maximum salary in empl table
M AX(S AL)

70000

Select min (sal) from empl It display who are having minimum salary in empl table
MIN(S AL)

2000

Having clause: Restricting on grouping functions Select deptno, avg (sal) from empl group by deptno having avg(sal)>=600
DEPTNO AVG(S AL)

30 20 10

16000 9000 66666.6666666666666666666666666666666667


3 rows returned in 0.00 seconds

Where clause: It is used for to select columns based on condition we used. In this used mainly logical connectives AND, OR, NOT, BETWEEN..AND Comparison operators are also used like =, !=, <>, <, >, <=, >=

===============================================================

Sub Queries:
=============================================================== Ex: Select * from empl where sal>500 Here from WHERE sal>500 is a sub query Select * from empl where sal> (select sal from emp where ename=bhadra)
EMPNO DEPTNO EN AM E JOB MGR S AL COMM HIRED ATE

5252 5253

10 10

bhadra bhadra

chirman chirman

50 50

70000 70000

20.5 20.5

25-MAR-12 29-MAR-12

We use order by in sub query analysis where only in top-n analysis Single row operators ; multiple row operators: Ex: Select eid,ename,sal from empl where sal in(select sal from empl where ename=bhadra) and dept= (select empl where ename=raj) Select empno,ename,Sal from empl where sal=(select min(sal) from empl)
EMPNO EN AM E S AL

5667

raju

2000

Select empno,ename,Sal from empl where sal=(select max(sal) from empl)


EMPNO EN AM E S AL

5252 5253

bhadra bhadra

70000 70000

Select empno, ename, job, sal from empl where sal> (select avg(sal) from empl where deptno=30)
EMPNO EN AM E JOB S AL

5666 5667 5252 5253

bhadra raj bhadra bhadra

president vice_pres chirman chirman

60000 30000 70000 70000

Row id: very useful when finding duplicates Create table dup as (select ename,deptno,sal,job from empl); Table created. Create table with structure but not data. 1. Alter table <table name> add (column_name datatype,); Set-value sub queries: Syntax: <expression> [not] in (<sub query) <expression> <comparison operator> [any/all] (<sub query)

Comparison operator used for to compare a given Expression. With each value selected by sub query Test for existing /[non existing] Syntax: [not] exists (<sub query>) 1. [ ]--- optional values are mention in [ ] 2. All and Any: In = any Not in = < > all or !=all 3. For certain rows do (not) exist in (other) tables, formulated using exists operator. Data Definition Language (DDL): Create table <table_name> (columns) Desc <table_name> ---- It describes about the table Alteration table: It is used with a user want to add a new column or change the width of data type or data itself or to add or drop integrity constraints column i.e. table altered by adding column by changing definition or dropping column or add column Syntax: alter table <table name> add/drop <column datatype,.) Add is used with alter table Drop is delete the column Modify is used when you want to modify any existing column Syntax: alter table <table name> modify (column name) Ex: alter table empl modify empid varchar2 (50) The actual size is replaced with 50 Drop table <table name> Truncate command deletes all the records permanently but not deletes the whole structure. Once command is performed it cant be rollback. Change table name by using Rename Syntax: rename <old name> to <new name> Data Manipulation Language (DML): Insert, update, delete, and merge Insert into <table name> [Column names] values (column data); Update <table name> set <column name> = <condition> where <condition> Delete <from> <table name> where <condition>

Potrebbero piacerti anche