MySQL 8 get PROCEDURE / FUNCTION full definition - mysql-8.0

I need to get the user defined PROCEDURE / FUNCTION full definition in MySQL 8.
MySQL 5.6 contain mysql.proc table there we can get the function full definition but MySQL 8 does not contain the proc table.
But MySQL 5.6 and 8 also have information_schema.ROUTINES table it contain only the function body,
I can not find functions parameter and return types.
what I did in MySQL 5.6
SELECT
`name` AS _schema,
CONVERT(body USING utf8) AS _schemaDef,
CONVERT(param_list USING utf8) AS param_list,
CONVERT(`returns` USING utf8) AS `returns`
FROM mysql.proc
WHERE db = 'my_db_name'
Any idea how to do this MySQL 8?
My ultimate target is copying all function and procedure from one DB to another DB by using PHP
I have find a solution that...
SHOW CREATE FUNCTION function_name
Above query work fine in MySQL 5.6 and 8.
But first I have to get list of FUNCTION names from information_schema.ROUTINES table and loop the record set, Inside the loop I have to run the above SHOW CREATE FUNCTION query.
How to Optimize this flow?

Related

FireDAC "table or view does not exist" when insert into ORACLE TABLE Delphi Belin 10.1 upd 2

We are migrating our codebase from Delphi XE3 with FireDAC 8.0.5 to Delphi Berlin 10.1 Upd 2 with FireDAC 15.0.1 (Build 86746). Everything is working smoothly using MS Sql Server, but using ORACLE it has been another history.
Throughout the application source code we use lots of TAdQuery with sql instructions like
AdQuery1.Sql.Text := 'SELECT FIELD1, FIELD2 FROM TABLE1';
In order to insert a record, we use Append or Insert methods, like this
AdQuery1.Insert;
//or
AdQuery1.Append;
Just after invoking its Post method, the component internally creates an INSERT sql statement, that goes like this
INSERT INTO TABLE1 (FIELD1, FIELD2) VALUES(:FIELD1, :FIELD2)
So the record gets inserted successfully.
Now, using TFdQuery in Delphi Berlin, the component internally creates an INSERT sql statement, like this
INSERT INTO USERNAME.TABLE1 (FIELD1, FIELD2) VALUES(:FIELD1, :FIELD2)
Failing with a [FireDAC][Phys][Ora] ORA-00942: table or view does not exist
This happens because in our Oracle database, TABLE1 is created in a schema called MAIN_SCHEMA, and we access it by using a public synonym.
Trying to find a workaround, we compared FireDAC source code, finding that
in Delphi XE3, the unit uADDAptManager.pas, on its function TADDAptTableAdapter.GetUpdateRowCommand, calls oConn.CreateCommandGenerator(oCmdGen, nil);
in Delphi Berlin, the unit FireDAC.DApt.pas, on its function TFDDAptTableAdapter.GetUpdateRowCommand
calls oConn.CreateCommandGenerator(oCmdGen, GetSelectCommand);
Whenever that second parameter (called ACommand: IFDPhysCommand) is not nil, the name of the table is returned concatenating the user name (in a function called TFDPhysCommandGenerator.GetFrom).
If we add 'MetaCurSchema=MAIN_SCHEMA' to the TFdConnection params, it works with the applications that not use a pooled connection, but We have several process that use a pooled connection with the same params, even MetaCurSchema param, but it doesn't work
What can we do?
thanks for your help
What I understand is that you would do better making the connection avoid the use of any schema name, rather than specifying it. Also, keeping in mind that you already use public synonyms.
So, according to the documentation:
Full object names
FireDAC supports full object names, which include the catalog and/or schema names.
When a short object name is specified to StoredProcName, TableName, etc, they will be expanded into the full object names, using the current catalog and/or schema names. To override or avoid usage of the current catalog and/or schema names, use the MetaCurCatalog and MetaCurSchema connection definition parameters. For example:
[Oracle_Demo]
DriverID=Ora
...
MetaCurCatalog=*
MetaCurSchema=*
~ Source: Object Names (FireDAC) - docWiki
MetaCurSchema
Specifies the current schema for the application. If not specified, then its value will be received from the DBMS. When an application is asking for metadata and do not specify a schema name, then FireDAC will implicitly use the current schema.
If MetaCurSchema is '*', then schema names will be me omitted from the metadata parameters.
~ Source: Common Connection Parameters (FireDAC) - docWiki
That asterisk (*) should do the trick, let us know if that's the case.

Oracle Stored Procedure is not working in SSRS Query Designer

