Sunteți pe pagina 1din 7

Plsql operators:

----------------
Arithmetical operators:
-----------------------
+ addition
- subtract
* multiply
/ division (quotient)

Mod() - division (remainder)

Relational operators or comparision operators:


-----------------------------------------------
< less than
> greater than
<= less than or equal to
>= Greater than or equal to
= equal to
!= not equal to

a>b and a>c

Logical operators:
------------------
and
or
not

and
a b c=a*b
0 0 0
0 1 0
1 0 0
1 1 1

Note: if all input values are true then output is true else false.

or

a b c=a+b
0 0 0
0 1 1
1 0 1
1 1 1

Note: If any one input values are true then output is true else false.

Not
a c
0 1
1 0

Special operators:
-----------------
in
not in
between
not between
like
not like
is null
is not null

set operators:
--------------
union
union all
intersect
minus

Assignment operators:
--------------------
:=

a:=100
b:=200
c:=a+b

Concatenation operators:
------------------------
|| (pipe line char)

Plsql datatype or fieldtypes:


-----------------------------
Character Datatypes: (A to Z and 0 to 9)
-----------------------------------------
char(2000) - Fixed length char - 1 byte - Ascii - Static memory allocation -Ansi
rules

gender -> M/F


ttype -> cr/db

varchar(20) - variant length char - 1 byte - Ascii - dynamic memory allocation -


Ansi rules/Ansi syntax

varchar2(40) - variant length char - 1 byte - Ascii - dynamic memory allocation -


oracle rules/syntax

Nchar(20) - Fixed length char - 2 bytes - unicode - static memory allocation

nvarchar(20) - variant length char - 2 bytes - unicode - dynamic memory allocation

Number datatypes: (0 to 9)
------------------
number(10)
number(10,2)=> 9999999.99
int - 4 bytes
OR
INTEGER - 4 BYTES

decimal point datatypes:


-----------------------
float - 4 bytes (Approx. 7 decimal digits)
Date and time datatypes:
------------------------
date - 8 bytes - 'DD-MON-YY' ex: '14-DEC-18'
timestamp - 13 bytes - 'DD-MON-YY HH:MI:SS.MS AM/PM'

Large objects(LOB)
------------------
BLOB -binary large objects
CLOB - character large objects
BFILE -binary file

Raw datatypes:
---------------
raw
long raw

--How to create new table?

syntax:

create table <tablename> (fieldname1 fieldtype1,fieldname2 fieldtype2,fieldname3


fieldtype3,....);

--example

create table employee(ename varchar2(20),empno number(4),


salary number(5));

--How to insert the records?

I syntax:

insert into <tablename> values('value1',value2,value3);

insert into employee values('aaa',101,25000);


insert into employee values('bbb',102,35000);
insert into employee values('ccc',103,45000);

--How to select the records? (day to day work)

syntax: (User follows)

select <Fieldnames>
from <tablename>
where <condition>
group by <fieldname>
having <condition>
order by <fieldname> desc/asc;

System follows:
---------------
from <tablename>
where <condition>
group by <fieldname>
having <condition>
order by <fieldname> desc/asc;
select <fieldnames>

ex:

select ename,empno,sal from employee;

select * from employee;

--example

create table employee(ename varchar2(10),empno number(4),


salary number(5))

insert into employee values('aaa',101,25000)


insert into employee values('bbb',102,35000)
insert into employee values('ccc',103,45000)
select * from employee

select ename,salary from employee

student

sname sno s1 s2 s3
aaa 101 90 89 78
bbb 102 67 90 99
ccc 103 45 67 56

create table student(sname varchar2(10),sno number(3),s1 number(3),s2 number(3),s3


number(3));

insert into student values('aaa',101,90,89,78);


insert into student values('bbb',102,67,90,99);
insert into student values('ccc',103,45,67,56);

select * from student;

Insert command
-----------------

I method (only one record all values)

insert into <tablename> values('value1',value2,value3);

II method (only one record partial values)

insert into <tablename>(fieldname1,fieldname2,fieldname3)


values('value1',value2,value3);

III method (Multiple records)


insert into <tablename> values('&value1',&value2,&value3);

insert into student(sname,sno,s2,s3) values('chandra',104,89,78)


select * from student
insert into student(sname,sno) values('rajesh',105)

what is meant by null?

* Null is not equal to zero.

* Null is not equal to empty.

* Null is not equal to blankspace.

* Null is an undefined values.

--How to insert multiple records?

insert into student values('&sname',&sno,&s1,&s2,&s3);

select * from student

select * from student where s1>=80 and s2>=80


select * from student where sname='reddy'
select sname,sno,s1 from student

party

partyid partyname partyloc


101 aaa hyd
102 bbb che
103 ccc mum

bank_transaction

cname accno ttype tdate amount


raj 1001 cr 14-DEC-18 2500
KUMAR 1002 DB 14-DEC-18 3500
SHEKAR 1003 CR 14-DEC-18 4500

CREATE TABLE BANK_TRANSACTION(CNAME VARCHAR2(10),ACCNO NUMBER(4),TTYPE


CHAR(2),TDATE DATE,AMOUNT NUMBER(5));

INSERT INTO BANK_TRANSACTION VALUES('RAJ',1001,'CR','14-DEC-18',2500);

INSERT INTO BANK_TRANSACTION VALUES('KUMAR',1002,'CR','14-DEC-18',4500);

INSERT INTO BANK_TRANSACTION VALUES('SHEKAR',1003,'CR','14-DEC-18',4500);


SELECT * FROM BANK_TRANSACTION;

BANK_MASTER

ACCNO BALANCE
1001 10000
1002 20000
1003 30000
1004 40000
1005 50000

S-ar putea să vă placă și