How to fix Unresolved Reference Error - sql

I have an error message that states: "Procedure [schemaName].[my_proc] has an unresolved reference to object [dbo].[callingProc]. I searched the web, but there doesn't appear to be many solutions. Do you have any suggestions? My Code looks something like the following:
create procedure schemaName.[my_proc]
as
begin
declare #variable int 0;
exec dbo.callingProc
#variable;
end;

What message is trying to tell you is that there is no [dbo].[callingProc] procedure in your database.
Reason for this might be as simple as typo, or callingProc might be under different schema than dbo.

I did a little more research and found the solution!
The dbo.callingProc and schemaName.[my_proc] were under different schema names. I went into the Database and changed the dbo.callingProc "Build Action" to "Build." The dbo.callingProc was not getting compiled, so it produced the reference error because the procedure could not be found.

Related

plsql : New function inside an existing package compilation and syntax check

How do I compile a new function created inside a package in plsql, to see syntactical error and so on
You can't compile a single function - compile the whole package.
If your concern is about invalidating the whole package in case that function has errors, then
create a standalone function (i.e. outside of the package)
debug it
once it is OK (doesn't have syntax errors, returns result as expected), include it into the package
In addition to #Littefoot's advise I'd say: use a proper GUI. Oracle has a free tool called sql developer. It has a great interface for editing database objects (packages/functions/procedures/triggers). It highlights errors and is very well documented (https://www.thatjeffsmith.com/sql-developer/). Note that is does not point out syntax errors - but once you're a bit used to working with pl/sql they become obvious very quickly.
In Oracle, after compiling a procedure/function/package. If there is an error then the command will return with the message:
ORA-24344: success with compilation error
You can then use:
SHOW ERRORS
or
SELECT * FROM USER_ERRORS;
or, for example, for errors with packages in a specific schema:
SELECT *
FROM ALL_ERRORS
WHERE owner = 'SCHEMA_NAME'
AND type IN ( 'PACKAGE', 'PACKAGE BODY');
Which will list the errors (complete with line numbers and error messages) and you can then debug the procedure/function/package and recompile it.
fiddle

How to Call package successfully

got error when calling package
error is
Error starting at line : 1 in command -
PKG_Generate_GRNo.GenerateGR(TO_NUMBER(:P164_APP_ID,
'9999999'),:APP_USER,:P164_FIRST_NAME,:P164_LAST_NAME,:P164_EMAIL,:P164_SKYPE_ID,:P164_COUNTRY,:P164_DATE_OF_BIRTH)
Error report - Unknown Command
PKG_Generate_GRNo.GenerateGR(TO_NUMBER(:P164_APP_ID,
'9999999'),:APP_USER,:P164_FIRST_NAME,:P164_LAST_NAME,:P164_EMAIL,
:P164_SKYPE_ID,:P164_COUNTRY,:P164_DATE_OF_BIRTH);
Session state protection violation is definitely an Apex error, relating to your page settings. It seems your package is trying to change the state of a read-only page. See this other question.
The item identifier in the error message P164_COURSECOUNT has the same prefix as the parameters you pass to the package (:P164_APP_ID) so presumably they relate to the same page. We know nothing about your application or its architecture, so it's hard to offer concrete advice. Maybe you need to change the page or item settings, maybe you need to change what the package does. Only you can tell the right course of action.
As you didn't post the whole command, a note: you have to enclose it into begin-end block, e.g.
BEGIN
PKG_Generate_GRNo.GenerateGR (TO_NUMBER ( :P164_APP_ID, '9999999'),
:APP_USER,
:P164_FIRST_NAME,
:P164_LAST_NAME,
:P164_EMAIL,
:P164_SKYPE_ID,
:P164_COUNTRY,
:P164_DATE_OF_BIRTH);
END;
/

Initialize / activate SQL prior to GET DIAGNOSTICS

I have two service programs: mySrvPgm and myErr
mySrvPgm has a procedure which contains:
/free
...
exec sql INSERT INTO TABLE VALUES(:RECORD_FMT);
if sqlError() = *ON;
//handle error
endif;
...
/end-free
myErr has a procedure sqlError:
/free
exec sql GET DIAGNOSTICS CONDITION 1
:state = RETURNED_SQLSTATE;
...
/end-free
Background info: I am using XMLSERVICE to call the given procedure in mySrvPgm from PHP. I am not using a persistent connection. myErr is bound-by-reference via a binding directory used by mySrvPgm. Its activation is set to *IMMED, its activation group is set to *CALLER.
The problem: Assume there is an error on the INSERT statement in mySvrPgm. The first time sqlError() is called it will return SQLSTATE 00000 despite the error. All subsequent calls to sqlError() return the expected SQLSTATE.
A workaround: I added a procedure to myErr called initSQL:
/free
exec sql SET SCHEMA MYLIB;
/end-free
If I call initSQL() before the INSERT statement in mySrvPgm, sqlError() functions correctly. It doesn't have to be SET SCHEMA, it can be another GET DIAGNOSTICS statement. However, if it does not contain an executable SQL statement it does not help.
The question: I believe the myErr service program is activating properly and has the correct scope, but I am wondering if there is something more I need to do to activate the SQL part of it. Is there some way to set it up so SQL auto-initializes when the service program is activated, or do I have to execute an unneeded SQL statement in order to get it started?
There is some more background information available here.
Thank you for reading.
What version an release of the OS? Are you upto date on PTFs?
Honestly, seems to me that it's possibly a bug. Or the manual(s) need clarification.. I'd open a PMR.

updateblob fails in Powerbuilder

In Powerbuilder I am trying to update a table (Oracle) with blob but get sqlerror, "Database statement must refer to blob variable". My declaration and updateblob statements are as follows:
blob lblob_newxml
long llong_subid
UPDATEBLOB RP_XML_FORMS SET XML_DOC = :lblob_newxml
WHERE SUBMISSION_ID = :llong_subid
USING SQLCA;
Does anybody know why it is happening and or how to solve this problem? Thanks.
To get more information on this problem and the possible causes, I'd run with one of the database traces turned on. (You can check out database trace options in the Connecting to Your Database manual; link may not be appropriate for your PB version, which you haven't mentioned yet.) This may or may not tell you more, but it tracks everything between the app and when the PB drivers pass the commands "over the wall" to the database's driver.
Good luck,
Terry.
"The PowerBuilder VM can get the SQL syntax for the following types of errors, and passes it to the Transaction object’s DBError event for the following types of errors: ..." (see this page).
If your lblob_newxml is null then use this update statement instead:
UPDATE RP_XML_FORMS SET XML_DOC = NULL
WHERE SUBMISSION_ID = :llong_subid
USING SQLCA;