I wrote a stored procedure in Oracle 11g. It has 4 input parameters and 60 output parameters. It executes successfully and returns output using GUI in Oracle SQL developer tool.
But problem is in SSRS I connect with Oracle as ODP.NET Data Source. Test connection succeeds in shared data set properties.
When I select the specific stored procedure and pass 4 input parameters which are VARCHAR2 Data types
it shows an error:
You have to use the output parameters as well when you call the procedure.
PS: I don't like the idea of having 60 output parameters. I'd use a record or a collection (or both).

How do I use a parameter within BI Publisher to update the table name I am querying in an Oracle Data set

I am trying to create a BI Publisher data model which runs the Oracle query below -
SELECT *
FROM audit_YYYYMM
(this should be the YYYYMM of the current date)
How do I setup a parameter default value within the datamodel to grab the YYYYMM from the SYSDATE?
How do I append this parameter within the data set SQL Query?
I tried SELECT * FROM audit_:Month_YYYYMM
(where I had a string parameter called Month_YYYMM)
This did not work.
You are going to have to use something like EXECUTE_IMMEDIATE. And you may have to make a separate PL/SQL package to launch rather than use the built in data definition stuff.
https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/executeimmediate_statement.htm

Getting results from an Oracle package function returning a table

Our database has a package that returns a type t_daily_array_table.
This type is defined as:
TYPE t_daily_array_table IS TABLE OF r_daily_array_rec
and r_daily_array_rec is defined as a record with a number of fields.
We have a package called schedule_pkg with the function f_daily_array_table which returns the t_daily_array_table. The function takes a single Number parameter.
I've tried calling it a number of ways, but I can't seem to get it to work (I know this function works. It's called from an COBOL app that functions just fine).
I've tried:
select schedule_pkg.f_daily_array_table(74501) from dual;
When I do that, I get
SQL Error: ORA-00902: invalid datatype
I've tried:
select * from schedule_pkg.f_daily_array_table(74501)
That gives me:
SQL Error: ORA-00933: SQL command not properly ended
I've tried using code (C#) and calling in various ways using OleDb, OracleClient, and ODBC and I have yet to find a way I can call this, other than using COBOL.
If you want to query the values from an SQL context but have a PL/SQL collection type, you can create a pipelined wrapper function, either within the package or as a standalone object for testing/debuggging. Something like this should work:
create function f_daily_array_pipe(p_id IN number)
return schedule_pkg.t_daily_array_table pipelined is
l_daily_array_table schedule_pkg.t_daily_array_table;
begin
l_daily_array_table := schedule_pkg.f_daily_array_table(p_id);
for i in 1..l_daily_array_table.count loop
pipe row (l_daily_array_table(i));
end loop;
end f_daily_array_pipe;
/
select * from table(f_daily_array_pipe(74501));
This calls your original function, assigns the result to a local collection, iterates over it, and pipes each record in turn back to the caller; which uses the SQL table() collection expression to convert it to something you can query from.
SQL Fiddle demo.
If you are using an OCI or JDBC client you can use an array descriptor and retrieve the data as an array, but that won't work from plain SQL.
I think the syntax you're looking for is:
select * from table(schedule_pkg.f_daily_array_table(74501));

Getting the return value of a PL/SQL function via Hibernate

I have a PL/SQL function in an Oracle database that I can't change. This function takes a parameter which identifies an entity, creates a copy of that entity and then returns the ID of the copy. This looks something like
FUNCTION copy_entity(id IN NUMBER) RETURN NUMBER
I need to call this function from Hibernate. I tried creating a named SQL query with something similar to
CALL copy_entity(:id)
as the query, but from this I can't seem to get the return value of the function. Hibernate's "return-scalar" and similar options require a column name to return and I don't have a column name. This lead me to
SELECT copy_entity(:id) AS newEntityId
with "return-scalar" using newEntityId as column name, but this also did not work since Oracle then throws an exception that I can't call INSERT (to save the copy) in a SELECT.
Is there any way to get the return value of such a PL/SQL function? The function is actually much more complex and still required in other parts of the app, so re-writing it is not really an option.
I hope/think you can use an anonymous PL/SQL block:
begin
:myresult = copy_entity(:id);
end;
Now you have 'column name' myresult with the result.
I've never used hibernate so I hope it works. I don't know how flexible Hibernate is.
I think you are stuck using straight JDBC. The Hibernate documentation has this in the limitations section for Oracle:
For Oracle the following rules apply:
A function must return a result set.
The first parameter of a procedure
must be an OUT that returns a result
set. This is done by using a
SYS_REFCURSOR type in Oracle 9 or 10.
In Oracle you need to define a REF
CURSOR type. See Oracle literature for
further information.
Since this function accepts a number and returns a number you are out of luck with Hibernate and would probably be better off making a simple JDBC CallableStatement.

Resources