PLS-00201: identifier 'DBMS_AWM' must be declared on owbsys user - database

After upgrading oracle database from 11gR1 to 11gR2, owbsys user's procedure get the following compilation error.
PROCEDURE OWBSYS.WB_OLAP_LOAD_CUBE
On line: 1
PLS-00201: identifier 'DBMS_AWM' must be declared
Procedure Code:
CREATE OR REPLACE PROCEDURE OWBSYS.WB_OLAP_LOAD_CUBE(olap_aw_owner VARCHAR2, olap_aw_name VARCHAR2, olap_cube_owner VARCHAR2, olap_cube_name VARCHAR2, olap_tgt_cube_name VARCHAR2) AS v varchar2(32);
BEGIN
BEGIN
DBMS_AWM.CREATE_AWCUBELOAD_SPEC(olap_cube_name, olap_cube_owner, olap_cube_name, 'LOAD_DATA');
EXCEPTION WHEN OTHERS THEN NULL;
END;
DBMS_AWM.REFRESH_AWCUBE(olap_aw_owner, olap_aw_name, olap_tgt_cube_name, olap_cube_name);
DBMS_AW.EXECUTE('upd '||olap_aw_owner||'.'||olap_aw_name ||'; commit');
BEGIN
SELECT null into v from all_olap2_aw_cube_agg_specs where aw_owner=olap_aw_owner and aw_name=olap_aw_name and aw_cube_name=olap_tgt_cube_name and aw_aggspec_name=olap_cube_name;
EXCEPTION
WHEN OTHERS THEN RETURN;
END;
DBMS_AWM.AGGREGATE_AWCUBE(olap_aw_owner, olap_aw_name, olap_tgt_cube_name, olap_cube_name);
EXCEPTION
WHEN OTHERS THEN RAISE;
END;
/

The following is the workaround to fix the issue
Step 1: Login to database as SYSDBA
Step 2: Run the following grant command
GRANT EXECUTE ON DBMS_AWM TO OWBSYS;
Step 3: Re-compile your procedure.
Hopefully, after performing the above actions, your procedure will compile without errors.

Related

How to call a private procedure which is body implemented inside package body but there is no package specification

What is the use of a package body without package specification in Oracle?
Tried in the mentioned link example.
below is the example:
create or replace package pkg_spec_test
AS
procedure p1;
v_1 NUMBER := 10;
END;
/
create or replace package body pkg_spec_test
AS
procedure p1 AS
BEGIN
dbms_output.put_line('HELLO. I can be called externally');
END p1;
procedure p2 AS
BEGIN
dbms_output.put_line('I''m private to package body.');
END;
procedure main as
begin
p2; --called within the body;
END main;
END pkg_spec_test;
/
Here the procedure p2 and main both have no specifications.
Below are the execution blocks
begin
pkg_spec_test.p1;
end;
/
above block is working fine.
now, executing the p2 procedure. it throws errors
begin
pkg_spec_test.p2;
end;
/
Error starting at line : 30 in command -
begin
pkg_spec_test.p2;
end;
Error report -
ORA-06550: line 2, column 15:
PLS-00302: component 'P2' must be declared
now, executing the main procedure it also throws the same errors as above.
begin
pkg_spec_test.main;
end;
/
Question: in the mentioned link shows executing the main procedure its does not throws any error. how it works ,Why p2 throws errors? here both p2 and main both are not in package specification.
if main procedure works then p2 also works right?.
even tried to execute main procedure it also throws same errors as p2.
How to execute private procedures? means without package specification.

How to SET NOCOUNT ON/OFF inside a Netezza stored procedure?

Based on NZ documentation, it seems NZSQL equivalent command NO_ROWCOUNT will suppress row count information. But how do I execute/apply it inside a NZ stored procedure?
I've tried to create and executed a NZ SP that contains the command "SET NO_ROWCOUNT" with error "expecting an identifier found a keyword".
My sample code as follows:
CREATE OR REPLACE PROCEDURE MYSCHEMA.MYSP()
RETURNS CHARACTER VARYING(ANY) EXECUTE AS CALLER
LANGUAGE NZPLSQL AS
BEGIN_PROC
DECLARE
iTot INTEGER;
BEGIN
--SET NO_ROWCOUNT;
SELECT COUNT(1) INTO iTot FROM MYSCHEMA.MYTABLE;
RETURN iTot;
END;
END_PROC;
Pls advise.
TQ in advance!

System.Data.SqlClient.SqlException procedure has no parameters and arguments were supplied. How should I go about fixing this error?

