Você está na página 1de 4

Functions Numeric Functions Character Functions Date Fn. Group / Aggregate Fn. 1. Numeric Functions 1. ABS(n) 2.

Ceil (n) 3. Floor ( n) 4. Mod(m,n) 5. Power(m,n) 6. Sign(n) will return -1 if n<0 , 1 if n >0 , 0 if n=0 7. Sqrt(n) 8. Trunc(m,n) for decimal 9. Round(m,n) 10. Exp(n) 11.Greatest( n1,n2,n3,n....) 12.Least(n1,n2,n3,n....)

2. Character Functions 1. Initcap(string field) will convert first char. to Capital Letter 2. Lower(string) 3. Upper(string) 4. Lpad(string , n , char) Lpad('Ora' , 10,'*') =*******Ora 5. Rpad(string , n,char) Rpad('Ora', 10,'*') = Ora******* 6. Ltrim(string) 7. Rtrim(string) 8. Substr(string , start pos., no. of characters to extract ) eg. Su bstr('computer',3,3) = put 9. Length (string) 10. Instr ( string , char to search ) will return first occurence of the char. from string 11. Instr ( string , char to search , Starting Pos. , pos. of occurence ) 12. Trim(string) Trim(' Ora ') 13. Trim(leading 'x' from string ) 14. Trim(Both 'x' from string ) 15. Decode ( field to check , value to compare,True , False) same as if condition if (field to compare , True value , Fals e value ) if (field to compare , True value, field to compare , True Value , field to compare ,True , False ) e.g. select decode(job,'CLERK',11,'SALESMAN',12,'MANAGER',13,14 ) ,JOB FROM EMP;

same as

16. Translate (string , 'String to translate' , 'String to replace' ) Find and Replace e.g. Translate ( '456Oracle123' , '423' , '796' ) output : 756Oracle196

3. Date Functions

1. 2. 3. 4. 5. 6.

Sysdate will return system date Add_months (date , no.) Months_between(date1 , date2) Last_day(date) Next_day(date , day ) e.g Next_day (sysdate , 'Friday') Extract ( year from datefield) will extract year from date Extract( month from datefield) Extract(day from datefield) Extract(minute from datefield)

4. Group / Aggregate Functions ( It affects to whole table ) 1. 2. 3. 4. 5. Count ( ) Max( ) Min( ) Avg( ) Sum( ) e.g 1. Select count(*) as 'Total Emp' from Emp; 2. Select max(Salary) as 'Max Sal' from Emp; 3. Select min(Salary ) as 'Min Sal' from Emp; 4. Select Avg(Salary) as 'Average ' from Emp; 5. Select Sum(Salary ) as ' Total Salary' from Emp; -------------- All group fn. in one --------------Select Count(*) as 'Count' , max(salary ) as 'Max Salary ' , min(salary ) as 'Min Salary' as 'Average Salary' , sum (salary) as 'Total Salary ' from Emp; , Avg(salary) will count no. of records in table will return maximum amount from numeric field will return minimum amount from numeric field will return Average value from numeric field will do summation of numeric field

******************************** ****** 1. 2. 3. 4. 5. 6. Not Null Check Default Primary key Foreign Key Unique

Constraints

******************************

Constraint can be defined at column level and table level *** Giving multiple constraint Create Table myTab ( no name number(4) Not Null Primary key, varchar2(30) ,

city 'Abad' , Grade Check ( Grade in ('101','102','103')), PassPortNo Unique, CustNo CustNo) );

varchar2(30) Not Null Default char(3) char(15) number(4) Default '100' Not Null References Order(

Above table will store all constraints in oracle as some system no. You can view all those constraints by select constraint_name , constraint_type , Table_name from user_constra ints ; ** To specify constraint name so that we can know , for future reference Create TAble myTab( no name city Grade CustNo number (4) Not Null , varchar2(30) , varchar2(30 ) Not Null , char(3) , number(4),

constraint myTab_pk primary key (no) , constraint myTab_ck check ( Grade in ('101','102','103' )) , constraint myTab_fk r(CustNo) ); Above table will store your defined constraints with name specif ied i.e. myTab_pk , myTab_ck , myTab_fk You can view your defined constraints in table USER_CONSTRAINTS as select constraint_name , constraint_type , TAble_name from user_ constraints ; *** If we want to delete check constraint from myTab, we will specify as Alter table myTab drop constraint myTab_ck ; CASE 1 : Create table myTab ( no number(4) , name varchar2(30) , CustNo n umber(4) ); In above statement we missed to give constraints, so now we will specify constraints by ALTER command as 1st method : ( without constraint name ) Alter table myTab add primary key (no ) add foriegn key CustNo references Order(CustNo) ; foriegn key CustNo references Orde

2nd method : ( with constraint name ) Alter table myTab add constraint myTab_pk add constraint myTab_fk erences Order(CustNo) add constraint myTab_ck check ( name in ('aa',' bb','cc')); ************************BYE FOR TODAY ______________ MEET U ON FRIDAY PRAC. Al primary key (no) foriegn key CustNo ref

Você também pode gostar