0

I try to create one test procedure but it gets Error(4,1): PL/SQL: SQL Statement ignored ** and ** Error(12,20): PL/SQL: ORA-00942: table or view does not exist when I try to compile. Then I test select statement in next session, it run successfully. Could you please help me.

create or replace PROCEDURE TEST_1
AS
BEGIN
SELECT
A.EMPLOYEE_ID AS "Employee ID",
A.FIRST_NAME||' '||A.LAST_NAME AS "Name",
B.DEPARTMENT_NAME AS "Department Name",
A.EMAIL AS "Email Address",
A.PHONE_NUMBER AS "Contact Number",
C.STREET_ADDRESS||', '||C.CITY||', '||NVL(C.STATE_PROVINCE,C.CITY) AS "Address"
FROM HR.EMPLOYEES A 
LEFT OUTER JOIN HR.DEPARTMENTS B
ON A.DEPARTMENT_ID = B.DEPARTMENT_ID
LEFT OUTER JOIN HR.LOCATIONS C
ON B.LOCATION_ID = C.LOCATION_ID;
END;
asked Mar 28, 2018 at 6:16

1 Answer 1

1

Looks like a right problem. Do you realy need "HR." ?

Try

create PROCEDURE TEST_1 AS BEGIN 
CURRENT_USER
SELECT A.EMPLOYEE_ID AS "Employee ID",
 A.FIRST_NAME || ' ' || A.LAST_NAME AS "Name",
 B.DEPARTMENT_NAME AS "Department Name",
 A.EMAIL AS "Email Address",
 A.PHONE_NUMBER AS "Contact Number",
 C.STREET_ADDRESS || ', ' || C.CITY || ', ' ||
 NVL(C.STATE_PROVINCE, C.CITY) AS "Address"
 FROM EMPLOYEES A
 LEFT OUTER JOIN DEPARTMENTS B
 ON A.DEPARTMENT_ID = B.DEPARTMENT_ID
 LEFT OUTER JOIN LOCATIONS C
 ON B.LOCATION_ID = C.LOCATION_ID;
END;

And have a look at GRANT (for example)

GRANT EXECUTE ON PROCEDURE <user>.test_1 TO <role>
answered Mar 28, 2018 at 7:28
5
  • Thanks for answer but it doesn't work. Yes, I need HR because I create procedure from another users, it has got DBA role. Do I need to add another GRANT on it? Commented Mar 28, 2018 at 8:27
  • So you can use "GRANT ON ... TO <user>". HR inside is not neccessary. Commented Mar 28, 2018 at 8:32
  • It doesn't work.I got this Error(4,1): PLS-00428: an INTO clause is expected in this SELECT statement. Commented Mar 28, 2018 at 9:30
  • What do you what to do. Show some user some data. So maybe CREATE VIEW is the right way to do so. Commented Mar 28, 2018 at 9:49
  • @AZT In PL/SQL context you cannot use a query like that, you have to either run a query that returns exactly one row, and use "INTO" clause to save the row or value to a variable, or you use it as a cursor and iterate it. Commented Jun 7, 2021 at 8:02

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.