I built a database application in Visual Studio. When I run, I get this error:
System.Data.SqlClient.SqlException: procedure sp_select_number_of_films has no parameters and arguments were supplied.
I know what the error means, but I am not sure how to fix it in my SQL code. I have tried a bunch of small tweaks, but I still get the same error.
Stored procedure:
CREATE PROCEDURE [dbo].[sp_select_number_of_films]
(#REC_ID_OUTPUT int OUTPUT)
AS
SELECT COUNT(*)
FROM Film.Title;
EXEC dbo.sp_select_number_of_films
GO
It should be called as:
DECLARE #sth INT;
Exec dbo.sp_select_number_of_films #sth OUTPUT;
But then inside stored procedure you need to assign output variable:
CREATE PROCEDURE [dbo].[sp_select_number_of_films]( #REC_ID_OUTPUT int OUTPUT)
AS SELECT #REC_ID_OUTPUT = COUNT(*)
FROM Film.Title;
And you should avoid naming stored procedures with "sp_" prefix.

Creating Procedures with Transactions using PGAdmin 4

I'm coming from a long history with SQL Server and trying to learn PL/PGSQL. I've recently discovered the PG11 feature CREATE PROCEDURE which allows for internal transactions inside their body.
As a learning exercise, I've created this:
DROP PROCEDURE IF EXISTS test_proc();
CREATE PROCEDURE test_proc()
LANGUAGE plpgsql
AS $$
BEGIN
DROP TABLE IF EXISTS a;
CREATE TABLE a (aid int);
COMMIT;
END;
$$;
call test_proc();
It works fine in PSQL, however when I execute it in PGAdmin 4's Query Tool, it errors with
ERROR: invalid transaction termination
CONTEXT: PL/pgSQL function test_proc() line 5 at COMMIT
SQL state: 2D000
Can someone please explain what's going on? I'm guessing that the PROCEDURE is in fact valid and the issue might be in the query tool might be incorrectly processing the contained COMMIT.
Are there any suggestions for working around this?
Thanks!
In Pgadmin CREATE PROCEDURE as FUNCTION
please try this by Replace PROCEDURE with Function and add Return type also and it will work
DROP FUNCTION IF EXISTS test_proc();
CREATE FUNCTION test_proc()
RETURNS VOID
LANGUAGE plpgsql
AS $$
BEGIN
DROP TABLE IF EXISTS a;
CREATE TABLE a (aid int);
COMMIT;
END;
$$;
Can you please try unchecking auto commit & auto rollback options in pgAdmin4?
You can find drop down near Execute button in the query tool.

Create user through procedure on another database via database link

I'd like to create users through procedure on another database via database link.I am getting error while executing procedure.
Here are the code which i used.
create or REPLACE PROCEDURE hostname
(host_name in varchar2,user_name in VARCHAR2, pass_word in VARCHAR2,
table_space in varchar2,pro_file in varchar2)
as
db_link_name varchar2(30);
begin
select db_link into db_link_name from all_db_links where host=host_name;
EXECUTE IMMEDIATE 'dbms_utility.exec_ddl_statement#'||db_link_name||('CREATE USER '||user_name||' IDENTIFIED BY '||pass_word||'
DEFAULT TABLESPACE '||table_space||' PROFILE '|| pro_file||' ACCOUNT UNLOCK');
EXECUTE IMMEDIATE 'dbms_utility.exec_ddl_statement#'||db_link_name||
('GRANT CONNECT,RESOURCE,EXECUTE_CATALOG_ROLE,Create table,create session,create view,create sequence,create procedure,create job,create synonym TO '||user_name);
end;
/
execute hostname('orcl1','rahul1','rahul','users','default');
Error: ORA-00900: invalid SQL statement ORA-06512: at
"SYS.HOSTNAME", line 6 ORA-06512: at line 1
00900. 00000 - "invalid SQL statement"
*Cause:
*Action:
I think you may have got a little confused by some of the advice provided by the commenter mustaccio. What he meant to say is that the SQL strings in your EXECUTE IMMEDIATE statements need to use PL/SQL blocks in order to call stored procedures.
In other words, instead of writing
EXECUTE IMMEDIATE 'dbms_utility.exec_ddl_statement ... ';
you should write
EXECUTE IMMEDIATE 'BEGIN dbms_utility.exec_ddl_statement ... ; END;';
For your procedure, I would recommend doing introducing a local variable for the strings you are passing to EXECUTE IMMEDIATE. These can be notoriously tricky to get right, and if you've assigned them to a local variable you can easily output them using dbms_output.put_line. In fact, I did exactly this while fixing up the problems in your procedure. I would recommend continuing to do this if you wish to modify or extend your procedure.
Anyway, here's what I ended up with, which appeared to work:
create or REPLACE PROCEDURE hostname
(host_name in varchar2,user_name in VARCHAR2, pass_word in VARCHAR2,
table_space in varchar2,pro_file in varchar2)
as
db_link_name varchar2(30);
l_ddl_sql varchar2(4000);
begin
select db_link into db_link_name from all_db_links where host=host_name;
l_ddl_sql := 'begin dbms_utility.exec_ddl_statement#'||db_link_name||'(''CREATE USER '||user_name||' IDENTIFIED BY '||pass_word||'
DEFAULT TABLESPACE '||table_space||' PROFILE '|| pro_file||' ACCOUNT UNLOCK''); END;';
EXECUTE IMMEDIATE l_ddl_sql;
l_ddl_sql := 'begin dbms_utility.exec_ddl_statement#'||db_link_name||
'(''GRANT CONNECT,RESOURCE,EXECUTE_CATALOG_ROLE,Create table,create session,create view,create sequence,create procedure,create job,create synonym TO '||user_name || '''); END;';
EXECUTE IMMEDIATE l_ddl_sql;
end;
/

Resources