34

I executed a PL/SQL script that created the following table

TABLE_NAME VARCHAR2(30) := 'B2BOWNER.SSC_Page_Map';

I made an insert function for this table using arguments

CREATE OR REPLACE FUNCTION F_SSC_Page_Map_Insert(
         p_page_id   IN B2BOWNER.SSC_Page_Map.Page_ID_NBR%TYPE, 
         p_page_type IN B2BOWNER.SSC_Page_Map.Page_Type%TYPE, 
         p_page_dcpn IN B2BOWNER.SSC_Page_Map.Page_Dcpn%TYPE)

I was notified I had to declare B2BOWNER.SSC_Page_Map prior to it appearing as an argument to my function. Why am I getting this error?

EDIT: Actual error

Warning: compiled but with compilation errors
Errors for FUNCTION F_SSC_PAGE_MAP_INSERT

LINE/COL ERROR                                                            
-------- -----------------------------------------------------------------
2/48     PLS-00201: identifier 'SSC_PAGE_MAP.PAGE_ID_NBR' must be declared
0/0      PL/SQL: Compilation unit analysis terminated 

EDIT: Complete PL/SQL Function

RETURN INTEGER
IS
   TABLE_DOES_NOT_EXIST exception;  
   PRAGMA EXCEPTION_INIT(TABLE_DOES_NOT_EXIST, -942); -- ORA-00942

BEGIN

   INSERT INTO 
       B2BOWNER.SSC_Page_Map VALUES(
           p_page_id, 
           p_page_type, 
           p_page_dcpn);

   RETURN 0;

   EXCEPTION
       WHEN TABLE_DOES_NOT_EXIST THEN
           RETURN -1;
       WHEN DUP_VAL_ON_INDEX THEN
           RETURN -2;
       WHEN INVALID_NUMBER THEN
           RETURN -3;
       WHEN OTHERS THEN
           RETURN -4;
END;

SHOW ERRORS PROCEDURE F_SSC_Page_Map_Insert;

GRANT EXECUTE ON F_SSC_Page_Map_Insert TO B2B_USER_DBROLE; 
RETURN INTEGER

EDIT: I change the arguments and received a new error related to the insert command

CREATE OR REPLACE FUNCTION F_SSC_Page_Map_Insert(
                            p_page_id   IN INTEGER, 
                            p_page_type IN VARCHAR2, 
                            p_page_dcpn IN VARCHAR2)

RETURN INTEGER
IS

TABLE_DOES_NOT_EXIST exception;  
PRAGMA EXCEPTION_INIT(TABLE_DOES_NOT_EXIST, -942); -- ORA-00942

BEGIN

INSERT INTO 
    B2BOWNER.SSC_Page_Map VALUES(
        p_page_id, 
        p_page_type, 
        p_page_dcpn);

The error

Errors for FUNCTION F_SSC_PAGE_MAP_INSERT

LINE/COL ERROR                                                            
-------- -----------------------------------------------------------------
17/18    PL/SQL: ORA-00942: table or view does not exist                  
16/5     PL/SQL: SQL Statement ignored                                    

The tables has been verified within the correct schema and with the correct attribute names and types

EDIT: I executed the following command to check if I have access

DECLARE
    count_this INTEGER;

BEGIN

select count(*) into count_this 
from all_tables 
where owner = 'B2BOWNER' 
and table_name = 'SSC_PAGE_MAP';

DBMS_OUTPUT.PUT_LINE(count_this);

END;

The output I received is

1
PL/SQL procedure successfully completed.

I have access to the table.

EDIT:

So I finally conducted an insert into the table via the schema using PL/SQL and it worked fine. It appears I simply do not have authority to create functions but that is an assumption.

EDIT:

Actual table DDL statement

 v_create := 'CREATE TABLE ' ||  TABLE_NAME || ' (
                PAGE_ID_NBR   NUMERIC(10)   NOT NULL Check(Page_ID_NBR > 0),
                PAGE_TYPE     VARCHAR2(50)  NOT NULL, 
                PAGE_DCPN     VARCHAR2(100) NOT NULL,
                PRIMARY KEY(Page_ID_NBR, Page_Type))';

EXECUTE IMMEDIATE v_create; 

COMMIT WORK;

COMMIT COMMENT 'Create Table'; 
Srini V
  • 11,045
  • 14
  • 66
  • 89