What does "%%DatabaseEx" do in TSQL?

I was looking at the source of sys.sp_dbcmptlevel in SQL Server 2005.
In the source, there is this line I do not understand how it works.
EXEC %%DatabaseEx(Name = #dbname).SetCompatibility(Level = #input_cmptlevel)
It doesn't appear that DatabaseEx is a stored procedure.
-- does not return any result
select *
from sys.procedures
where [name] like '%DatabaseEx%'
So my questions are
What is DatabaseEx and what does it do?
What is %% before DatabaseEx?
I think the best answer here is that it's not documented, and not supported, so don't rely on it. While it's interesting to know how SQL Server works internally, anything you do with that knowledge has the potential to break in a future hotfix, service pack or release.
Interesting find.
System SP's also refer to %%Object, %%Relation, %%ColumnEx, %%LinkedServer, %%Owner, %%CurrentDatabase(), %%ErrorMessage, %%Module, %%DatabaseRef, %%LocalLogin, %%Alias, %%ServerConfiguration, %%IndexOrStats, %%ScalarType (etc)
My interpretation is that the %%() retrieves some kind of (COM?) object based on filter criteria, followed by a method call.
-- Note: database #dbname may not exist anymore
-- Change compatibility level
-- If invoke gets error, exception will abort this proc.
EXEC %%DatabaseEx(Name = #dbname).SetCompatibility(Level = #input_cmptlevel)
it looks like a way to refer to a variable database as an object and make config changes