DBMS Ex4
DBMS Ex4
1201
Experiment-4:
Queries using conversation functions (To-char,To-
date,To_no)stringfunctions(L pad,R pad,R trim,substring,instr)
Date
functions(sysdate,nextdate,add_months,least_date,months_between,
least,greatest,trunc,round)
To_char:
IT converts date Values into characters string values.
Query:
Ex:sql>select To-char(sysdate) from dual;
To_date:
IT converts string Values into characters date
Query:
Ex:sql>select To-date(‘jan 3 1998’,’month dd, yy)from dual;
String functions:
Lower:
It converts the string value to lower
case. Query:Sql>select lower(‘SAI’) from
dual;
Upper:
It converts the string value to upper case.
Query:Sql>select upper(‘SAI’) from dual;
Page no:
DATE: / /
1201
Page no:
DATE: / /
1201
R trim: It is used to remove all specify characters from left side of the string.
Query:
Sql> select rtrim(’******’ ,‘sai’,’***’,’*’) from dual;
Date functions:
SysDATE():
It returns the current date in the
system. Query:
Sql> select sysdate from dual;
NextDAy():
It returns the next date the next coming day.
Query:
Sql> select nextday (‘Sunday’)from dual;
Page no:
DATE: / /
1201
Add_months():
It returns the next date after adding number of months in the arguments.
Query:
Sql>select add_months(sysdate,5) from dual;
Last_day():
It will takes a date value as an argument and returns the last day of month in that
date. Query:
Sql> select last_date(sysdate) from dual;
Months_between():
It returns the number of months between given two dates.
Query:
Sql>select months_between(‘2-feb-2021’,’2-oct-2020’) from dual;
Least():
It returns least value from the given arguments or attributes.
Query:
Sql>select least(300,17,2121) from dual;
greatest():
It returns maximum value from the given arguments or attributes.
Query:
Sql>select greatest(17,100,2121) from dual;
Page no:
DATE: / /
1201
trunc():
It returns a date value truncated to a specified
unit. Query:
Sql>select trunc(sysdate,’mm’) from dual;
Round():
It returns round a number to a specified length or precision.
Query:
Sql>select round(23.49,0) from dual;
To_char():
It convert the given data type attribute values to text and return the date in the specific
Format.
Query:
Sql>select to_char(sysdate,’yy-mm-dd’) from dual;
DATE: / /
Page No: