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
  • Recent Questions
  • Answers
  • No Answers
  1. Asked: August 17, 2022In: Oracle SQL

    How to get Column Names from a Table in Oracle

    Hassan AbdElrahman
    Best Answer
    Hassan AbdElrahman Master Oracle ACE Pro Alum ♠ | Oracle Senior ERP Technical Consultant
    Added an answer on August 17, 2022 at 1:35 am
    This answer was edited.

    To get the list of columns of a table in Oracle, we use to query the view "USER_TAB_COLUMNS" to get the columns of the tables or views owned by the current user. Or use the other view "USER_TAB_COLS". SELECT table_name ,column_name ,data_type ,data_length ,nullable ,data_default FROM user_tab_columnRead more

    To get the list of columns of a table in Oracle, we use to query the view “USER_TAB_COLUMNS” to get the columns of the tables or views owned by the current user. Or use the other view “USER_TAB_COLS“.

    SELECT table_name
    ,column_name
    ,data_type
    ,data_length
    ,nullable
    ,data_default
    FROM  user_tab_columns
    WHERE table_name = '&YOUTABLENAME'
    ORDER BY column_id;

    in the above query, we selected 7 columns to retrieve the most important information that you might be looking for in table columns which are

    • table names: the table name.
    • column name: column name.
    • data type: column data type like varchar2, number, etc.
    • data length: the value length.
    • nullable: whether the table accepts the null value or not.
    • data_default: whether the column has a default value or not.

    Note: you have to specify the table name parameter in uppercase.

    Note 2: If you use the above view, you will get all unhidden columns, but if you query the view “USER_TAB_COLS” you will get all columns, including hidden columns.

    Another view is “ALL_TAB_COLUMNS” this one is the same as “USER_TAB_COLUMNS” except that the “ALL_TAB_COLUMNS” view has a column called “OWNER” in which you can specify the owner of the table that you want to get its columns list.

    See less
      • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  2. Asked: July 19, 2022In: Oracle SQL

    What is the use of LIMIT and OFFSET in SQL

    Himanshu kumar
    Himanshu kumar Junior TA @GEEKSFORGEEKS | CONTENT CREATOR | FREELANCE CONTENT WRITER |
    Added an answer on July 23, 2022 at 1:42 am

    We will be using below Students table to explain the Example Queries:- If there are a large number of tuples satisfying the query conditions, it might beresourceful to view only a handful of them at a time. The LIMIT clause is used to set an upper limit on the number of tuplesreturned by SQL. It isRead more

    We will be using below Students table to explain the

    Example Queries:-

    If there are a large number of tuples satisfying the query conditions, it might be
    resourceful to view only a handful of them at a time.

    • The LIMIT clause is used to set an upper limit on the number of tuples
      returned by SQL.
    • It is important to note that this clause is not supported by all SQL versions.
    • The LIMIT clause can also be specfied using the SQL 2008 OFFSET/FETCH
      FIRST clauses.
    • The limit/offset expressions must be a non-negative integer.

    Example Queries to demonstrate LIMIT Clause.

    • SELECT *
      FROM Students
      LIMIT 3;

    Output of the query gives First three Student Records.

    • SELECT *
      FROM Students
      ORDER BY age
      LIMIT 3;

    Output of the query gives three Student Records in order of Ascending Ages.

    The LIMIT operator can be used in situations such as the above, where we need to
    find the top N students in a class and based on any condition statements.

    Using LIMIT along with OFFSET

    LIMIT x OFFSET y simply means skip the first y entries and then return the next x
    entries.
    OFFSET can only be used with the ORDER BY clause. It cannot be used on its own.
    OFFSET value must be greater than or equal to zero. It cannot be negative, else
    returns error.
    Example query to demonstrate LIMIT and OFFSET.

    • SELECT *
      FROM Students
      LIMIT 3 OFFSET 2
      ORDER BY roll_no;

    Returns 3 Student Records skipping first two records in Table.

     

     

     

     

    See less
      • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  3. Asked: July 19, 2022In: Oracle SQL

    What are the differences between SQL and PL/SQL in Oracle

    Himanshu kumar
    Himanshu kumar Junior TA @GEEKSFORGEEKS | CONTENT CREATOR | FREELANCE CONTENT WRITER |
    Added an answer on July 23, 2022 at 1:32 am

    SQL- SQL, is Structural Query Language for database. SQL has no variables. SQL is data oriented languages. SQL is very declarative in nature. SQL is used in manipulating data. SQL tells data what to do ? PLSQL- PL/SQL is a programming language using SQL for a database. PL/SQL has variables, data typRead more

    SQL-

    1. SQL, is Structural Query Language for database.
    2. SQL has no variables.
    3. SQL is data oriented languages.
    4. SQL is very declarative in nature.
    5. SQL is used in manipulating data.
    6. SQL tells data what to do ?

    PLSQL-

    1. PL/SQL is a programming language using SQL for a database.
    2. PL/SQL has variables, data types etc.
    3. PL/SQL has a procedural nature.
    4. PL/SQL used for creating application.
    5. we can execute block of statements in PL/SQL.
    6. PL/SQL tells databases how to do.
    See less
      • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  4. Asked: July 20, 2022In: Oracle SQL

    What is the use of ADD, DROP and MODIFY Commands

    Himanshu kumar
    Himanshu kumar Junior TA @GEEKSFORGEEKS | CONTENT CREATOR | FREELANCE CONTENT WRITER |
    Added an answer on July 23, 2022 at 1:22 am

    ALTER TABLE is used to add, delete/drop or modify columns in the existing table. It is alsoused to add and drop various constraints on the existing table. ALTER TABLE - ADD ADD is used to add columns into the existing table. Sometimes we may require to addadditional information, in that case we do nRead more

    ALTER TABLE is used to add, delete/drop or modify columns in the existing table. It is also
    used to add and drop various constraints on the existing table.

    ALTER TABLE – ADD

    ADD is used to add columns into the existing table. Sometimes we may require to add
    additional information, in that case we do not require to create the whole database
    again, ADD comes to our rescue.

    Syntax:

    • ALTER TABLE table_name
      ADD (Columnname_1 datatype,
      Columnname_2 datatype,
      Columnname_n datatype);

    ALTER TABLE – DROP

    DROP COLUMN is used to drop column in a table. Deleting the unwanted columns from
    the table.

    Syntax:

    • ALTER TABLE table_name
      DROP COLUMN column_name;

    ALTER TABLE-MODIFY

    It is used to modify the existing columns in a table. Multiple columns can also be modified
    at once.
    Syntax may vary slightly in different databases. Syntax(Oracle,MySQL,MariaDB):

    • ALTER TABLE table_name
      MODIFY column_name column_type;

     

    Syntax(SQL Server):

    • ALTER TABLE table_name
      ALTER COLUMN column_name column_type;

    Queries
    Sample Table:

    Student

    • ROLL_NONAME
      1 Ram
      2 Abhi
      3 Rahul
      4 Tanu

     

    QUERY:•

    To ADD 2 columns AGE and COURSE to table Student

    • ALTER TABLE Student ADD (AGE number(3),COURSE varchar(40));

     

    OUTPUT:

    • ROLL_NONAMEAGECOURSE
      1 Ram
      2 Abhi
      3 Rahul
      4 Tanu

     

    • MODIFY column COURSE in table Student

     

    • ALTER TABLE Student MODIFY COURSE varchar(20);

     

    After running the above query maximum size of Course Column is reduced to 20
    from 40.

    • DROP column COURSE in table Student.

     

    ALTER TABLE Student DROP COLUMN COURSE;

    • OUTPUT:
      ROLL_NONAMEAGE
      1 Ram
      2 Abhi
      3 Rahul
      4 Tanu
    See less
      • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  5. Asked: July 17, 2022In: Oracle SQL

    How do I get nth sting from comma delimiter string

    Hassan AbdElrahman
    Hassan AbdElrahman Master Oracle ACE Pro Alum ♠ | Oracle Senior ERP Technical Consultant
    Added an answer on July 17, 2022 at 1:24 pm

    You can use REGEXP_SUBSTR to find the nth specific string from comma delimiter string Example: SELECT REGEXP_SUBSTR ('Oraask,Google,yahoo,new,old,etc','[^,]+' , 1, 3) third_value FROM DUAL; Result: yahoo  

    You can use REGEXP_SUBSTR to find the nth specific string from comma delimiter string

    Example:

    SELECT REGEXP_SUBSTR ('Oraask,Google,yahoo,new,old,etc','[^,]+' , 1, 3) third_value
    FROM DUAL;

    Result:

    yahoo

     

    See less
      • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  6. Asked: June 15, 2022In: Oracle SQL

    What is CTE in Oracle SQL

    Hassan AbdElrahman
    Hassan AbdElrahman Master Oracle ACE Pro Alum ♠ | Oracle Senior ERP Technical Consultant
    Added an answer on July 11, 2022 at 1:45 pm

    CTE stands for Common Table Expression. Another acronym is subquery factory; It's simply a query that you can define in another query. It starts with WITH clause that lets you assign a name to a subquery block. Then you can reference this subquery block in multiple places within your main query by gRead more

    CTE stands for Common Table Expression. Another acronym is subquery factory; It’s simply a query that you can define in another query. It starts with WITH clause that lets you assign a name to a subquery block. Then you can reference this subquery block in multiple places within your main query by giving that query a name.

    Oracle database traits that query name as either an inline view or as a temporary table that will be dropped automatically after the execution of your main query is finished.

    Let’s take a simple example to showcase the use of CTE in the Oracle database

    Let’s say we need to get the employees that are hired on the first day of each month in the current year.

    WITH hiring_periods (period)
    AS (SELECT to_date ('2006-01-01', 'yyyy-mm-dd') FROM dual
    UNION ALL
    SELECT to_date ('2006-02-01', 'yyyy-mm-dd') FROM dual
    UNION ALL
    SELECT to_date ('2006-03-01', 'yyyy-mm-dd') FROM dual
    UNION ALL
    SELECT to_date ('2006-04-01', 'yyyy-mm-dd') FROM dual
    UNION ALL
    SELECT to_date ('2006-05-01', 'yyyy-mm-dd') FROM dual
    UNION ALL
    SELECT to_date ('2006-06-01', 'yyyy-mm-dd') FROM dual
    UNION ALL
    SELECT to_date ('2006-07-01', 'yyyy-mm-dd') FROM dual
    UNION ALL
    SELECT to_date ('2006-08-01', 'yyyy-mm-dd') FROM dual
    UNION ALL
    SELECT to_date ('2006-09-01', 'yyyy-mm-dd') FROM dual
    UNION ALL
    SELECT to_date ('2006-10-01', 'yyyy-mm-dd') FROM dual
    UNION ALL
    SELECT to_date ('2006-11-01', 'yyyy-mm-dd') FROM dual
    UNION ALL
    SELECT to_date ('2006-12-01', 'yyyy-mm-dd') FROM dual)
    SELECT e.first_name, e.last_name, e.hire_date
    FROM employees e, hiring_periods hp
    WHERE e.hire_date = hp.period;

    Output:

    | FIREST_NAME | LAST_NAME | HIRE_DATE
    | ——————- | —————- | —————-|
    | Samuel                 | McCain           | 01/07/2006   |

     

    In the above query, we first start our query with a WITH clause to define a temporary table that has a date of the first day of each month and give that temp table or inline view a name which is “hiring_period” and then uses this name in the main query by joining it with the employee’s table using the hire date column.

    See less
      • 1
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  7. Asked: July 7, 2022In: Oracle SQL

    Why do we use bulk collect in Oracle

    Hassan AbdElrahman
    Best Answer
    Hassan AbdElrahman Master Oracle ACE Pro Alum ♠ | Oracle Senior ERP Technical Consultant
    Added an answer on July 8, 2022 at 8:51 pm

    BULK COLLECT in Oracle PL/SQL: BULK COLLECT in Oracle PL/SQL reduces the round trip between SQL engine and PL/SQL engine and allows SQL engine to fitch a bulk collection of data at once instead of the traditional LOOP statement. We are using the BULK COLLECT clause in the SELECT statement to fitch tRead more

    BULK COLLECT in Oracle PL/SQL:

    BULK COLLECT in Oracle PL/SQL reduces the round trip between SQL engine and PL/SQL engine and allows SQL engine to fitch a bulk collection of data at once instead of the traditional LOOP statement.

    We are using the BULK COLLECT clause in the SELECT statement to fitch the cursor result set in bulk or to populate the records in bulk.

    Since the BULK COLLECT fetches a result set or more than one record, the INTO clause must contain a collection variable like Oracle TYPE.

    Example:

    DECLARE
    CURSOR oraask_dept_details
    IS
    SELECT * FROM departments;

    TYPE l_dept_details_tbl IS TABLE OF departments%ROWTYPE;

    l_dept_details l_dept_details_tbl;
    BEGIN
    OPEN oraask_dept_details;

    LOOP
    FETCH oraask_dept_details BULK COLLECT INTO l_dept_details LIMIT 10;

    EXIT WHEN l_dept_details.count = 0;

    FOR dept_details_rec IN l_dept_details.first .. l_dept_details.last
    LOOP
    dbms_output.put_line ('DEPARTMENT ID:' || l_dept_details (dept_details_rec).department_id || ' - DEPARTMENT NAME:' || l_dept_details (dept_details_rec).department_name);
    END LOOP;
    END LOOP;

    CLOSE oraask_dept_details;
    END;
    /

    Output :

    DEPARTMENT ID:10 - DEPARTMENT NAME:Administration
    DEPARTMENT ID:20 - DEPARTMENT NAME:Marketing
    DEPARTMENT ID:30 - DEPARTMENT NAME:Purchasing
    DEPARTMENT ID:40 - DEPARTMENT NAME:Human Resources
    DEPARTMENT ID:50 - DEPARTMENT NAME:Shipping
    DEPARTMENT ID:60 - DEPARTMENT NAME:IT
    DEPARTMENT ID:70 - DEPARTMENT NAME:Public Relations
    DEPARTMENT ID:80 - DEPARTMENT NAME:Sales
    DEPARTMENT ID:90 - DEPARTMENT NAME:Executive
    DEPARTMENT ID:100 - DEPARTMENT NAME:Finance
    DEPARTMENT ID:110 - DEPARTMENT NAME:Accounting
    DEPARTMENT ID:120 - DEPARTMENT NAME:Treasury
    DEPARTMENT ID:130 - DEPARTMENT NAME:Corporate Tax
    DEPARTMENT ID:140 - DEPARTMENT NAME:Control And Credit
    DEPARTMENT ID:150 - DEPARTMENT NAME:Shareholder Services
    DEPARTMENT ID:160 - DEPARTMENT NAME:Benefits
    DEPARTMENT ID:170 - DEPARTMENT NAME:Manufacturing
    DEPARTMENT ID:180 - DEPARTMENT NAME:Construction
    DEPARTMENT ID:190 - DEPARTMENT NAME:Contracting
    DEPARTMENT ID:200 - DEPARTMENT NAME:Operations
    DEPARTMENT ID:210 - DEPARTMENT NAME:IT Support
    DEPARTMENT ID:220 - DEPARTMENT NAME:NOC
    DEPARTMENT ID:230 - DEPARTMENT NAME:IT Helpdesk
    DEPARTMENT ID:240 - DEPARTMENT NAME:Government Sales
    DEPARTMENT ID:250 - DEPARTMENT NAME:Retail Sales
    DEPARTMENT ID:260 - DEPARTMENT NAME:Recruiting
    DEPARTMENT ID:270 - DEPARTMENT NAME:Payroll

    In the above script, we used a LIMIT clause to limit fetching the bulk of records to 10 records at a time. This clause is very handful when dealing with a large number of records to avoid running out of memory because the collection type we use is expanding as more records are inserted into it.

    Do you find it helpful? Share to spread the knowledge

    See less
      • 1
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  8. Asked: July 6, 2022In: Oracle SQL

    Search all columns of the database oracle SQL

    Hassan AbdElrahman
    Best Answer
    Hassan AbdElrahman Master Oracle ACE Pro Alum ♠ | Oracle Senior ERP Technical Consultant
    Added an answer on July 7, 2022 at 12:14 am
    This answer was edited.

    To find The tables which contain a particular column name, you can use the following query: SELECT owner, table_name, column_name FROM all_tab_columns WHERE column_name LIKE '%TRANSACTION_QUANTITY%'; The output of this select statement would be: You can get the result from a specific owner schema liRead more

    To find The tables which contain a particular column name, you can use the following query:

    SELECT owner, table_name, column_name 
    FROM all_tab_columns
    WHERE column_name LIKE '%TRANSACTION_QUANTITY%';

    The output of this select statement would be:

    query result

    You can get the result from a specific owner schema like ‘INV’ and so on. 

    You may also be interested in checking my answer to other related questions from here Get Column Name from Table in Oracle

    See less
      • 1
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  9. Asked: March 28, 2020In: Oracle SQL

    How to copy a table without data in oracle?

    Hassan AbdElrahman
    Hassan AbdElrahman Master Oracle ACE Pro Alum ♠ | Oracle Senior ERP Technical Consultant
    Added an answer on June 25, 2022 at 2:43 pm

    To copy a table without copying its data, you can simply use this SQL statement: CREATE TABLE xx_oraask_tbl_bkp AS SELECT * FROM xx_oraask_tbl WHERE 1=0; But there is a limitation to using the above statement that you have to pay attention to: The following database objects are not copied to the newRead more

    To copy a table without copying its data, you can simply use this SQL statement:

    CREATE TABLE xx_oraask_tbl_bkp AS SELECT * FROM xx_oraask_tbl WHERE 1=0;

    But there is a limitation to using the above statement that you have to pay attention to:

    The following database objects are not copied to the new version of your table

    • Sequences
    • Triggers
    • Indexes
    • Identity column
    • Some constraints
    • Partitioning

    Or you can use another way to do this:

    SELECT dbms_metadata.get_ddl( 'TABLE', 'xx_oraask_tbl' ) FROM DUAL;

    In the above statement, you will get the DDL statement of a specified table, and then you can easily change the table name, the indexes, etc.

    See less
      • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  10. Asked: September 18, 2021In: Oracle SQL

    ORA-01417: a table may be outer joined to at most one other table

    Hassan AbdElrahman
    Best Answer
    Hassan AbdElrahman Master Oracle ACE Pro Alum ♠ | Oracle Senior ERP Technical Consultant
    Added an answer on June 17, 2022 at 3:20 am

    Before Oracle database release 12c, the error ORA-01417 is raised when you have more than one table on the left-hand side of an outer join. To overcome this limit, we can convert the join to an ANSI syntax, e.g.: SELECT * FROM EMPLOYEES E LEFT JOIN DEPARTMENTS D ON (D.DEPARTMENT_ID = E.DEPARTMENT_IDRead more

    Before Oracle database release 12c, the error ORA-01417 is raised when you have more than one table on the left-hand side of an outer join. To overcome this limit, we can convert the join to an ANSI syntax, e.g.:

    SELECT *
    FROM EMPLOYEES E
    LEFT JOIN DEPARTMENTS D ON (D.DEPARTMENT_ID = E.DEPARTMENT_ID)
    LEFT JOIN LOCATIONS L ON (L.LOCATION_ID = D.LOCATION_ID);

    From the 12c version, Oracle has supported having multiple tables on the left-hand side of the join.

    See less
      • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
1 2 3 … 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.