I have a procedure that identifies each locked
account that was locked because of invalid login attempts. However the sp is creating with compilation errors: "ORA-00942: table does not exist". If I run the select statement by itself it works fine but within the sp. Can anyone help?
Create or replace PROCEDURE IdentifyLockedAccounts(p_recordset OUT SYS_REFCURSOR) AS
BEGIN
OPEN p_recordset FOR SELECT USERNAME FROM DBA_USERS WHERE ACCOUNT_STATUS = 'LOCKED' OR ACCOUNT_STATUS = 'LOCKED(TIMED)';
END IdentifyLockedAccounts;
/
Your schema probably has SELECT privilege on DBA_USERS via some role (SELECT_CATALOG_ROLE for instance) - that is why you are able to run it via SQL client.
Roles are not enabled during the compilation of plsql/views therefore you have to grant SELECT ON DBA_USERS directly to schema to be able to use it in stored procedure.
GRANT SELECT ON DBA_USERS to YOURSCHEMA;
Related
it's possible to define an alias for a stored procedure (sql-native)?
In the documentation, reference is made only to: SEQUENCE and TABLES
1) CREATE PROCEDURE OWXXCOLL.STORED1()
2) CREATE ALIAS DB2C.STORED1 FOR OWXXCOLL.STORED1;
3) CALL DB2C.STORED1();
EDIT 2021-05-14
The original question arises for the following problem (I was hoping to get away with using aliases)
Intro
I have defined a native SP
The OWXXCOLL schema is the same one I also use for tables/index...
(I noticed that the tables also have different aliases)
CREATE PROCEDURE OWXXCOLL.STORED1(...)
LANGUAGE SQL
ISOLATION LEVEL CS
WLM ENVIRONMENT FOR DEBUG MODE WLMENV1
ALLOW DEBUG MODE
BEGIN
...
END#
I also modified the cobol program (name:PGMSTO1) to call the Stored with the CALL statement (without qualifier)
EXEC SQL
CALL STORED1 (...)
END-EXEC.
The problem
The various table accesses (SELECT) work correctly BUT When I run the PGMSTO1 the call to the Stored ends with sqlcode -440
NO AUTHORIZED PROCEDURE BY THE NAME STORED1 HAVING COMPATIBLE ARGUMENTS WAS FOUND<
The error comes from the fact that it is not using the owner OWXXCOLL but DB2C (DB2C is user who scheduled the jcl/batch)
If I enter the qualifier (OWXXCOLL) the call it's OK.
I don't understand what to check and what configurations are missing.
Thanks
The cobol program (PGMSTO1) that calls the stored procedure has the following BIND parameters:
COLLID NAME OWNER CREATOR QUALIFIER DYNAMICRULES PATHSCHEMAS
OWXXCOLL PGMSTO1 DB2C DB2C FPXX B "DB2C"
"DB2C" path is used to resolve unqualified stored procedure
I will need to modify the bind parameter "PATH".
I will try to ask to add my schema as well (OWXXCOLL)
PATH("OWXXCOLL","DB2C")
CREATE OR REPLACE PROCEDURE wh.sp_schema.my_sp(arg1 STRING, arg2 STRING)
RETURNS VARCHAR(16777216)
LANGUAGE JAVASCRIPT
AS
$$
stmt = snowflake.createStatement(
{sqlText: `CREATE OR REPLACE TABLE wh.table_schema.RAW_`+arg2+`_`+arg1+` LIKE wh.temp_schema.RAW_`+arg2+`_TEMPLATE`}
);
rs = stmt.execute();
rs.next();
output = rs.getColumnValue(1);
return output;
$$
;
when i create the above stored procedure - below message is displayed
Function my_sp successfully created.
when i run the stored procedure from the worksheet using
CALL my_sp('2018','abc');
I see the below error:
SQL compilation error: Invalid identifier my_sp
I even tried running using fully qualified name for the stored procedure:
CALL wh.sp_schema.my_sp('2018','abc');
I still see the below error:
SQL compilation error: Invalid identifier my_sp.
Also, i would like to know a command to see if my stored procedure has been created or not.
I've looked in the snowflake UI, under 'wh" warehouse and "sp_schema" schema, but could not see anything(stored procedures) other than tables.
This is a simple case of a grants issue. As SECURITYADMIN, if you apply the necessary grants to the role you're using,
GRANT USAGE ON DATABASE wh TO ROLE <role>;
GRANT USAGE ON SCHEMA wh.sp_schema TO ROLE <role>;
GRANT USAGE ON ALL PROCEDURES IN SCHEMA wh.sp_schema TO ROLE <role>;
you'll get past this ambiquous error and get to the next real error
JavaScript execution error: Uncaught ReferenceError: arg2 is not defined in MY_SP
Which is due to javascript SP parameters being case sensitive, so you need to modify the code as follows (change arg to ARG):
{sqlText: `CREATE OR REPLACE TABLE wh.table_schema.RAW_`+ARG2+`_`+ARG1+` LIKE wh.temp_schema.RAW_`+ARG2+`_TEMPLATE`}
Snowflake does not support Stored Procedures. They are implementingjavascript` based APIs for it, but it's still in draft mode.
Here's the link to their APIs (Note Draft Document is written on right hand side).
and here's the link to a ticket on their support forum where they've confirmed it.
There are two obvious possibilities why this may go wrong:
You've implicitly donated the procedure ownership to a ROLE you don't have
There is now a mismatch between the procedure and call type signatures. Verify that there is a wh.sp_schema.my_sp(STRING, STRING) and that your call is like CALL wh.sp_schema.my_sp('2018'::STRING,'abc'::STRING);
Try to solve the error by following query syntax.
CALL database_name.schema.MY_SP('database_name','schema');
I am using MariaDB 10.0.20.
I do have one database e.g. "Db1", and have one stored procedure under this database named as "SP1". I created one user "user1" as:
GRANT ALL ON DB1.* to user1#'%' identified by '';
Now the problem is that, using this user I am not able to execute Stored procedure and it is returning below error:
ERROR 1370 (42000): execute command denied to user
I've execute the GRANT EXECUTE on user1 as well, but still no luck.
The Security_type of procedure was set to "DEFINER", and later changing to "INVOKER" it didn't help.
Is there any issue with the Grants or SP ? Or its some bug with MariaDB?
Got resolution :).
EXECUTE GRANT For stored Procedure is something like :
GRANT EXECUTE ON Procedure DB1.SP1 to user1;
I tried to install orchard CMS the from source code. I opened it in VS 2012, and I m using Sql Server 2012.
I am geting the following error.
error text:
Setup failed: could not execute query
[ select rolerecord0_.Id as Id13_, rolerecord0_.Name as Name13_ from Test_Orchard_Roles_RoleRecord rolerecord0_ where rolerecord0_.Name=#p0 ]
Name:p1 - Value:Anonymous
[SQL: select rolerecord0_.Id as Id13_, rolerecord0_.Name as Name13_ from Test_Orchard_Roles_RoleRecord rolerecord0_ where rolerecord0_.Name=#p0]
I cant find any solution for this error. Where did I go wrong? How can I fix this error? When I choose built-in storage, it runs. Also, are there any disadvantages if I use the built-in one?
UPDATE (new error message)
Setup failed: could not execute query [ SELECT TOP (#p0) this_.Id as
Id17_2_, this_.Number as Number17_2_, this_.Published as
Published17_2_, this_.Latest as Latest17_2_, this_.Data as Data17_2_,
this_.ContentItemRecord_id as ContentI6_17_2_, contentite1_.Id as
Id16_0_, contentite1_.Data as Data16_0_, contentite1_.ContentType_id
as ContentT3_16_0_, contenttyp4_.Id as Id18_1_, contenttyp4_.Name as
Name18_1_ FROM Orchard_Framework_ContentItemVersionRecord this_ inner
join Orchard_Framework_ContentItemRecord contentite1_ on
this_.ContentItemRecord_id=contentite1_.Id left outer join
Orchard_Framework_ContentTypeRecord contenttyp4_ on
contentite1_.ContentType_id=contenttyp4_.Id WHERE contentite1_.Id =
#p1 and this_.Published = #p2 ] Name:cp0 - Value:2 Name:cp1 -
Value:True [SQL: SELECT TOP (#p0) this_.Id as Id17_2_, this_.Number
as Number17_2_, this_.Published as Published17_2_, this_.Latest as
Latest17_2_, this_.Data as Data17_2_, this_.ContentItemRecord_id as
ContentI6_17_2_, contentite1_.Id as Id16_0_, contentite1_.Data as
Data16_0_, contentite1_.ContentType_id as ContentT3_16_0_,
contenttyp4_.Id as Id18_1_, contenttyp4_.Name as Name18_1_ FROM
Orchard_Framework_ContentItemVersionRecord this_ inner join
Orchard_Framework_ContentItemRecord contentite1_ on
this_.ContentItemRecord_id=contentite1_.Id left outer join
Orchard_Framework_ContentTypeRecord contenttyp4_ on
contentite1_.ContentType_id=contenttyp4_.Id WHERE contentite1_.Id =
#p1 and this_.Published = #p2]
Before creating SQL Server database, set collocation as Latin1_General_100_CI_AS
Do this, right click to Database note on SQL Server management Tool and click to New Database. When you see the New Database window, type the database name and click to Option tab left hand side on New Database windows.
You will see Collocation combobox top of the New Database window. Change default to Latin1_General_100_CI_AS. And then run Orchard setup again.
Set up a new application pool in your IIS manager and have it run as an account with permissions to query your sql server. Then assign your orchard website to use that application pool. Here is a screen shot of where to set the identity of the application pool, click the "Advanced Settings" link to get to this menu:
In the "Process Model" section - set the Identity to an account with SQL server permissions. Set "Load User Profile" = 'false'. This will prevent the pool from trying to retrieve the user profile when running the orchard website.
I find that usually when I get that error message, it's because the query being executed has a syntax error, or table/column names don't match. If you can halt execution where the exception is thrown, you can check the InnerException to see if that provides more info. If not, just copy the SQL from the message, fill in the parameters #p0, #p1, #p2 with values, and try to run it in whatever tool you use to manually query your database. It will often give you a more helpful error message.
Hi I am using Oracle SQL Developer 3.1.06 and connected to 11g EE. Whenever I will click edit in any procedure in the left pane, showing "create or replace" in the right side window.. I am not able to see any procedure code. I am able to see the procedure in same login in toad.
Are you sure the user you are logging in with is the owner of the objects?
You can check the owner by looking into the ALL_OBJECTS table:
SELECT * FROM ALL_OBJECTS WHERE OBJECT_NAME LIKE '%MYOBJECT%'
The user you are logging into could perhaps only have limited view rights preventing you from accessing the code. If you found the owner, you could browse in the connection window to other users and select the procedure from the relevant user. You should then be able to see everything.
I have a user called LOW_PRIVS.
They only have RESOURCE and CONNECT.
I create a procedure.
I open procedure.
Here is what we run to get the source code on a local procedure:
WITH src AS (
SELECT ROWNUM,
line,
text,
origin_con_id
FROM sys.all_source
WHERE type = :type
AND owner = :owner
AND name = :name
)
SELECT text
FROM src,
(
SELECT MAX(origin_con_id) max_orig
FROM src
)
WHERE origin_con_id = max_orig
ORDER BY line
We're hitting the ALL_SOURCE view that belongs to SYS. That should work for anyone.
But test and verify.
Note: I am on version 18.2 - that is many years newer than version 3.1. For best support, upgrade.