Professional Documents
Culture Documents
select tes123.name,tes123.price from (select name,sum(price) as price from test group by name )
tes123
where 1= (select count(distinct(t2.price)) from (select name,sum(price) as price from test group by
name) t2 where tes123.price>t2.price);
select * from
select name, price,dense_rank() over (partition by name order by price) rnk from test)
delete from test where rowid not in (select max(rowid) from test group by name)
update test set price=1000 where name in (select name from test group by name having count(name) >
1)
select * from (select * from test order by name desc) where rownum<=5
the EMP_SRC table will be dropped from the db and It will be available in recycle bin
Error:
Error starting at line : 1 in command -
empno NUMBER(4),
ename VARCHAR2(10),
job VARCHAR2(9),
mgr NUMBER(4),
hiredate DATE,
sal NUMBER(4),
comm NUMBER(4),
deptno NUMBER(4)
Error report -
*Cause: identifiers may not start with any ASCII character other than
letters and numbers. $#_ are also allowed after the first
Reference Manual.
*Action:
Regular Expression
REGEXP_LIKE
REGEXP_REPLACE
REGEXP_SUBSTR
REGEXP_INSTR
1.REGEXP_LIKE
REGEXP_LIKE condition allows you to perform regular expression matching in the
WHERE clause of a SELECT, INSERT, UPDATE, or DELETE statement.
Syntax
SELECT last_name
FROM contacts
SELECT last_name
FROM contacts
SELECT last_name
FROM contacts
REGEXP_REPLACE
REGEXP_SUBSTR
REGEXP_INSTR
select name from EMP_MNG where emp_id in( select mng_id from EMP_MNG where
emp_id=2)
select name,mng_id from emp_mng e1 where emp_id in ( select mng_id from emp_mng
e2 where e2.mng_id=e1.emp_id)
select * from
(select empno,ename,sal,deptno,dense_rank() over(partition by deptno order by sal
desc) rnk from EMP_12282017) where rnk=2
select * from (select * from emp order by rownum desc) where rownum<=2
select * from
(select emp_id,dept_id,dense_rank() over(partition by dept_id order by sal desc) rk from
emp1) a
join LOCATION on a.dept_id=LOCATION.dept_id where a.rk=2
select
substr(substr(eaddr,instr(eaddr,'@',1)+1),instr(substr(eaddr,instr(eaddr,'@',1)+1),'.',1,2)+1) from
table1
where instr(substr(eaddr,instr(eaddr,'@',1)+1),'.',1,2) > 0
Merge
when you want to do an "upsert" i.e. update existing rows in a table or insert new rows
depending on a match condition. This is typically the case when you have to synchronize a table
periodically with data from another source (table/view/query). In place of 3 separate unwieldy INSERT,
UPDATE and DELETE statements with conditional sub-queries, the all-in-one MERGE does the job in one
shot
Syntax
MERGE into <target table>
USING
<souce table/view/result of subquery>
ON
<match condition>
WHEN MATCHED THEN
<update clause>
<delete clause>
WHEN NOT MATCHED THEN
<insert clause>
Example
SQL> merge into student a
2 using
3 (select id, name, score
4 from student_n) b
5 on (a.id = b.id)
6 when matched then
7 update set a.name = b.name
8 , a.score = b.score
9 when not matched then
10 insert (a.id, a.name, a.score)
11 values (b.id, b.name, b.score);
To get random values from table(It should print different result whenever
we run select query)