Академический Документы
Профессиональный Документы
Культура Документы
select max(field1) from tname1 where field1=(select max(field1) from tname1 where field1<(select max(field1) from tname1);
select min(column) from (select column from table order by column desc) where rownum <=2
select max(field1) from table_name where field1 < (select max(field1) from table_name)
select min(int_salary) from Tbl_Test_Salary where int_salary in (select top 10 int_Salary from Tbl_Test_Salary order by
int_salary desc)
union will return the distinct rows in two select s, while union all return all rows
Union will filter duplicate values where as union all will not filter duplicate values
A materialized view is a database object that contains the results of a query. They are local copies of data located remotely or
used to create summary tables based on aggregation of a tables data. Materialized views which store data based on the remote
tables are also know as snapshots.
Triggers are fired implicitly on the tables/views on which they are created. There are various advantages of using a trigger.
Some of them are:
- Suppose we need to validate a DML statement(insert/Update/Delete) that modifies a table then we can write a trigger on the
table that gets fired implicitly whenever DML statement is executed on that table.
- Another reason of using triggers can be for automatic updation of one or more tables whenever a DML/DDL statement is
executed for the table on which the trigger is created.
- Triggers can be used to enforce constraints. For eg : Any insert/update/ Delete statements should not be allowed on a
particular table after office hours. For enforcing this constraint Triggers should be used.
- Triggers can be used to publish information about database events to subscribers. Database event can be a system event like
Database startup or shutdown or it can be a user even like User loggin in or user logoff.
A materialized view is a replica of a target master from a singlepoint in time. The concept was first introduced with Oracle7
termed asSNAPSHOT. In Oracle release 7.1.6 snapshots were enhanced to enableDMLs along with a new terminology,
updatable snapshots. With Oracle8.1.6 snapshots started to be used in data warehouse environments so anew terminology
materialized view was introduced to address bothdistributed and data warehouse materialized views.
The union is a structure.The main difference between structure and union isThe size of the union is equal to the size of the
largest member of the union where as size of the structrue is the sum of the size of al members of the structure.And one more
thing is that we can use one member of the union at a time.
Indeed both equi join and the Union are very different. Equi join is used to establish a condition between two tables to select
data from them.. eg
This is the example of equijoin whereas with a Union allows you to select the similar data based on different conditions eg
select a.employeeid, a.employeename from employeemaster a where a.employeeid >100 b.employeeid
Union
the above is the example of Union where in we select employee name and Id for two different conditions into the same recordset
and is used thereafter.
but for union no need to have any relation between the two tables
but equijoin & union are used with more than one table
UNION - the values of the first query are returned with the values of the second query eliminating duplicates.
MINUS - the values of the first query are returned with duplicates values of the second query removed from the first query.
UNION ALL - the values of both queries are returned including all duplicates
INTERSECT - only the duplicate values are returned from both queries.
select count(1) from (select ename from emp union select ename from emp e1) returns 14
But
select count(1) from (select ename from emp union All select ename from emp e1)
returns 28.
1.RDBMS=DBMS+Refrential Integrity
DBMS does not support client/server Architecture but RDBMS supports client/server Architecture.
2.IN check returns values to main query where as EXISTS returns Boolean (T or F).
IN check for all the values and where as EXISTS looks for values one by one and it exists when it found the value....
how can i hide a particular table name of our schema
Oracle has Schema triggers (CREATE OR REPLACE TRIGGER ... ON SCHEMA ... that will file on DDL commands. You can do
things like
The difference is that, Clustered index is unique for any given table and we can have only one clustered index on a table. The
leaf level of a clustered index is the actual data and the data is resorted in case of clustered index, whereas in case of non-
clustered index the leaf level is actually a pointer to the data in rows so we can have 249 non-clustered indexes on a table.
Clustered Index:- A Clustered index is a special type of index that reorders the way records in the table are physically stored.
Therefore table may have only one clustered index.Non-Clustered Index:- A Non-Clustered index is a special type of index in
which the logical order of the index does not match the physical stored order of the rows in the disk. The leaf nodes of a non-
clustered index does not consists of the data pages. instead the leaf node contains index rows.
How to write a sql statement to find the first occurrence of a non zero value?
select a from t where nvl(a,0)<> 0 and rownum < 2 where a is col name and t is the table name
select col from tabname where rowid =(select min(rowid) from tabname where col is not null)here col is column name and
tabname is table name.
Why do I get "Invalid Cursor State" errors when I insert/update/delete data with executeQuery()?
IF u get this error, then there is a problem with the Java program, U may open the cursor with the Readonly mode.Change the
Resultset type then you will get it.This is not problem with the Oracle
varchar means fixed length character data(size) ie., min size-1 and max-2000
where as varchar2 means variable length character data ie., min-1 to max-4000
Emp_name varchar(10) - if you enter value less than 10 then remaining space can not be deleted. it used total 10 spaces.
Emp_name varchar2(10) - if you enter value less than 10 then remaining space is automatically deleted
There are 5 normal forms. It is necessary for any database to be in the third normal form to maintain referential integrity and
non-redundance.
First Normal Form: Every field of a table (row,col) must contain an atomic value
Second Normal Form: All columns of a table must depend entirely on the primary key column.
Third Normal Form: All columns of a table must depend on all columns of a composite primary key.
Fourth Normal Form: A table must not contain two or more independent multi-valued facts. This normal form is often avoided for
maintenance reasons.
Fifth Normal Form: is about symmetric dependencies.
There are 2 tables, Employee and Department. There are few records in employee table, for which, the department is
not assigned. The output of the query should contain all th employees names and their corresponding departments, if
the department is assigned otherwise employee names and null value in the place department name. What is the
query?
Refereence cursor is dynamic cursor used with SQL statement like For select* from emp;
There is a eno & gender in a table. Eno has primary key and gender has a check constraints for the values 'M' and 'F'.
While inserting the data into the table M was misspelled as F and F as M.What is the update statement to replace F with
M and M with F?
COMMIT;
update <TableName> set gender= case where gender='F' Then 'M' where gender='M' Then 'F'
what is diffrence between Co-related sub query and nested sub query??
Co-related sub query is one in which inner query is evaluated only once and from that result outer query is evaluated.
Nested query is one in which Inner query is evaluated for multiple times for gatting one row of that outer query.
Nested subquery runs only once for the entire nesting (outer) query. It does not contain any reference to the outer query row.
For example,
Correlated Subquery:
select e1.empname, e1.basicsal, e1.deptno from emp e1 where e1.basicsal = (select max(basicsal) from emp e2 where
e2.deptno = e1.deptno)
Nested Subquery:
select empname, basicsal, deptno from emp where (deptno, basicsal) in (select deptno, max(basicsal) from emp group by
deptno)
Data Base is divided into 2 or more logical structure known as table space. Each table space one or more physical data file in
the hard disk.
How to find out the database name from SQL*PLUS command prompt?
SELECT INSTANCE_NAME from V$INSTANCE;
We need to call the stored procedure explictily where as triggers fires when ever an event occurs.
eg
to scott/tiger@ORCL92-
create new_emp –
I have a table with duplicate names in it. Write me a query which returns only duplicate rows with number of times they
are repeated.
Which function is used to find the largest integer less than or equal to a specific value
Floor