Mushy
  • 2,535
  • 10
  • 33
  • 54
  • 2
    You haven't included any code which would cause that error. This makes it rather difficult to determine why you might have caused that error. Can you also please post the actual error rather than your interpretation of it? – Ben May 07 '14 at 19:49
  • @Ben As you can see from the posted error this is indeed a real issue – Mushy May 07 '14 at 19:54
  • 3
    I never disputed that you were having a problem @Mushy, just that you didn't give enough information to solve the problem. The error you've posted is different from that stated.. it states that there is no identifier `SSC_PAGE_MAP.PAGE_ID_NBR`. Have you validated that the column `PAGE_ID_NBR` on the table `SSC_PAGE_MAP` in the schema ` B2BOWNER` exists and that you have the ability to SELECT from this table in the schema that you are creating this function? – Ben May 07 '14 at 19:57
  • @Ben Yes, table verified as existing under schema, can be the target of a DDL statement and the attributes of such a table are verified as correct and match the function argument names. Only thing I can think of is if somehow case sensitivity has thrown this off but I doubt it. – Mushy May 07 '14 at 20:07
  • Do you mean a DML statement rather than DDL @Mushy? – Ben May 07 '14 at 20:08
  • Well yes @Ben a DML statement such as SELECT – Mushy May 07 '14 at 20:09
  • Your latest edit indicates that you do not have access to the table. Can you post indicate what the result of `select count(*) from all_tables where owner = 'B2BOWNER' and table_name = 'SSC_PAGE_MAP'` is? Can you log into the schema `B2BOWNER` and `grant insert on ssc_page_map to `? – Ben May 07 '14 at 20:39
  • Try `SELECT * FROM ALL_TAB_COLUMNS WHERE OWNER='B2BOWNER' AND TABLE_NAME='SSC_PAGE_MAP'`. What column names are returned? – Bob Jarvis - Слава Україні May 07 '14 at 20:57
  • @Ben I don't know how to log into the schema and perform such a grant. I would need to get with the DBAs on that unless you can explain how. I am using TOAD for Oracle. – Mushy May 07 '14 at 21:01
  • @BobJarvis when I ran the query I received a `Error at line 1 ORA-06550: line 13, column 31: PL/SQL: ORA-00947: not enough values ORA-06550: line 13, column 5: PL/SQL: SQL Statement ignored Script Terminated on line 1.` – Mushy May 07 '14 at 21:04
  • There's no difference between the query I posted and the one @Bob did.... that's a _very_ strange error to be getting on a SELECT statement... I doubt that's what you did. If the one either I or Bob posted returns 0 rows then you need to grant the correct privileges. Judging by the way this is going I strongly suspect this is the case. Either way, you're probably going to have to talk to your DBAs... – Ben May 07 '14 at 21:15
  • 2
    For the original error it just looks like the column name is wrong, as has already been suggested - from the function argument names, which you said match the table columns, maybe the `_nbr` part just shouldn't be there for the `%type`, but only you can query the data dictionary to see. For the later error, it sounds like you have privileges on the table granted via a role instead of directly to your user - look up `authid` in the PL/SQL manual. – Alex Poole May 07 '14 at 22:16
  • @AlexPoole No, the table attributes have been checked and double checked. All is in order. It may be as you stated and I will need to contact the DBAs to have them grant me the proper permissions. – Mushy May 08 '14 at 10:09
  • @AlexPoole That is not a secret and, since you asked, I have included it. They used to be mixed-case but my DB IDE (TOAD) ignores case and shows everything as all caps. I have never head of case-sensitivity being an issue for a table. – Mushy May 08 '14 at 11:30

3 Answers3

13

When creating the TABLE under B2BOWNER, be sure to prefix the PL/SQL function with the Schema name; i.e. B2BOWNER.F_SSC_Page_Map_Insert.

I did not realize this until the DBAs pointed it out. I could have created the table under my root USER/SCHEMA and the PL/SQL function would have worked fine.

Mushy
  • 2,535
  • 10
  • 33
  • 54
4

The procedure name should be in caps while creating procedure in database. You may use small letters for your procedure name while calling from Java class like:

String getDBUSERByUserIdSql = "{call getDBUSERByUserId(?,?,?,?)}";

In database the name of procedure should be:

GETDBUSERBYUSERID    -- (all letters in caps only)

This serves as one of the solutions for this problem.

Bojangles
  • 99,427
  • 50
  • 170
  • 208
udhay
  • 57
  • 1
  • 4
  • 5
    I have mixed case names for my procs - no problems. The issue I had was permission was allocated by role, and this is not allowed. – Ruskin Jan 12 '15 at 12:23
  • @Ruskin Yep this was the answer for me too. `grant execute on [package] to [some role that the user has]` and it raised the compile error, but `grant execute on [package] to [user]` and it compiled fine. – Andrew Spencer Jan 19 '16 at 14:41
  • 4
    Why is this the accepted answer? Is there any evidence that this could ever even cause this error? Also, OP posted his/her own answer which is different. – Jay Sullivan May 25 '16 at 20:10
  • 1
    I concur with Jay Sullivan. Why is this even an accepted answer. This does not make any sense. Do I smell voting fraud? – shashwatZing Sep 23 '16 at 17:14
3

you should give permission on your db

grant execute on (packageName or tableName) to user;
elifekiz
  • 1,456
  • 13
  • 26