PLS-00103: Encountered the symbol "CREATE" - oracle

What is the problem with this package as it is giving an error?
CREATE OR REPLACE PACKAGE PKG_SHOW_CUST_DETAILS
AS
PROCEDURE SHOW_CUST_DETAILS( myArg VARCHAR2);
END PKG_SHOW_CUST_DETAILS;
CREATE OR REPLACE PACKAGE BODY PKG_SHOW_CUST_DETAILS
AS
PROCEDURE SHOW_CUST_DETAILS(myArg VARCHAR2)
IS
BEGIN
DBMS_OUTPUT.PUT_LINE(myArg);
END SHOW_CUST_DETAILS;
END PKG_SHOW_CUST_DETAILS;
/
On compilation of the above script, I am getting the following errors:
SQL> show errors
Errors for PACKAGE PKG_SHOW_CUST_DETAILS:
LINE/COL ERROR
-------- -----------------------------------------------------------------
6/1 PLS-00103: Encountered the symbol "CREATE"
The package is very simple and I am not able to compile it. I searched earlier answers on this error message and none of them did solve my problem.
I am consistently getting this error for 2 more packages and I am stuck on this error message no matter what I do. I even tried to strip everything to the barest minimum as shown above, but the error message does not seem to go away.
BTW I am executing this on command line SQL plus session after logging into my Oracle 11G database.
YES- SET SERVEROUTPUT ON -- is executed and the error message has nothing to do with this command.
What am I missing?

At line 5 there is a / missing.
There is a good answer on the differences between ; and / here.
Basically, when running a CREATE block via script, you need to use / to let SQLPlus know when the block ends, since a PL/SQL block can contain many instances of ;.

For me / had to be in a new line.
For example
create type emp_t;/
didn't work
but
create type emp_t;
/
worked.

In my case EXECUTE IMMEDIATE ('CREATE TABLE ...') works, for example:
DECLARE
  myVar INT;
BEGIN
SELECT 2 INTO myVar FROM dual;
IF myVar > 1 THEN
   EXECUTE IMMEDIATE('Create Global Temporary Table TestTemp ( id VARCHAR2(2) ) ON COMMIT PRESERVE ROWS');
END IF;
END;
Reference to Create Table As within PL/SQL?

Run package declaration and body separately.

Related

Oracle command works in database but not in SQLPlus

I'm currently trying to implement a bash script that runs at the end of the day that runs a simple oracle query. The command works just fine in Oracle but when inside a .sql file it does not run.
I've attempted to put all of the code on one line and adding semicolons.
Contents of batch file (with user/pass altered):
sqlplus username/password#database #set_changed.sql
Contents of set_changed.sql file:
UPDATE ris_web a
SET a.changed = 0
where exists
(
select modified_date from invn_sbs b
where b.item_sid = a.item_sid
and b.modified_date <= sysdate-1
);
COMMIT;
END;
In SQLPlus you should use a / on a separate line to terminate an SQL statement or PL/SQL block instead of using a semicolon, so change your file to
UPDATE ris_web a
SET a.changed = 0
where exists
(
select modified_date from invn_sbs b
where b.item_sid = a.item_sid
and b.modified_date <= sysdate-1
)
/
SHOW ERRORS
/
COMMIT
/
SHOW ERRORS
/
END
You might also want to have a look at this question
You have end; command at the end of the script but no BEGIN for it.
Simply replace the END; with /
The original syntax was correct. There were uncommitted changes in sqldeveloper that were causing the .sql file to never finish running. Thank you everyone for your help.

Oracle - can not declare variables

I have strange problem, which I cannot find solution...
I am trying to check how syntax in Oracle works, just to get started, but I can't get even started, because I get:
Incorrect syntax near the keyword 'declare'.
This is what I am trying to execute:
declare log varchar(100);
begin
log := 'abc';
log := log || LENGTH(log);
dbms_output.put_line(log);
end;
Also tried
declare log varchar(100) := '';
None worked... What is the right syntax?
EDIT
Worth mentioning: I am connected to SQL Server engine.

DBMS_OUTPUT.PUTLINE in spooled log file? [duplicate]

