0% found this document useful (0 votes)
9 views

DBMS15

Uploaded by

sudhanshuraj2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

DBMS15

Uploaded by

sudhanshuraj2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

PRACTICAL 15:

AIM: Query Using Column Functions.

Column Function:
A column function in SQL refers to operations or functions applied to entire columns to
summarize or transform their values.
1. Arithmetic Operations: These are mathematical operations performed on numeric
data, often applied directly on numeric columns or constants in SQL queries.
Arithmetic operations allow you to compute results like totals, differences, and
averages.

Common Arithmetic Operators:


• SQRT() : Returns the square root of a non-negative number.
• ABS() : Returns the absolute value of a numeric expression,removing any
negative sign.
• ROUND() : Rounds a numeric value to the specified number of decimal
places.
• FLOOR(): Rounds a number down to the nearest integer.
• TRUNC() : Truncates a numeric value to a specified number of decimal places
without rounding.
• SIGN() : Returns the sign of a number.
• MOD() : Returns the remainder of a division operation (modulus).
• CEIL(): Rounds a number up to the nearest integer.
• POWER() : Raises a number to the power of another number.

2. Character Operations: Character (or string) operations in SQL allow you to


manipulate and format string data.

• LENGTH(): Returns length of a string.


• SUBSTRING(): Extracts part of a string.
• UPPER(): Converts string to uppercase.
• LOWER(): Converts string to lowercase.
• TRIM(): Removes leading/trailing spaces.
• POSITION(): Finds position of substring
• REPLACE(): Replaces substring with another.
• LIKE : Pattern matching.
• SOUNDEX(): The SOUNDEX() function generates a four-character code based on
how a word sounds.
EXAMPLES:
Absolute Value:
SELECT ABS(-5.5) FROM DUAL;
SELECT ABS(5.5) FROM DUAL;

Ceiling Value:
SELECT CEIL(5.4) FROM DUAL;
SELECT CEIL(-5.4) FROM DUAL;
Floor Value :
SELECT FLOOR(5.4) FROM DUAL;
SELECT FLOOR(-5.4) FROM DUAL;

Modulus:
SELECT MOD(5, 3) FROM DUAL;
Power:
SELECT POWER(2, 4) FROM DUAL;

Sign function:
SELECT SIGN(-5) FROM DUAL;
SELECT SIGN(0) FROM DUAL;
SELECT SIGN(5) FROM DUAL;
Square Root:
SELECT SQRT(25) FROM DUAL;

Truncate:
SELECT TRUNC(3.567, 2) FROM DUAL;
Rounding:
SELECT ROUND(3.567, 2) FROM DUAL;
SELECT ROUND(3.565, 2) FROM DUAL;
SELECT ROUND(3.563, 2) FROM DUAL;

Example of Character Operations:

SELECT INITCAP(DNAME) FROM DEPT;


SELECT LOWER(DNAME) FROM DEPT;

SELECT UPPER('hello') FROM DUAL;

SELECT LPAD(DNAME,11,'*') FROM DEPT;


SELECT RPAD(DNAME,11,'*') FROM DEPT;

SELECT ' HELLO' AS HELLO FROM DUAL;


SELECT LTRIM(' HELLO') AS HELLO FROM DUAL;
SELECT 'HELLO ' AS HELLO FROM DUAL;
SELECT RTRIM('HELLO ') AS HELLO FROM DUAL;

SELECT SUBSTR('HELLO',4,2) FROM DUAL;


SELECT SUBSTR('HELLO',2,4) FROM DUAL;

SELECT LENGTH('HELLO') FROM DUAL;

SELECT INSTR('HELLO','LO') FROM DUAL;


SELECT INSTR('HELLO','GO') FROM DUAL;

You might also like