Sign Up

Sign Up to our social questions and Answers to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In
Continue with Google
or use


Have an account? Sign In Now

Sign In

Login to our social questions & Answers to ask questions, answer people’s questions & connect with other people.

Sign Up Here
Continue with Google
or use

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Continue with Google
or use

Forgot Password?

Need An Account, Sign Up Here

Sorry, you do not have permission to add post.

Continue with Google
or use

Forgot Password?

Need An Account, Sign Up Here

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.

Oraask Logo Oraask Logo
Sign InSign Up

Oraask

  • Write
    • Add A New Post
    • Ask A Question

Oraask Navigation

Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Categories
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Dev Tools
    • Online Compiler
    • Base64 Converter
    • Oraask XML Formatter
    • Oraask JSON Formatter
  • Wiki
    • SQL Tutorials
    • Java Tutorials
    • Python Tutorials
    • JavaScript Tutorials

Oracle SQL

This category lists all questions related to Oracle SQL database

Share
  • Facebook
6 Followers
57 Answers
85 Questions
Home/Database/Oracle SQL/Page 4
  • Recent Questions
  • Answers
  • No Answers
  1. Asked: March 3, 2017In: Oracle SQL

    what is the difference between “INNER JOIN” and “OUTER JOIN”?

    albert
    albert Explorer
    Added an answer on August 23, 2017 at 1:40 pm

    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
    —–+—–
    1 | null
    2 | null
    3 | 3
    4 | 4
    null | 6
    null | 5

    See less
      • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  2. Asked: June 23, 2016In: Oracle SQL

    How to query a CLOB column in Oracle SQL ?

    Hassan AbdElrahman
    Hassan AbdElrahman Master Oracle ACE Pro Alum ♠ | Oracle Senior ERP Technical Consultant
    Added an answer on August 23, 2017 at 1:32 pm
    This answer was edited.

    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:

    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 to 10000 as the default is 4000

    and you can refer to Oracle Substr Function Article for more information about the substr function

    See less
      • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  3. Asked: June 23, 2016In: Oracle SQL

    Error ORA-00933: SQL command not properly ended – update

    Hassan AbdElrahman
    Hassan AbdElrahman Master Oracle ACE Pro Alum ♠ | Oracle Senior ERP Technical Consultant
    Added an answer on August 13, 2017 at 7:48 pm

    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]

     

    See less
      • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  4. Asked: June 23, 2016In: Oracle SQL

    how to check if the column value is number or character

    Hassan AbdElrahman
    Hassan AbdElrahman Master Oracle ACE Pro Alum ♠ | Oracle Senior ERP Technical Consultant
    Added an answer on July 12, 2017 at 9:16 pm

    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 less
      • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  5. Asked: June 18, 2016In: Oracle SQL

    How to count specific values from table ?

    Hassan AbdElrahman
    Hassan AbdElrahman Master Oracle ACE Pro Alum ♠ | Oracle Senior ERP Technical Consultant
    Added an answer on July 12, 2017 at 9:05 pm

    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 (
    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]

    See less
      • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  6. Asked: March 24, 2017In: Oracle SQL

    How to add a new column to a table only if not exist?

    Hassan AbdElrahman
    Hassan AbdElrahman Master Oracle ACE Pro Alum ♠ | Oracle Senior ERP Technical Consultant
    Added an answer on July 12, 2017 at 7:12 pm

    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 less
      • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  7. Asked: May 1, 2017In: Oracle SQL

    How to get a list of all packages, procedures and functions in oracle database ?

    Mmorsy
    Mmorsy Junior mahmoudmorsymm1985@gmail.com
    Added an answer on July 12, 2017 at 5:27 pm

    Hi , use the below query : [code] select * from dba_objects [/code]

    Hi ,

    use the below query :

    [code]

    select * from dba_objects

    [/code]

    See less
      • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  8. Asked: March 28, 2017In: Oracle SQL

    How to find all DB objects that has particular column name ?

    Beter
    Beter Explorer
    Added an answer on April 21, 2017 at 6:55 pm

    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 less
      • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  9. Asked: April 7, 2017In: Oracle SQL

    need query to display ‘job’ & their counts & then display the no. of distinct ‘dept no’ under each ‘job’ & their counts ?

    Beter
    Beter Explorer
    Added an answer on April 21, 2017 at 6:51 pm

    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]

    JOB COUNT(*)
    ANALYST 2
    CLERK 4
    MANAGER 3
    PRESIDENT 1
    SALESMAN 4
     
    5 rows selected.

    [code]

    SQL>select job, count(distinct deptno), count(*)
    from scott.emp
    group by job
    order by 1;

    [/code]

    JOB COUNT(DISTINCTDEPTNO) COUNT(*)
    ANALYST 1 2
    CLERK 3 4
    MANAGER 3 3
    PRESIDENT 1 1
    SALESMAN 1 4
         
    5 rows selected.

    [code]

    select job, deptno, count(*)
    from scott.emp
    group by job,deptno
    order by 1,2;

    [/code]

     

    JOB DEPTNO COUNT(*)
    ANALYST 20 2
    CLERK 10 1
    CLERK 20 2
    CLERK 30 1
    MANAGER 10 1
    MANAGER 20 1
    MANAGER 30 1
    PRESIDENT 10 1
    SALESMAN 30 4
     
    9 rows selected.

     

    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
      • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  10. Asked: March 20, 2017In: Oracle SQL

    Convert number of seconds to Hours:Minutes:Seconds format

    ashishpandey
    ashishpandey Explorer
    Added an answer on March 28, 2017 at 8:47 am

    Hi, SELECT TO_CHAR(SYSDATE,'SSSSS') FROM DUAL; -- will return like 54071SELECT TO_CHAR(TO_DATE(54071,'SSSSS'),'HH24:MI:SS') FROM DUAL;-- will RETURN like 15:01:11 It will help

    Hi,

     

    SELECT TO_CHAR(SYSDATE,’SSSSS’) FROM DUAL; — will return like 54071

    SELECT TO_CHAR(TO_DATE(54071,’SSSSS’),’HH24:MI:SS’) FROM DUAL;– will RETURN like 15:01:11

     

    It will help

    See less
      • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
1 2 3 4 5 6

Sidebar

Adv 250x250

Explore

  • Categories
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Dev Tools
    • Online Compiler
    • Base64 Converter
    • Oraask XML Formatter
    • Oraask JSON Formatter
  • Wiki
    • SQL Tutorials
    • Java Tutorials
    • Python Tutorials
    • JavaScript Tutorials

Footer

Oraask

About

Oraask is a website for developers and software engineers who want to learn new skills, share their knowledge, and solve their coding problems. Oraask provides free content on various programming languages and topics, such as Oracle, Python, Java, etc. Oraask also allows users to ask questions and get answers from other members of the community.

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy
  • Terms & Conditions

Follow

Oraask is licensed under CC BY-NC-SA 4.0Oraask CopyrightOraask CopyrightOraask CopyrightOraask Copyright

© 2019 Oraask. All Rights Reserved
With Love by Oraask.