I need some meta data about my stored procedures. I know oracle stores meta information of its objects in sys tables.
systemtables
Does oracle store the parameter information of stored procedures?
Like name, type and maybe description?
SYS.ALL_STORED_SETTINGS
does not store this information. It only stores plsql meta parameter information.
Yes, in the ALL_ARGUMENTS view
Related
I am trying to pass a collection of Employee objects from Java code to a DB2 Stored Procedure. In SQL server I can do that by making use of Table-Valued Parameters. In DB2 how can I achieve this?
Refer to Invoking stored procedures with ARRAY of ROW parameters in JDBC applications.
Or use Declared Global Temporary Table creating it and inserting rows into it beforehand and use this DGTT in your SP as ordinary table.
We are planning to create a procedure for our logic what should be in PL SQL in redshift (using workbench).
Can we use a table variable to traverse through the rows of the table ? Like we have dataframe in Python.
Sort of. Redshift implements a RECORD data type for stored procedures. Variables with this type can hold an arbitrary sets of rows.
"Overview of stored procedures in Amazon Redshift" > "Record types"
However, note that you cannot currently SELECT from a RECORD typed variable, only loop over the content.
There are several examples of using a RECORD variable in our GitHub repository: "amazon-redshift-utils/src/StoredProcedures/"
I'm trying to pass an array of JSON objects to the Stored procedure, so that each JSON object will be stored in a single row of the table.
for an example:
to insert a single entry: INSERT INTO SCHEMA_NAME.TABLE_NAME (id,name) values (1,'my_name')
now i have an array of such data which I want to push into stored procedure to get all data inserted into table without hitting SP again and again.
array example: [{id:1,name:'name1'},{id:2,name:'name2'}]
now i can have number of object to be stored.
so either i would hit the SP again and again to push each object individually or i would pass whole array and run a loop inside a stored procedure to get it done.
I have DB2 10.5 LUW with fixpack 7 installed and using node.js
DB2 10.5 does not support JSON as a native data type, so you won't be able to do this without passing the JSON as a VARCHAR and having the stored procedure parse/deconstruct the JSON. The obvious way to do this would with a C or Java stored procedure.
That said, there are some JSON capabilities (see this series of articles for more details, but this is almost certainly not what you want.
I am using SQL Server 2012 and trying to write a stored procedure that will have two components:
1. Select statement that will return several rows
2. Another component will have an aggregated value based on some conditions.
So, for the second component, I am thinking to declare a variable in the stored procedure and store the aggregated data there.
Now, my question is can I populate my output parameter with the data stored in previously declared variable and access the parameter from SSRS 2012?
I would appreciate any suggestion(s) to get me started.
Thank you
scenario is, I am having 2 database. db1 and db2. where as I have around more than 45 stored procedures in db2 which are having join with tables in db1. I could able to do by db1.dbo.tablename but since if I am renaming db1 to db3. All db2 stored procedures getting failed. What should approach? as per client requirement as usual he want to rename db1. By find replace in script db1 to db3 is not the good approach. because if client asks to rename again db3 databse to some another name , then it is permanent tedious and unprofessional work. What should I use here?
Create synonyms. Reference the synonyms in your objects. If the database changes, you just have to change one synonym per object. There's no avoiding changing the logical name in your code but if you control access through synonyms you only have to change it in one place.
For example
Without synonyms:
Six Stored Procedures in db2 refer to objects db1..Table1 and db1..Table2
When you rename db1 to db7, you need to alter two objects in six stored procedures.
With synonyms:
Six Stored Procedures refer to synonyms snTable1 and snTable2 (in the local database - note no database reference here)
The synonym snTable1 refers to db1.Table1
When you rename db1 to db7, you need to alter two synonyms to point at the new database. No changes to stored procedures are required. All objects referring to the synonyms will still work.
This requires you to create synonyms in db2 pointing at objects in db1, and an initial rewrite of your stored procedures in db2 to refer to local synonyms instead of database-qualified objects. But you need to do that anyway right?
Example Procedure
Create a synonym in db2 called snTable1 that refers to Table1 in db1
USE db2
CREATE SYNONYM snTable1 FOR db1.Table1
Alter your 45 stored procedures to refer to snTable1, not db1.Table1. You only have to do this once. Note these stored procedures are referring to objects in the local database.
If your database gets renamed to xyz, recreate the synonym:
USE DB2
DROP SYNONYM snTable1
CREATE SYNONYM snTable1 FOR xyz.Table1
This is only useful if there are far more stored procedures/views than objects.
If you wish to change these on the fly you could probably use DMO or powershell or generate some T-SQL to do it. You just run the above commands against the database with a user that has suitable security.
Another very unpleasant option that may work is to create a linked server to your local database with a hard coded login whose default database is the database that you want. But it hides the user that is really accessing the object, and probably introduces performance issues. In short it's bad practice. I question why the database needs to be renamed so much. No end user should ever see it. If you take a look at Sharepoint databases they have hideous names but this is irrelevant to an end user.
Example linked server procedure
Create a user that only has access to db1, and whose default database is db1
Create a linked server (called MyLinkedServer for example) on the SQL Server to the local database using the user created in step 1
Alter all your code in db2 to use four part naming through this linked server: SELECT * FROM MyLinkedServer...Table1
If the database name changes, there are probably no changes required
This is just a theory and if it works its bad practice... worse practice than needing to rename your database.