This question already has an answer here:
PL/SQL procedure succesfully completed but shows nothing
(1 answer)
Closed 8 years ago.
I have created package like this:
create or replace package test_package is
procedure ShowDate;
end test_package;
/
create or replace package body test_package is
PROCEDURE ShowDate
IS
begin
dbms_output.put_line(to_char(sysdate,'YYYY-MM-DD HH24:MI:SS'));
END ShowDate;
end test_package;
/
I'd like to run this package using sqlplus and have result (SYSTDATE) stored in a log file.
I've created a file ShowDate.sql containing:
call test_package.showdate()
I've tried ro run in as:
sqlplus user/password#server
spool ShowDate.log
#ShwoDate.sql
spool out.
But the onlu result I can see is: Call completed.
I have also tried modification of ShowDate.sql :
begin
test_package.showdate;
end;
/
but then I get PL/SQL procedure successfully completed.
Can anyone help?
Regards
Pawel
You need this line in your SQL*Plus script (before the procedure call):
set serveroutput on

calling exist/not exist package dynamically

I have a PL/SQL package as following (A piece of code):
if(IsRegisterMode)
num_result := kwp_gep.register(var_name,var_family, bool_is_incomming);
My problem is : in some environment kwp_gep package exist and IsRegisterMode flag is true so kwp_gep.register called but in another environment kwp_gep package don't exist(not necessary) and IsRegisterMode flag is false.
With above explanation in second environment main package doesn't compile and show error : kwp_gep does not exist.
My question is: What is solution for this problem? I think exist a solution for dynamically execute kwp_gep procedures.
EDIT:
kwp_gep.register has a number as return value and bool_is_incomming and boolean.
Option 1: Conditional Compilation
You could use conditional compilation, e.g.
$IF $$isregistermode $THEN
kwp_gep.register(var_name,var_family);
$ENDIF
When you compile the package, you'd do something like this in the environments where the package exists:
ALTER SESSION SET PLSQL_CCFLAGS = 'isregistermode:true'
Option 2: Dynamic execution
if IsRegisterMode then
execute immediate 'kwp_gep.register(:var_name,:var_family)'
using var_name, var_family;
end if;
Option 3: Stub
(as per Egor's suggestion) in the environments that don't have kwp_gep.register, create a stub that never gets called, e.g.
CREATE OR REPLACE PACKAGE kwp_gep IS
PROCEDURE register (var_name in varchar2, var_family in varchar2);
END kwp_gep;
Note that it has no package body, so it will never execute without error. In your case it doesn't matter since your flag ensures it won't get called. If it does, then you know there's a problem in that environment.

Oracle procedure call fails from jdbc

We have a procedure declared in an oracle package with name x_pkg.proc_name. When called from jdbc through java.sql.Statement.execute("BEGIN x_pkg.proc_name; END;"); the call fails with an error
java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00201: identifier 'x_pkg.proc_name' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
The above error indicates that the procedure is not declared in the given package.
The jdbc call surprisingly succeeds if I rename the procedure to x_pkg.proc_name_something. This seems very strange. I tried deleting the procedure declaration and its body and re-adding it but I get the same error.
Any suggestions on troubleshooting this further?
Note - the procedure call succeeds always through pl-sql code. It just fails when executed through jdbc.
Update :
It procedure call succeeds if I prefix it with the schema name like "BEGIN schema_name.x_pkg.proc_name; END;"
Any idea when should the schema name be prefixed and when is it not required?
Update :
The actual package name is "COMMONS_UTILS" and the procedure name is "SET_SESSION_NLS_PARAMS". The call "BEGIN COMMONS_UTILS.SET_SESSION_NLS_PARAMS; END;" fails when made through JDBC. It works if I rename the procedure name to "SET_SESSION_NLS_PARAMSX".
Update :
The procedure call works if I compile it before executing it.
"BEGIN EXECUTE IMMEDIATE 'ALTER PACKAGE COMMONS_UTILS COMPILE'; COMMONS_UTILS.SET_SESSION_NLS_PARAMS; END;"

Resources