0

I have wrote simple stored procedure in Oracle SQL Developer but found, attached ,error on execution/run step.

problem faced

Here is my code:

CREATE OR REPLACE PROCEDURE EMP_NAME (EMP_ID_IN      IN     VARCHAR2,
                                      EMP_NAME_OUT      OUT VARCHAR2)
AS
BEGIN
   SELECT first_name
     INTO EMP_NAME_OUT
     FROM employee
    WHERE emp_id = EMP_ID_IN;
END EMP_NAME;

It also shows this error

error_log

8
  • I don't see quite that message so possibly you're on an earlier version; but it looks like you're creating the procedure through the wizard, and clicking 'Run' before clicking 'Compile' - is that right? Commented Nov 14, 2018 at 10:27
  • I have tried both manual as well as create by wizard approaches and faced the same issue. Similarly, I have tried to 'Run' before compile but found nothing helping. Commented Nov 14, 2018 at 10:38
  • @MuhammadWaheed I have tried with SQL Developer 1.5.5, and it does execute without facing any issues. What is your database version and SQL Developer version? Commented Nov 14, 2018 at 11:09
  • Oracle 10g 101..0.4.2 and Oracle SQL Developer 18.1.0.095.1630-x64 Commented Nov 14, 2018 at 11:16
  • @MuhammadWaheed And your Windows version? Commented Nov 14, 2018 at 11:37

2 Answers 2

1

The procedure itself seems to be OK. However, its execution is somewhat strange.

I suggest you to run it from the Worksheet itself, such as

declare
  l_out employee.first_name%type;
begin
  emp_name(100, l_out);
  dbms_output.put_line('Result = ' || l_out);
end;
/

Though, why is it a procedure? Wouldn't a function be a better choice? E.g.

create or replace function emp_name (emp_id_in in varchar2)
  return employee.first_name%type
is
  retval employee.first_name%type;
begin
  select first_name
    into retval
    from employee
    where emp_id = emp_id_in;

  return retval;
end;
/

You'd run it in a simple manner, as

select emp_name(100) from dual;
Sign up to request clarification or add additional context in comments.

10 Comments

In fact I want to go for stored procedures in Oracle SQL Developer. But it prompts same error on simple 'HelloWorld!' procedure.
CREATE OR REPLACE PROCEDURE HELLO AS BEGIN DBMS_OUTPUT.PUT_LINE('I love Paksitan'); END HELLO;
This is how you create it. How do you call it? By the way, which SQL Developer version is it? If not the latest, consider upgrading it.
It's version is latest one as per oracle.com. I use 'Run' button from given IDE(I saw multiple videos with this approach as successful execution).
I showed you how to run a procedure "manually" (the first piece of code I posted). Try it.
|
1

There's something wrong with your data dictionary. edit: you're on DB 10g, I'm guessing object_id isn't in the all arguments view. When we go to execute a stored procedure, we ask the database for some information about your code.

SELECT data_type, argument_name name 
FROM all_arguments a, all_objects o 
WHERE a.object_id=o.object_id 
AND o.object_name=? and o.owner=? and a.package_name is NULL 
order by position

The error about an invalid object_id - that's coming from this query. What version Oracle Database are you running? Can you see your PL/SQL object in ALL_OBJECTS and do your arguments show up in ALL_ARGUMENTS?

I've taken your code and modified it for the HR.EMPLOYEES table.

It works as expected.

enter image description here

We run some code to be able to show you the two parameters.

I put in a value of '101' for employee number or ID, and hit OK.

Then the OUT parameter is displayed below in the Log panel.

enter image description here

If you open your log panel (view -> log), you'll see a 'Statements' page as well. It's there that you can see ALL the code we execute on the database. That's where I went to get the SQL that's failing for you on the OBJECT_ID. Go look at that, and walk the code and confirm what's not working.

To fix this, go find an OLD copy of SQLDev that supports 10g..like maybe 2.1, OR upgrade your DB to at least 11.2.0.4.

3 Comments

Kindly let me know about those question marks placed in your query. What should I write at that position?
What do you mean by 'object_id' and argument ?
object_id is a column in both all_objects and all_arguments views

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.