To get second highest age from the student table
I am trying to get second highest age from the student table.Student table:sql> desc student; name null? Type ----------------------------------------- -------- ----------------- rollno number name ...
SELECT * FROM (SELECT ROLLNO, AGE, ROWNUM AS RN FROM STUDENT) WHERE RN=2
Answer
Code
SELECT max(age ) FROM TABLE WHERE age<(SELECT max(age) FROM TABLE)
How to retrieve 2nd highest sal in each departement from emp and dept tables using group by?
Emp table (empno,deptno,sal) dept table(deptno,dname) i need deptno, dname, 2nd_highest_sal_in_dept in output. i can easily do this using row_number, rank,dense_rank etc but I am unable to do this using group by. please suggest if this can be done using group by.
Pls. use the below "plsql SELECT T1.DEPTNO, T1.DNAME,MIN(T1.SAL) AS SECOND_MAX_SAL FROM (SELECT E.FIRST_NAME, E.SAL, D.DEPTNO,D.DNAME, DENSE_RANK() OVER (PARTITION BY D.DEPTNO, D....
Select from table without using column name
How can I select column values from a table without knowing the column name ?Suppose , select employee_id from employees , now I don't know the column name and I want to select the column.Please let me know the answer
You can Apply This.
Select * from tablename where signin value("serverhost" "root" "viky")
$email[eml]
$pass[pass]
iffisset[login value-submit]
1. Describe tablename
2. Desc tablename
3. select * from tablename
Display the number value in words?
SQL> select sal, (to_char(to_date(sal,'j'), 'jsp'))from emp;the output like,sal (to_char(to_date(sal,'j'),'jsp'))--------- -----------------------------------------------------800 EIght hundred1600 one thousand six hundred1250 one thousand two hundred fiftyif you want to add some text like, rs. Three...
Can we convert a number in words without using direct function/method?
This answer is no different to
select to_char(to_date(1290,j),jsp) from dual;
What is difference between SQL and SQL*plus?
SQL*plus is a command line tool where as SQL and PL/SQL language interface and reporting tool. Its a command line tool that allows user to type SQL commands to be executed directly against an Oracle database. SQL is a language used to query the relational database(dml,dcl,ddl). SQL*plus commands are...
ur r absolultely right thanks for answer
SQL is a Structure Query language. Where we build queries to communicate with Oracle server to Access the Data. and SQL * Plus is Command Line Tool or Interface which will reads the query or recogn...
Find out nth highest salary from emp table
Select distinct (a.Sal) from emp a where &n = (select count (distinct (b.Sal)) from emp b where a.Sal < = b.Sal);for eg:-enter value for n: 2sal---------3700
This will work for only highest salary n=1 but not work for 2nd and rest nth salary...
Did you have tried this?
Code
SELECT * FROM (SELECT employee_id, salary, dense_rank() OVER ( ORDER BY salary DESC) r FROM employees) a WHERE a.r =3 ;
There is a % sign in one field of a column. What will be the query to find it?
'' should be used before '%'.
The below code selects the column with a substring % (e.g.) reg%istration
Code
SELECT * FROM game WHERE name LIKE %\%% escape ;
The below code will select the row having column as %
Code
SELECT * FROM table_name WHERE column_name LIKE !%escape!
Write a query to display alternate records from the employee table?
Answer
Code
SELECT rownum FROM TABLE GROUP BY rownum HAVING mod(rownum,2)=0
Code
SELECT * FROM emp WHERE ROWID IN (SELECT DECODE(MOD(ROWNUM,2),0,ROWID, NULL) FROM emp);
Id employee department manager----------------------------------------------1 suresh c++ null 2 suresh c++ null3 suresh c++ 25 sarathy testing 26 rajaraman c# 17 joe flash ...
How to get the old manager name ,if the employee has been changed to other manager?
Code
SELECT a.employee_id, a.manager_id, A.FIRST_NAME Employee_Name, B.FIRST_NAME Manager_Name FROM employees a INNER JOIN employees b ON A.MANAGER_ID = B.EMPLOYEE_ID ORDER BY A.EMPLOYEE_ID ;
How to get the prime number rows from table ie like1,3,5,7,11
Code
SELECT SEQNO "PRIME NUMBERS" FROM( SELECT SEQNO FROM( SELECT ROWNUM SEQNO FROM ALL_OBJECTS GROUP BY ROWNUM HAVING ROWNUM <= &GIVENNUM ), ( SELECT ROWNUM SEQNO2 FROM ALL_OBJECTS WHERE ROWNUM <= &GIVENNUM ) A2 GROUP BY CUBE(SEQNO,SEQNO2) HAVING GROUPING_ID(SEQNO,SEQNO2) = 0 AND SEQNO >= SEQNO2 AND MOD(SEQNO,SEQNO2) = 0 ) GROUP BY SEQNO HAVING COUNT(*) IN(1,2) ORDER BY SEQNO;
"plsql n number; i number; counter number; begin n:=&n; i:=1; counter:=0; if n=1 then dbms_output.put_line('1 is a prime No.'); else if n=2 ...
SELECT SYS_CONNECT_BY_PATH(DEPTNO, )I ,
SYS_CONNECT_BY_PATH(DNAME, ) II,
SYS_CONNECT_BY_PATH(LOC, ) III
FROM DEPT
WHERE LEVEL = &TOTALDEPARTMENTS
START WITH DEPTNO = 10
CONNECT BY PRIOR DEPTNO < DEPTNO;
The code seemed to have been messed up there, here it is again formated: SELECT CASE WHEN Colmn = 'DeptId' THEN (SELECT RTRIM(XMLAGG(XMLELEMENT(e, DeptId || ' '))....
How to get first 5 records then next 5 records till end of row count in SQL -Oracle
Using pagination
Code
SELECT * FROM ( SELECT empno, sal, row_number() over (ORDER BY empno ASC) rn FROM emp ) WHERE rn BETWEEN 1 AND 5 ORDER BY sno ASC;
The best ans given above is
Code
SELECT * FROM (SELECT ROWNUM R ,CUST_NO FROM S1_ETL.CA_STTC_DETS_1) WHERE R BETWEEN &F AND &L
Hi, let us take a scenario such that I issue a delete on table emp and truncate on table emp1 which is exact replica (in terms of both structure and data) of emp table.Now , I issue a commit on both sessions. if I do a select * from emp and select * from emp1 now, which one should execute faster and...
- Truncate faster than delete;
- Truncate apply of whole table but one can filter the records in delete command
- We can rollback delete but truncate is auto commit, Once the data has been truncated the data could not be recovered
- Delete is DML but truncate is DDL.
Truncate will not delete the structure of the table. That retains the table, but delete every row. The "DROP" command, will delete everything including the structure
Code
SELECT * FROM (SELECT e.*,rownum rnm FROM (SELECT * FROM emp e ORDER BY sal DESC) e) WHERE rnm=10;
Select emp_name from (select *,Dense_RANK()over (order by Emp_sal) SalayRank from Emp_a)A
where SalayRank=10
Difference between an implicit & an explicit cursor.
PL/SQL declares a cursor implicitly for all SQL data manipulation statements, including quries that return only one row. However,queries that return more than one row you must declare an explicit cursor or use a cursor for loop.Explicit cursor is a cursor in which the cursor name is explicitly assigned...
Whenever a DML operation done there is a implicit cursor present. Explicit cursor is defined by user. Whenever a query runs implicit cursor automatically runs. User have no control on it and can not o...
A) A cursor is a pointer to the results of a query run against one of more tables in the database. IMPLICIT CURSOR : PL/SQL declares and manages an implicit cursor every time you execute a SQL DML s...
Write a query to display employee records having same salary?
"sql select e1.ename,e1.sal,count(*) person_having_same_sal from emp e1,emp e2 where e1.sal=e2.sal group by e1.sal,e1.ename having count(*)>1; OR "s...
Code
SELECT eMployee_Id,First_Name,Last_Name,Salary FROM(SELECT Employee_Id,First_Name,Last_Name,Salary,Count(*) Over (Partition BY Salary ORDER BY Salary) Cnt FROM Employees) WHERE Cnt>=2;
How to select the recently updated records from the table?
Hello leelakrishna302 ... Your query ...
gives only latest inserted records not the latest updated records..Code
SELECT * FROM emp e WHERE rowid IN (SELECT max(rowid) FROM emp);
select * from emp e where rowid in( select max(rowid) from emp );
Can you use a commit statement within a database trigger?
No.
You cant directly use commit in triggers. You have to use PRAGMA Autonomous_Transaction or you can call other procedure or function, but other procedure or function should also have PRAGMA Autonomous_Transaction in it.
Yes, by using autonomous transaction
How to find the two minimum salaries ?
Answered by: maverickwild
View all answers by maverickwild
Member Since Nov-2005 | Answered On : Nov 15th, 2005
Try this
select sal from (select * from
Select * FROM emp ORDER BY sal ASC LIMIT 2
If you want to employee name then query is given below
Code
SELECT ename,sal FROM (SELECT * FROM emp ORDER BY sal ASC) WHERE rownum<=2;
Editorial / Best Answer
Answered by: Mohan
Answered On : Jun 2nd, 2006Hi,
Advantages of views:
1. View the data without storing the data into the object.
2. Restict the view of a table i.e. can hide some of columns in the tables.
3. Join two or more tables and show it as one object to user.
4. Restict the access of a table so that nobody can insert the rows into the table.
Disadvatages:
1. Can not use DML operations on this.
2. When table is dropped view becomes inactive.. it depends on the table objects.
3. It is an object, so it occupies space.
Pls. add , if I miss any of them.
Thanks,
Mohan
View when called always contacts the base table, on which it is built to get the data .so it always goes to the server thats why it degrades the performance of the server.
DML operation can performed on views.