Oracle refresh materialized view - Compile error - oracle

Im trying to execute a refresh on a materialized view, but I cant get the script to compile.
CREATE OR REPLACE PROCEDURE REFRESH_MV AS
BEGIN
exec DBMS_MVIEW.REFRESH('my_mat_view_mv','C');
END REFRESH_MV;
I get the message:
ORA-06550: line 3, column 9:
PLS-00103: Encountered the symbol
"DBMS_MVIEW" when expecting one of the
following:
:= . ( # % ; immediate The symbol
":=" was substituted for "DBMS_MVIEW"
to continue.
Am i doing something wrong ? Need to import anything?
Update
CREATE OR REPLACE PROCEDURE REFRESH_MV AS
BEGIN
EXECUTE DBMS_MVIEW.REFRESH('my_mat_view_mv','C');
END REFRESH_MV;
(S1917) Expecting: ( ; #
IMMEDIATE
CREATE OR REPLACE PROCEDURE REFRESH_MV AS
BEGIN
EXECUTE IMMEDIATE DBMS_MVIEW.REFRESH('my_mat_view_mv','C');
END REFRESH_MV;
Warning: compiled but with compilation errors
This is an Oracle 10g XE, hope thats no problem.
Thanks in advance !

I think if you just eliminate the "exec" altogether it might work better. "exec" is a SQL*Plus command. IOW, try:
CREATE OR REPLACE PROCEDURE REFRESH_MV AS
BEGIN
DBMS_MVIEW.REFRESH('my_mat_view_mv','C');
END REFRESH_MV;

Related

ORA-00900: invalid SQL statement - Call procedure inside another

I create procedure which call procedure inside another. I have an error ORA-00900: invalid SQL statement.
CREATE OR REPLACE PROCEDURE AP_MOVE_OUT
is
BEGIN
EXECUTE IMMEDIATE 'AP_MOVEOUT_COUNT(''GNW-M2'',to_date(''2020-11-02'',''yyyy-MM-dd''),to_date(''2020-11-06'',''yyyy-MM-dd''),''ast'');';
END;
/
Procedure compiled without any error, but when I run it:
BEGIN
AP_MOVE_OUT;
END;
/
I've got an error: ORA-00900: invalid SQL statement
ORA-06512: at "DEVUSER.AP_MOVE", line 4
ORA-06512: at line 2
00900. 00000 - "invalid SQL statement"
When I execute procedure AP_MOVEOUT_COUNT outside procedure AP_MOVE_OUT it works correctly, so I can't find the reason of these error. Here is the example that works for me outside procedure AP_MOVE_OUT:
EXEC AT_MOVEOUT_COUNT('GNW-M2',to_date('2020-11-02','yyyy-MM-dd'),to_date('2020-11-06','yyyy-MM-dd'),'ast');
Expression called by execute immediate should be a valid sql or pl/sql statement. In your case the statement is not complete. Transforming it to a complete anonymous pl/sql block should solve the problem.
create or replace procedure AP_MOVE_OUT
is
BEGIN
execute immediate 'begin AP_MOVEOUT_COUNT(''GNW-M2'',to_date(''2020-11-02'',''yyyy-MM-dd''),to_date(''2020-11-06'',''yyyy-MM-dd''),''ast''); end;';
END;
See also simple example on fiddle
Also consider using bind variables instead of concatenating values into the code.
You don't need to use EXECUTE IMMEDIATE to call a stored procedure from another. You also don't use EXEC or any other keyword.
You've said that
exec AT_MOVEOUT_COUNT('GNW-M2',to_date('2020-11-02','yyyy-MM-dd'),to_date('2020-11-06','yyyy-MM-dd'),'ast');
works, so I would expect the following procedure to work too:
create or replace procedure AP_MOVE_OUT
is
BEGIN
AT_MOVEOUT_COUNT('GNW-M2',to_date('2020-11-02','yyyy-MM-dd'),to_date('2020-11-06','yyyy-MM-dd'),'ast');
END;

calling stored procedure with cursor and out parameter

I have the following stored procedure
CREATE OR Replace PROCEDURE sprocvPOP_GetvemployeeByFilter
(TheFilter varchar2,
TheOrder varchar2,
PageOrder int,
ItemsPerPage int,
TheCount out number,
cur out sys_refcursor)as
begin
........
end
I want to call this procedure, and print cur parameter and the count parameter values because they are out variables.
I tried using the following syntax in SQL Developer
set serveroutput on
var rc refcursor;
declare
mycount number(19);
begin
execute sprocvPOP_GetvemployeeByFilter (NULL,NULL,1,10,mycount,:rc);
print rc;
dbms_output.put_line(mycount);
end;
but I got the error
PLS-00103: Encountered the symbol "RC" when expecting one of the following:
:= . ( # % ;
The symbol ":=" was substituted for "RC" to continue.
How can I execute this procedure and print out parameters in SQL Developer?
To answer your original question, print rc is a SQL*Plus command, so it needs to be outside the PL/SQL block. execute is also a SQL*Plus command and is not used in PL/SQL. So your code should look like this:
set serveroutput on
var rc refcursor;
declare
mycount number(19);
begin
sprocvPOP_GetvemployeeByFilter (NULL,NULL,1,10,mycount,:rc);
dbms_output.put_line(mycount);
end;
/
print rc;
However, it turns out you are using SQL Developer not SQL*Plus client to run your code. Not many SQL*Plus commands are natively supported in SQL Developer. The list is here.
The latest versions of the tool come with a Command Line interface which is very neat. Find out more.
Alternatively, use the built-in Run PL/SQL functionality as described in this tutorial

Using Variable- Oracle

In the above code, I am giving schemaname as input and using that input it should connect to the database. But In this case the value i entered is not taken by the schemaname. This is how the out put and the error is:
declare schemaname varchar2(20);
exec :schemaname := XYZ;
BEGIN
end;
Error report -
ORA-06550: line 2, column 6:
PLS-00103: Encountered the symbol "" when expecting one of the following:
constant exception <an identifier>
<a double-quoted delimited-identifier> table long double ref
char time timestamp interval date binary national character
nchar
ORA-06550: line 4, column 1:
PLS-00103: Encountered the symbol "CONNECT" when expecting one of the following:
Could any one suggest how to make it work using spool
the code between declare and end is PL/SQL. Commands like CONNECT or SPOOL are SQL*Plus commands. You cannot use SQL*Plus commands in a PL/SQL block.
In your case you don't need PL/SQL at all:
Create a script with following content
connect &1
spool C:\ABC
#c:\ABC
spool off;
and run it
#your_script_name
BTW: there is no reason to run script c:\ABC while you are spooling into it. What exactly do you want to achieve?
exec[ute] is SQL*Plus and SQL Developer (and maybe other clients) shorthand for an anonymous block. It is a client command, it is not part of PL/SQL. You are trying to use it inside a PL/SQL declare section, where it is not valid or recognised.
If you want a client bind variable you need the var[iable] command:
var schemaname varchar2(20);
exec :schemaname := '&1';
BEGIN
...
Notice the single quotes around &1, as it's being assigned to a string variable.
But you can't connect inside a PL/SQL block either, and you can't use a bind variable for the connection.
connect :schemaname
will prompt for a password (even if you defined it's value as user/passwd) and try to connect as a user lieterally called :schemaname.
You can use a substituion variable, but you don't really need to define a new one; as you seem to be passing the credentials in, you can do:
connect &1
(without surrounding quotes)

Oracle Trigger Error for updating timestamp field before update & insert

I am creating a trigger on a Table Name ADM I added a field
UPD_DATETIME TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP NOT NULL;
Following is my trigger code
create or replace trigger TRG_UPD_DATETIME
before insert or update
on adm
FOR EACH ROW
declare
begin
:NEW.UPD_DATETIME:=CURRENT_TIMESTAMP;
end TRG_UPD_DATETIME;
I am getting following error's when I am trying to compile:
Error(12): PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: ; The symbol ";" was substituted for "end-of-file" to continue.
Lose the DECLARE .. you don't need that in there.
http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/triggers.htm#LNPLS99955

"unknown command" for dbms_lob.open command in Sql+

I am a total beginner when it comes to PL/SQL and Sql+. I am trying to write a function that will extract the contents of a text file into a CLOB (following this as an example). When I issue the following command in Sql+:
dbms_lob.open( 'c:\temp\test.txt', dbms_lob.lob_readonly );
I get the following error message:
SP2-0734: unknown command beginning "dbms_lob.o..." - rest of line ignored.
Is there something wrong with the syntax of the command, or something else entirely?
Thanks much!
I'm not an expert in oracle. For me the problem is that for launch this command in sqlplus you may declare an anonymous block like this:
DECLARE
-- variables
BEGIN
--- your commands here
dbms_lob.open......
END;
To launch the execution you have to digit / and then return

Resources