Sign Up to our social questions and Answers to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers to ask questions, answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This category lists all questions related to Oracle SQL database
what is the difference between “INNER JOIN” and “OUTER JOIN”?
Hi there,i found some answer you will understand it so easy.Assuming you're joining on columns with no duplicates, which is a very common case:An inner join of A and B gives the result of A intersect B, i.e. the inner part of a Venn diagram intersection.An outer join of A and B gives the results ofRead more
Hi there,
i found some answer you will understand it so easy.
Assuming you’re joining on columns with no duplicates, which is a very common case:
An inner join of A and B gives the result of A intersect B, i.e. the inner part of a Venn diagram intersection.
An outer join of A and B gives the results of A union B, i.e. the outer parts of a Venn diagram union.
Examples
Suppose you have two tables, with a single column each, and data as follows:
A B
– –
1 3
2 4
3 5
4 6
Note that (1,2) are unique to A, (3,4) are common, and (5,6) are unique to B.
Inner join
An inner join using either of the equivalent queries gives the intersection of the two tables, i.e. the two rows they have in common.
[code]SELECT *
FROM a INNER JOIN b ON a.a = b.b;[/code]
[code]SELECT a.*, b.*
FROM a, b
WHERE a.a = b.b;[/code]
a | b
–+–
3 | 3
4 | 4
Left outer join
A left outer join will give all rows in A, plus any common rows in B.
[code]select * from a LEFT OUTER JOIN b on a.a = b.b;
select a.*,b.* from a,b where a.a = b.b(+);[/code]
a | b
–+—–
1 | null
2 | null
3 | 3
4 | 4
Right outer join
A right outer join will give all rows in B, plus any common rows in A.
[code]select * from a RIGHT OUTER JOIN b on a.a = b.b;
select a.*,b.* from a,b where a.a(+) = b.b;[/code]
a | b
—–+—-
3 | 3
4 | 4
null | 5
null | 6
Full outer join
A full outer join will give you the union of A and B, i.e. all the rows in A and all the rows in B. If something in A doesn’t have a corresponding datum in B, then the B portion is null, and vice versa.
[code]select * from a FULL OUTER JOIN b on a.a = b.b;[/code]
a | b
See less—–+—–
1 | null
2 | null
3 | 3
4 | 4
null | 6
null | 5
How to query a CLOB column in Oracle SQL ?
Hi Albert, You can use DBMS_LOB.substr like this for example: DBMS_LOB.substr(column, 3000) but don't forget that substring of a CLOB column has size/buffer restrictions sometimes you would need to set the BUFFER to a larger size. For example while using SQL Plus use the SET BUFFER 10000 to set it tRead more
Hi Albert,
You can use DBMS_LOB.substr like this for example:
but don’t forget that substring of a CLOB column has size/buffer restrictions sometimes you would need to set the BUFFER to a larger size.
For example while using SQL Plus use the SET BUFFER 10000 to set it to 10000 as the default is 4000
and you can refer to Oracle Substr Function Article for more information about the substr function
See lessError ORA-00933: SQL command not properly ended – update
hello, here you can find the cause and action to correct your statement : Cause: The SQL statement ends with an inappropriate clause. For example, an ORDER BY clause may have been included in a CREATE VIEW or INSERT statement. ORDER BY cannot be used to create an ordered view or to insert in a certaRead more
hello,
here you can find the cause and action to correct your statement :
Cause: The SQL statement ends with an inappropriate clause. For example, an ORDER BY clause may have been included in a CREATE VIEW or INSERT statement. ORDER BY cannot be used to create an ordered view or to insert in a certain order.
Action: Correct the syntax by removing the inappropriate clauses. It may be possible to duplicate the removed clause with another SQL statement. For example, to order the rows of a view, do so when querying the view and not when creating it. This error can also occur in SQL*Forms applications if a continuation line is indented. Check for indented lines and delete these spaces.
you can use :
[code]
UPDATE employees e
SET e.last_name = ‘test’
WHERE e.department_id = (SELECT d.department_id
FROM departments d
WHERE d.department_id = e.department_id);
[/code]
What is the difference between schema and user ?
SCOTT is a schema that includes the EMP, DEPT and BONUS tables with various grants, and other stuff. SYS is a schema that includes tons of tables, views, grants, etc etc etc. SYSTEM is a schema..... Technically -- A schema is the set of metadata (data dictionary) used by the database, typicalRead more
SCOTT is a schema that includes the EMP, DEPT and BONUS tables with various grants, and other stuff.
SYS is a schema that includes tons of tables, views, grants, etc etc etc.
SYSTEM is a schema…..
Technically — A schema is the set of metadata (data dictionary) used by the database, typically generated using DDL. A schema defines attributes of the database, such as tables, columns, and properties. A database schema is a description of the data in a database.
See lesshow to check if the column value is number or character
one example to create a function to return 'Y' if parameter value is number otherwise which is exception in this case to return ('N') ex: [code]CREATE OR REPLACE FUNCTION is_number (p_string IN VARCHAR2) RETURN VARCHAR2 DETERMINISTIC PARALLEL_ENABLE IS l_num NUMBER; BEGIN l_num := TO_NUMBER (p_strinRead more
one example to create a function to return ‘Y’ if parameter value is number otherwise which is exception in this case to return (‘N’)
ex:
[code]CREATE OR REPLACE FUNCTION is_number (p_string IN VARCHAR2)
RETURN VARCHAR2
DETERMINISTIC
PARALLEL_ENABLE
IS
l_num NUMBER;
BEGIN
l_num := TO_NUMBER (p_string);
RETURN ‘Y’;
EXCEPTION
WHEN VALUE_ERROR
THEN
RETURN ‘N’;
END is_number;[/code]
and here you can call the function created above to identify the value passed is number or not like :
[code]SELECT (CASE
WHEN (is_number (mycolumn) = ‘Y’)
THEN
‘your column value is number’
ELSE
‘your column value is not number’
END)
FROM myTable;[/code]
hope this help you.
See lessHow to count specific values from table ?
Hi, try this query : [code]SELECT SUM ( CASE WHEN Col1 = 2 THEN 1 ELSE 0 END + CASE WHEN Col2 = 2 THEN 1 ELSE 0 END + CASE WHEN Col3 = 2 THEN 1 ELSE 0 END) FROM table_name WHERE Col1 = 2 OR Col2 = 2 OR Col3 = 2;[/code]
Hi,
try this query :
[code]SELECT SUM (
See lessCASE WHEN Col1 = 2 THEN 1 ELSE 0 END
+ CASE WHEN Col2 = 2 THEN 1 ELSE 0 END
+ CASE WHEN Col3 = 2 THEN 1 ELSE 0 END)
FROM table_name
WHERE Col1 = 2 OR Col2 = 2 OR Col3 = 2;[/code]
How to add a new column to a table only if not exist?
You can find the following view to access all metadata about the columns :user_tab_cols; -- For all tables owned by the userall_tab_cols ; -- For all tables accessible to the userdba_tab_cols; -- For all tables in the Database.and lets consider you want to add new column only if doesn't exists you cRead more
You can find the following view to access all metadata about the columns :
user_tab_cols; — For all tables owned by the user
all_tab_cols ; — For all tables accessible to the user
dba_tab_cols; — For all tables in the Database.
and lets consider you want to add new column only if doesn’t exists you can use this pl/sql to check and add new column
[code]DECLARE
v_column_exists number := 0;
BEGIN
Select count(*)
into v_column_exists
from user_tab_cols
where column_name = ‘ADD_COLUMN’
and table_name = ‘departments’;
if (v_column_exists = 0) then
execute immediate ‘alter table departments add (ADD_COLUMN NUMBER)’;
end if;
end;[/code]
hope this help.
See lessHow to get a list of all packages, procedures and functions in oracle database ?
Hi , use the below query : [code] select * from dba_objects [/code]
Hi ,
use the below query :
[code]
select * from dba_objects
[/code]
See lessHow to find all DB objects that has particular column name ?
Hi,[code] SELECT table_name, column_name FROM user_tab_columns WHERE upper(column_name) LIKE upper('%Last_Name%'); [/code]this in Oracle
Hi,
[code]
SELECT table_name, column_name
FROM user_tab_columns
WHERE upper(column_name) LIKE upper(‘%Last_Name%’);
[/code]
this in Oracle
See lessneed query to display ‘job’ & their counts & then display the no. of distinct ‘dept no’ under each ‘job’ & their counts ?
Hi,[code]SQL> select job, count(*) from scott.emp group by job order by 1;[/code]JOBCOUNT(*)ANALYST2CLERK4MANAGER3PRESIDENT1SALESMAN4 5 rows selected.[code]SQL>select job, count(distinct deptno), count(*)from scott.empgroup by joborder by 1;[/code]JOBCOUNT(DISTINCTDEPTNO)COUNT(*)ANALYST12CLERKRead more
Hi,
[code]
SQL> select job, count(*)
from scott.emp
group by job
order by 1;
[/code]
[code]
SQL>select job, count(distinct deptno), count(*)
from scott.emp
group by job
order by 1;
[/code]
[code]
select job, deptno, count(*)
from scott.emp
group by job,deptno
order by 1,2;
[/code]
In order to put that in a PLSQL procedure, for each SQL you can do
set serverout on
[code]
begin
for i in ( “yoursql” )
loop
dbms_output.put_line( “attributes” );
end loop;
end;
[/code]
hope this help.
See less