Tuesday, 31 May 2016

How to DELETE multiple rows in Oracle?

We can DELETE multiple rows in Oracle by using the rowid.

Steps1:Lets Create a Table named DELETE_MULTIPLE 

CREATE TABLE DELETE_MULTIPLE
(
  EMP_ID NUMBER NOT NULL
, EMP_NAME VARCHAR2(20 BYTE)
, SALARY NUMBER

);

Table DELETE_MULTIPLE created.

Step2:Insert data into table DELETE_MULTIPLE (insert duplicate values too)

insert into DELETE_MULTIPLE values(1311,'John',25411);
insert into DELETE_MULTIPLE values(1313,'Perk',46456);
insert into DELETE_MULTIPLE values(1315,'Adam',46654);
insert into DELETE_MULTIPLE values(1317,'Gill',45454);
insert into DELETE_MULTIPLE values(1311,'John',25411);
insert into DELETE_MULTIPLE values(1313,'Perk',46456);
insert into DELETE_MULTIPLE values(1315,'Adam',46654);

insert into DELETE_MULTIPLE values(1317,'Gill',45454);

Here is the DELETE_MULTIPLE Table data.



Step3:Now query to delete the multiple rows.

delete from delete_multiple where rowid not in (select max(rowid) from delete_multiple group by emp_id);

4 rows deleted(there was 4 duplicate rows.)

Now give a try,And if you like this post please do share and like.

How to find Nth Highest Salary?





Monday, 14 March 2016

How to solve IO ERROR:THE NETWORK ADAPTER COULD NOT ESTABLISH THE CONNECTION?

Go to Start in your computer, type services

Go to services[select standard among Extended and standard] and start[right click on service and click start]
1.Oracle ORCL VSS writer Service
2.OracleDBConsole
3.OracleMTSRecovery Service
4.OracleOraDb11g_Home1ClrAgent
5.OracleOraDb11g_Home1TNSListener
6.OracleServiceORCL

Now connect the connection in Oracle SQL Developer by using username and password.
Eg:Username:hr
Password:hr

Saturday, 2 January 2016

Functions in Oracle

Example of Functions

--concat
select concat(concat('Adams','martin'),' Rodrick') from dual;
Ans->Adamsmartin Rodrick
--initcap
select INITCAP('adams martin rodrick') from dual;
Ans->Adams Martin Rodrick
--LOWER
select LOWER('LOWER CASE EXAMPLE') from dual;
Ans->lower case example
--upper
select UPPER('upper case example') from dual;
Ans->UPPER CASE EXAMPLE
--UCASE
select UCASE('upper case example') from dual;
Ans->UPPER CASE EXAMPLE
--LPAD
select first_name,LPAD(SALARY,length(salary)+1,'$')from EMPLOYEES
Ans->Steven $24000
--LTRIM
select LTRIM('xyxYyXz WORD','xy') from dual;
Ans->YyXz WORD
--replace
select replace('lets learn','learn','earn') from dual;
Ans->lets earn
--RPAD
select RPAD('PASSION',12,'x') from dual
Ans->PASSIONxxxxx
--LPAD
select LPAD('Rodrick',15,'Mr ') from dual;
Ans->Mr Mr MrRodrick
--trim
select trim(' Rodrick ') from dual;
Ans->Rodrick