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

Database

This Category lists all questions related to all different kind of databases

Share
  • Facebook
0 Followers
0 Answers
150 Questions
Home/Database/Page 6
  • Recent Questions
  • Answers
  • No Answers
  1. Asked: April 1, 2017In: PL/SQL

    What is the difference between procedure and function in PL/SQL?

    Hassan AbdElrahman
    Hassan AbdElrahman Master Oracle ACE Pro Alum ♠ | Oracle Senior ERP Technical Consultant
    Added an answer on July 13, 2017 at 9:53 am

    1. Procedure may or may not return value where as function should return one value. 2. Function can be called from SQL statement where as procedure can't be called from the SQL statement. 3. Function are normally used for computation where as procedure are normally used for executing business logic.Read more

    1. Procedure may or may not return value where as function should return one value.

    2. Function can be called from SQL statement where as procedure can’t be called from the SQL statement.

    3. Function are normally used for computation where as procedure are normally used for executing business logic.

    4. Stored procedure is pre-compiled execution plan where as function are not.

    5. We can call function within procedure but we can not call procedure within function.

    6. A FUNCTION must be part of an executable statement, as it cannot be executed independently, whereas procedure represents an independent executable statement.

    and for example of both syntax of function and procedure :

    [code]CREATE OR REPLACE PROCEDURE test_proc
    (p_id IN VARCHAR2) as begin … end

    CREATE OR REPLACE FUNCTION test_func
    (p_id IN VARCHAR2) return varchar2 as begin … end[/code]

     

    hope this help.

    See less
      • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  2. Asked: April 3, 2017In: PL/SQL

    ORA-06550: line , column : PLS-00201: identifier must be declared

    Hassan AbdElrahman
    Best Answer
    Hassan AbdElrahman Master Oracle ACE Pro Alum ♠ | Oracle Senior ERP Technical Consultant
    Added an answer on July 12, 2017 at 9:26 pm
    This answer was edited.

    ORA-06550: error causes are:  You tried to execute an invalid block of PLSQL code (like a stored procedure or function), but a compilation error occurred. in your example, you selected a value inside the variable (v_last) that is not declared in your block. So to correct your block of code, you canRead more

    ORA-06550: error causes are:  You tried to execute an invalid block of PLSQL code (like a stored procedure or function), but a compilation error occurred.

    in your example, you selected a value inside the variable (v_last) that is not declared in your block.

    So to correct your block of code, you can rewrite it like this:

    DECLARE
    V_LAST EMPLOYEES.LAST_NAME%TYPE;
    BEGIN
    SELECT LAST_NAME INTO V_LAST FROM EMPLOYEES; dbms_output.put_line(‘v_last is :’ || V_LAST );
    END;
    See less
      • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  3. 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
  4. 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
  5. 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
  6. 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
  7. Asked: July 11, 2017In: Oracle Database

    How to restore database with until time ?

    Mmorsy
    Mmorsy Junior mahmoudmorsymm1985@gmail.com
    Added an answer on July 11, 2017 at 4:28 pm

    Hello ,You can run this command in the shell session:export NLS_DATE_FORMAT="YYYY-MM-DD:HH24:MI:SS"Thenconnect with RMAN rman target /RUN{ ALLOCATE CHANNEL prmy1 TYPE disk ; set until time= "to_date('14/07/2015 10:34:36','dd/mm/yyyy hh24:mi:ss')"; RESTORE DATABASE; RECOVER DATABASE; RELEASE CHANNELRead more

    Hello ,

    You can run this command in the shell session:

    export NLS_DATE_FORMAT=”YYYY-MM-DD:HH24:MI:SS”

    Then

    connect with RMAN
    rman target /

    RUN
    {
    ALLOCATE CHANNEL prmy1 TYPE disk ;
    set until time= “to_date(’14/07/2015 10:34:36′,’dd/mm/yyyy hh24:mi:ss’)”;
    RESTORE DATABASE;
    RECOVER DATABASE;
    RELEASE CHANNEL prmy1;
    }

    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 … 4 5 6 7 8 9

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.