0% found this document useful (0 votes)
24 views6 pages

DB 4

The document provides an overview of various SQL string and date functions, including examples and their outputs. It covers functions such as concatenation, padding, trimming, case conversion, substring extraction, and date manipulation. Each function is demonstrated with a SQL query and the expected output, showcasing their utility in SQL operations.

Uploaded by

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

DB 4

The document provides an overview of various SQL string and date functions, including examples and their outputs. It covers functions such as concatenation, padding, trimming, case conversion, substring extraction, and date manipulation. Each function is demonstrated with a SQL query and the expected output, showcasing their utility in SQL operations.

Uploaded by

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

String Functions

 Concatenation (||):

sql

Copy

SELECT 'Hello' || ' ' || 'World' FROM dual;

Output:

nginx

Copy

Hello World

 LPAD('123', 5, '0'):

sql

Copy

SELECT LPAD('123', 5, '0') FROM dual;

Output:

Copy

00123

 RPAD('123', 5, '0'):

sql

Copy

SELECT RPAD('123', 5, '0') FROM dual;

Output:

Copy

12300

 LTRIM(' Hello'):

sql
Copy

SELECT LTRIM(' Hello') FROM dual;

Output:

nginx

Copy

Hello

 RTRIM('Hello '):

sql

Copy

SELECT RTRIM('Hello ') FROM dual;

Output:

nginx

Copy

Hello

 LOWER('HELLO'):

sql

Copy

SELECT LOWER('HELLO') FROM dual;

Output:

nginx

Copy

hello

 UPPER('hello'):

sql

Copy
SELECT UPPER('hello') FROM dual;

Output:

nginx

Copy

HELLO

 INITCAP('hello world'):

sql

Copy

SELECT INITCAP('hello world') FROM dual;

Output:

nginx

Copy

Hello World

 LENGTH('Hello'):

sql

Copy

SELECT LENGTH('Hello') FROM dual;

Output:

Copy

 SUBSTR('Hello World', 1, 5):

sql

Copy

SELECT SUBSTR('Hello World', 1, 5) FROM dual;

Output:
nginx

Copy

Hello

 INSTR('Hello World', 'World'):

sql

Copy

SELECT INSTR('Hello World', 'World') FROM dual;

Output:

Copy

3. Date Functions

 SYSDATE:

sql

Copy

SELECT SYSDATE FROM dual;

Output (example, based on the current date and time):

Copy

06-MAR-25 10:45:23

 NEXT_DAY(SYSDATE, 'MONDAY'):

sql

Copy

SELECT NEXT_DAY(SYSDATE, 'MONDAY') FROM dual;

Output (if today is Wednesday, the output will be the date of the next Monday):

Copy

10-MAR-25
 ADD_MONTHS(SYSDATE, 2):

sql

Copy

SELECT ADD_MONTHS(SYSDATE, 2) FROM dual;

Output:

Copy

06-MAY-25

 LAST_DAY(SYSDATE):

sql

Copy

SELECT LAST_DAY(SYSDATE) FROM dual;

Output:

Copy

31-MAR-25

 MONTHS_BETWEEN(SYSDATE, TO_DATE('2024-01-01', 'YYYY-MM-DD')):

sql

Copy

SELECT MONTHS_BETWEEN(SYSDATE, TO_DATE('2024-01-01', 'YYYY-MM-DD')) FROM dual;

Output (based on current date of March 2025):

Copy

14.0

 LEAST(10, 20, 30):

sql

Copy

SELECT LEAST(10, 20, 30) FROM dual;


Output:

Copy

10

 GREATEST(10, 20, 30):

sql

Copy

SELECT GREATEST(10, 20, 30) FROM dual;

Output:

Copy

30

 TRUNC(SYSDATE, 'MM'):

sql

Copy

SELECT TRUNC(SYSDATE, 'MM') FROM dual;

Output:

Copy

01-MAR-25

 ROUND(SYSDATE, 'YYYY'):

sql

Copy

SELECT ROUND(SYSDATE, 'YYYY') FROM dual;

Output:

Copy

You might also like