cannot execute store procedure in phpmyadmin - stored-procedures

Error in processing request: No routine with name `selectCategory` found
in database `xxx`.
This is my stored procedure
DELIMITER $$
CREATE DEFINER=`root`#`localhost` PROCEDURE `selectCategory`()
BEGIN
SELECT category_id, name AS display_name
FROM category
ORDER BY name;
END$$
DELIMITER ;
I am trying to run the stored procedure on the phpmyadmin site to check if the other problem I am having is due to php I wrote or the procedure itself, because of that error I cannot check and I do not know how to fix this error.

Is it possible that you are connecting to an instance which does not have the SP? check the db instance contains your SP.

Related

Snowflake procedure is running as caller but not as owner even though both are same

The definition of the procedure is as follows
CREATE OR REPLACE PROCEDURE "EMPLOYEE_TREND_TMP"()
RETURNS VARCHAR(16777216)
LANGUAGE JAVASCRIPT
EXECUTE AS OWNER
AS '
var rs = snowflake.execute( { sqlText:
SELECT count(*) FROM "DATA_MART"."EMPLOYEE"."CCH_EMPLOYEE_COMP" ;
} );
';
The owner of the procedure is HR_ROLE. When I specify "execute as caller" and call the procedure using HR_ROLE, it works fine. But "execute as owner" throws an error:
"Execution error in store procedure EMPLOYEE_TREND_TMP: Stored procedure execution error: Requested information on the current user is not accessible in stored procedure. At Snowflake.execute, line 4 position 21"
This is strange because both the owner and caller of the procedure is HR_ROLE itself.
The query inside the procedure "SELECT count(*) FROM "DATA_MART"."EMPLOYEE"."CCH_EMPLOYEE_COMP" ;" is also running fine using the HR_ROLE.
I want to execute the procedure as owner but I am confused as to why it's throwing an error, when both the caller and the owner are the same exact role (HR_ROLE). I have checked all the privileges and access to objects, everything seems to be in place.
As I see, this error occurs usually happens when accessing information_schema or session parameters. Are you sure that the SP contains only 1 line, and it's just calling this statement? Could there be other statements to access session variables or information schema?
Have you checked the limitations of the Owner’s Rights Stored Procedures?
https://docs.snowflake.com/en/sql-reference/stored-procedures-rights.html#owner-s-rights-stored-procedures

Error while connecting to stored procedure in Tableau

I'm getting this error while trying to connect to a stored procedure as data source:
Unable to complete action
The stored procedure returned no results. The fields don't have column names, or the data in the fields is not a supported data type
But the same stored procedure returns data in database. Any idea on this?
Please try adding the SET NOCOUNT ON code in the beginning of the stored procedure.
Something like
CREATE PROCEDURE [dbo].[ZZZ_THIS_IS_MY_SP]
#p INT
AS
BEGIN
SET NOCOUNT ON
DECLARE #Var1 NVARCHAR(20)
DECLARE #Var2 DATETIME
-- All other instructions...
END

Unable to create a Stored procedure in Redshift Aginity and aginity pro

Trying to create the stored procedure in redshift aginity workbench but it through an error like 'unterminated dollar-quoted string at or near "$$
'
In amazon, they already gave the solution for this
https://docs.aws.amazon.com/redshift/latest/dg/stored-procedure-create.html
particular client tool only supported to create the stored procedure.
I want to conform aginity don't have the option to create this?
and
Which is the best tool to create stored-procedure?
CREATE OR REPLACE PROCEDURE staging.test_sp1(f1 int, f2 varchar)
AS $$
BEGIN
RAISE INFO 'f1 = %, f2 = %', f1, f2;
END;
$$ LANGUAGE plpgsql;
You can create RedShift stored procedures in Aginity Pro by using Run Batch. Full support will be in the 9/16 release.
Aginity need to update their tool to pass the dollar quoted procedure body to Redshift correctly. I note that Aginity is able to execute the procedure with CALL staging.test_sp1().
Some other tools have already been updated to allow creation and you can always use psql to create the procedure.

DB2 stored procedure razor sql

I'm trying to create a stored procedure in a DB2 database using RazorSQL Client but I'm getting this error:
Blockquote
ERROR: A character, token, or clause is invalid or missing.
DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=SELECT
The stored procedure code is:
CREATE PROCEDURE GENERAL.sp_checkemp
(IN emp_code VARCHAR(20))
LANGUAGE SQL
READS SQL DATA
BEGIN
SELECT "name_emp" FROM GENERAL."employee" WHERE "code_emp" = 'abc';
END
SELECT statements in the SQL PL context must have an INTO clause -- you have to put the query results somewhere. If your query returns more than one row, which I suspect it is, you must use a cursor instead.

Call one stored procedure to another stored procedure in DB2

Problem that I was facing is that I have to call one stored procedure from another stored procedure in DB2 database. Kind example that I am giving right below.
I have one stored procedure:
CREATE OR REPLACE PROCEDURE Proc1()
IS
Declare myName in varchar;
BEGIN
Select fname into myName from student where fname='x'; // is returning unique value
-- here call anoher proc2
END;
Now so this proc1 procedure is going to call this proc2 procedure.
Now I have second stored procedure:
CREATE OR REPLACE PROCEDURE Proc2(Name in varchar)
IS
BEGIN
-- do anything
END;
I solved this problem,
So solution is like If we want to execute proc using sql command then syntex is like below,
call Proc2('My Name');
We can use this same approach inside our proc also.
For that we have to follow some steps. Lets say that our above sql call is statement that we want to execute. we are going to convert that statement into String and pass necessary parameter by concating variable values. Then execute statement.
CREATE OR REPLACE PROCEDURE Proc1()
IS
Declare myName in varchar;
-- stmt variable is to execute our proc
STMT VARCHAR(4000);
BEGIN
Select fname into myName from student where fname='x'; // is returning unique value
-- this is our logic
STMT :='call Proc2('||myName||')';
EXECUTE IMMEDIATE STMT;
END;

Resources