You are on page 1of 4

1

Q. How to validate the email address using regular expression.

Table : Employee(Empno, Email)

101 manu29809@gmail@com

102 pankajdhaka@dav@hotmail.com

103 pranav165@yahoo.co.in

104 meetshrotriya@gmail.comcom

105 arya.anit3@gmail.com

Write query to validate the email address using regular expression.

In the above example, empno 103 and 105 is having valid email address

and rest email address are invalid.

Ans. SELECT empno, email

FROM Employee

WHERE email LIKE '%.com', '%.co.in' ;

Q. How to send mail from oracle 10g ?

Ans. Utl_smtp package


Utl_mail or utl_html package: utl_http

Q. Trouble inserting rows into a table. 164k rows are to be inserted, usually I can successfully insert single row.

What can be the reasons? One of my hunch is that indexes are causing the trouble.

Ans. 1. Disable the index

2. Use append hint along with insert statement if you are running single sql statement.

Or we can use BULK COLLECT WITH COLLECTION.

And if that is non prod db then you can use nologging hint too.

Q. How to retrieve whole column data in single row,that data can be separated with semicolon(;) ?

Ans. Select listagg(ename, ',') within group (order by ename) from emp;

- Use Listagg and wm_concat

The following single-set aggregate example lists all of the employees in Department 30 in the hr.employees table,
ordered by hire date and last name:

- SELECT LISTAGG(last_name, '; ')


- WITHIN GROUP (ORDER BY hire_date, last_name) "Emp_list",
- MIN(hire_date) "Earliest"
- FROM employees
- WHERE department_id = 30;
-
- Emp_list Earliest
- ------------------------------------------------------------ ---------
- Raphaely; Khoo; Tobias; Baida; Himuro; Colmenares 07-DEC-02
2

Q. How to find size of a table in Oracle and how can we know which table have occupied more space in the DB?

Ans. If we need by number of rows, use user_tables or user_objects,

If you need by size in bytes then use user_segments.

Ex.1- Select segment_name,

sum(bytes) size

from dba_segments

where upper(owner)=upper('<tablename>')

group by segment_name

order by 2 desc;

Ex.2- Select * from user_segments order by size desc;

Q. How can we return data which is contain "Yellow", without using OR operator from the below table?

Ans. Query 1: select * from table where sno||colur1||colur2||colur3 like '%Yellow%';

Query 2: Select * from table where 'Yellow' in (colur1, colur2, color3);

Query 3:

CREATE TABLE colors AS


SELECT 1 sno, 'Blue' color1, 'Yellow' color2, 'Orange' color3
FROM dual
UNION ALL
SELECT 2 sno, 'Yellow' color1, 'Black' color2, 'White' color3
FROM dual
UNION ALL
SELECT 3 sno, 'Red' color1, 'Purple' color2, 'Pink' color3
FROM dual;

WITH x AS (
SELECT sno, col_num, col_name
FROM colors
UNPIVOT (col_name for col_num in (color1 AS 1, color2 as 2, color3 AS 3))
)
SELECT sno, color1, color2, color3
FROM x JOIN colors USING (sno)
WHERE col_name='Yellow';

Q. How to get particular column in multiple tables?

Ans. Select * from dba_tab_columns where column_name='Your column name'

Same like User_tab_colums or All_tab_columns;


3

Those are very helpful docs in terms of performance tuning concept, Will give more details on how to understand explain plan
table .

links...

https://docs.oracle.com/cd/A58617_01/server.804/a58246/intro.htm

https://docs.oracle.com/cd/E11882_01/server.112/e41573/perf_overview.htm#PFGRF025

https://docs.oracle.com/cd/E11882_01/server.112/e41573/toc.htm

Pls find below links...

https://docs.oracle.com/.../server.804/a58246/intro.htm

https://docs.oracle.com/.../e41573/perf_overview.htm...

https://docs.oracle.com/.../E11.../server.112/e41573/toc.htm

SQL to generate a list of numbers from 1 to 100 ?


Q. Using the DUAL table, how can I get a list of numbers from 1 to 100?

A. Select Rownum r

From dual

Connect By Rownum <= 100;

SELECT LEVEL n

FROM DUAL

CONNECT BY LEVEL <= 100;

SELECT V

FROM DUAL

MODEL DIMENSION BY (0 R)

MEASURES (0 V)

RULES ITERATE (100) (

V[ITERATION_NUMBER] = ITERATION_NUMBER + 1

ORDER BY 1;

with bnd as (select 1 lo, 101 hi from dual)

select (select lo from bnd) - 1 + level r

from dual
4

connect by level <= (select hi-lo from bnd);

SELECT rownum

FROM XMLTABLE('1 to 100');

You might also like