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;"
Related
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
The breakpoints not match the code line when debug in SQL Server 2008 R2. Sometimes when hit the breakpoints,but not executing the right code line.How to fix it?
declare #SharedTable table(Num int,Name nvarchar(50))
Insert into #SharedTable(Num,Name) values('27149','Vader')
declare #numShared int=0;
select #numShared = COUNT(Num) from #SharedTable
declare #idx_Shared int =1
while #idx_Shared<=#numShared
begin
declare #Num int;declare #Name nvarchar(50)
select #Name=Name,#Num=Num from #SharedTable
declare #AllSharers nvarchar(max)=''
set #AllSharers+=('Num:'+Cast(#Num as nvarchar)+' '+'Name:'+#Name+CHAR(10))
set #idx_Shared+=1
end
print #AllSharers;
Very simple code copy from my query.
Every time the debug pointer step to line select #Name=Name,#Num=Num from #SharedTable,it'll ignore the code below in the 'while' loop, and from then on all the code below and breakpoints begin to mismatch.
Copy it to a new query,the problems still are there,but typed the content the same in a new query,the problem gone.
SQL Server will report the line of code a given statement started on when reporting an error or hitting a breakpoint. Thus, if you have something like this:
SELECT *
FROM [tableName]
WHERE 1 = 'text'
If you place the breakpoint on line 3, SQL Server is going to break at line 1 (and report that the error occurred on line 1 when you continue), because the statement did, in fact, start on line 1, and whitespace is irrelevant in SQL.
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.
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.
I'm trying to update a package in Oracle, coming from SQL Server this has been confusing.
I have written a batch file that runs the .spec file first and the .body file second, but even running it manually does not work.
I use this syntax:
sqlplus username/password#databasename #c:\temp\myfile.spec
sqlplus username/password#databasename #c:\temp\myfile.body
When I go back to Sql Developer I can look at the stored procedures in the package and see that they have not been updated.
Why aren't my packages getting updated?
The spec and body files need to have / make SQL*Plus create/replace the object.
Without the /:
CREATE OR REPLACE PACKAGE TEST12_13 AS
PROCEDURE TEST12_13;
END;
STAGE#DB>#C:\TEST.PKS
6
With the /:
CREATE OR REPLACE PACKAGE TEST12_13 AS
PROCEDURE TEST12_13;
END;
/
STAGE#DB>#C:\TEST.PKS
Package created.
In reply to your comment about passing filename as parameter, instead of passing the filename as parameter, have SQL*Plus ask you for the filename
wrapper.sql
ACCEPT filename_var Prompt 'Enter filename'
#c:\temp\&filename_var
/
#c:\temp\&filename_var
/
Connect to SQL*Plus with
sqlplus username/password#databasename
Then run the script from the SQL*Plus prompt:
set echo on
#c:\temp\myfile.spec
You should be able to see whats going on like this, including any error messages.