Вы находитесь на странице: 1из 12

EXPERIMENT-7

AIM – To Perform Various Functions On The Tables.

CHARACTER FUNCTIONS In order to compare an attribute with a string, It is


required to surround the string by apostrophes, For example., where LOCATION =
‘DALLAS’. A powerful operator for pattern matching is the like operator. Together with
this operator, two special characters are used :-

1. The present sign% (also called wild card)


2. The underline _, also called position marker.

Further string operations are

UPPER Takes a string and converts any letters in it to uppercase.The return data has
the same data type as the argument char. The syntax of the UPPER command is
UPPER(char)

For example, to change the all the values to uppercase letter in the column ‘name’

LOWER(<string>) returns the argument char, with all letters in lowercase.


The return value has the same datatype as the argument char (CHAR or VARCHAR2).
The syntax of the LOWER command is
LOWER(char)
For example
INITCAP(<string>) returns the given argument char, with the first letter of each in
uppercase, all other letters in lowercase. Words are delimited by white spaces or
characters that are not alphanumeric.The syntax of the INITCAP command is
INITCAP(char)

For example

SUBSTR(<string>,n,m) returns a portion of char, beginning at m, n characters long.


If m is 0, it is treated as 1.
If m is positive, oracle counts from the beginning of char to find the first character. If m
is negative, oracle counts backwards from the end of char. If n is omitted, oracle returns
all characters to the end of char. If n is less than 1, a null is returned.
Floating point numbers passed as arguments to substr are automatically converted to
integers. The syntax of the SUBSTR command is
SUBSTR(char,m,[n])

For example
LENGTH(char)this function returns the length of the given string.
it returns the length of parameter specified by argument char in characters.
If argument char has datatype char, the length includes all the trailing blanks.
If argument char is null, this function returns null. The syntax of the LENGTH
command is
LENGTH(char)

For example

INSTR Return the location of nth occurrence of string X in the string data , starting
from positions. The syntax of the INSTR command is
INSTR( DATA,X,S,N )

For example
GREATEST It returns the greatest value among all expression. The syntax of the
greatest command is
GREATEST (EXP1,EXP2,EXP3…. )

For example

LEASTIt returns the least value among all expression. The syntax of the LEAST
command is
LEAST (EXP1,EXP2,EXP3…. )

For example

NUMERIC FUNCTIONSNnumeric functions are those functions that accept values


and after performing the required operation, return numeric values. Some useful numeric
functions are

ABSReturns the absolute value of data. The syntax of the ABS command is
ABS( DATA )

For example
CEIL Returns the smallest integer greater than or equal to data. The syntax of the ceil
command is

CEIL( DATA )

For example

FLOORReturns the largest integer greater than or equal to data. The syntax of the
floor command is
FLOOR ( DATA )

For example

LN Returns the natural logarithm of data. The syntax of the LN command is

LN ( DATA )

For example
LOG Returns the logarithm of the data to the base B. The syntax of the LOG
command is

LOG ( B,DATA )

For example

MOD This functions returns modulus(i.e., remainder) of given two numbers. Returns
remainder of argument m divided by argument n. Returns x m if n is 0 i.e., if
denominator is o. The syntax of the MOD command is
MOD(m,n)

For example

POWER This function returns m raise to nth power. Returns value of argument m
raised to nth power. The base m and the exponent n can be any numbers, but if m is
negative, n must be an integer. The syntax of the POWER command is
POWER(m,n)
For example

ROUND This function returns a number rounded off as per given specifications.
Returns value of argument n rounded to m places right of the decimal point; if m is
omitted to 0 place,m can be negative to round off digits left of the decimal point. M must
be an integer. The syntax of the ROUND command is
ROUND(n,m)

For example

SQRT This function returns the square root of the given number. Returns square root
of argument n. The value n cannot be negative. SQRT returns a “real” result. The syntax
of the SQRT command is
SQRT(n)

For example
TRUNC This function returns a number with some digits truncated. Returns value of
argument n truncated to argument m decimal places. If argument m is omitted to 0 places,
m can be negative to truncate (i.e., make zero) m digits left of the decimal point. The
syntax of the TRUNC command is
TRUNC(m,n)

For example

AGGREGATE FUNCTIONS The summary values are calculated from the data in a
particular column using SQL’s aggregate functions. Aggregate functions can be applied
to all rows in a table or to a subset of the table specified by a WHERE clause. These
functions are statistical functions. They are used to compute a single value from a set of
attribute values of a column. It is used to provide summarization information for a SQL
statement, such as totals, averages etc. Some aggregate functions are

COUNT() Used to count rows or values of a column that do not contain a NULL
value. The syntax of the COUNT command is
COUNT(X)

For example to count the number of cities, the different members belong to, we use the
following command

COUNT(*) Used to count all the rows of a table including duplicates. The syntax of
the count(*) command is
COUNT(*)

For example to count the number of students in particular trades from sturept table, we
will use the following command
SUM( ) Used to return a total or sum on the values of a numeric column for a group of
rows. The syntax of the SUM command is
SUM (X)

For example

AVG( ) Used to find averages for a group of rows. The syntax of the AVG command
is
AVG (X)

For example

MAX( ) Used to return the maximum value for the values of a column in a group of
rows. The syntax of the MAX command is
MAX (X)
For example

MIN( ) Used to return the minimum value for the values of a column in a group of
rows. The syntax of the MIN command is
MIN (X)

For example.

VARIANCE Used to compute the variance of values in columns. The syntax of the
variance command is
VARIANCE (X)

For example

STDDEV Used to find the standard deviation. The syntax of the STDDEV command
is
STDDEV (X)

For example
DATE FUNCTIONS
Date functions operate on values of the DATE data type. All function return a value of
DATE data type, except the MONTHS_BETWEEN function, which returns a number.

ADD_MONTHSThis function adds number of months to a given date and returns a


date after those many months.
Returns the value of argument date d plus n months. The argument n can be any integer.
If the last day of the resulting month. Otherwise, the result has the same day component
as d. The syntax of the ADD_MONTHS command is
ADD_MONTHS(d,n)

For example

LAST_DAYThis function gives last day of the month specified in date.The syntax of
the last_day command is
LAST_DAY(d)

For example
NEXT_DAYThis function returns the date of a specified coming day in the next week.
Returns the date of the first weekday named by argument char that is later than the date
d.the argument char must be a day of the week. The return value has the same hours,
minutes, and seconds component as the argument d. The syntax of the NEXT_DAY
command is
NEXT_DAY(d,char)

For example

MONTHS_BETWEENThis function finds out the number of months passed between


given two dates. The syntax of the MONTHS_BETWEEN command is
MONTHS_BETWEEN(date2,date1)

For example

Вам также может понравиться