I have made multiple procedures in pl/sql oracle, using APEX.
I want to see pl/sql code for my Procedures.
I need a query to do this operation, not through wizards and stuff.
Kindly help me?
Well I found the solution.
Very simple.
SELECT TEXT
FROM USER_SOURCE
WHERE NAME = 'PROCEDURE NAME';
Note that procedure name must be in capitals.
For example:
SELECT TEXT
FROM USER_SOURCE
WHERE NAME = 'SELECTION_SORT';
Related
I am trying to create a new field in a FireDAC-compatible database with this PROCEDURE:
PROCEDURE CreateField(Connection : TFDConnection ; CONST TableName : STRING; F : TFieldDefinition);
VAR
Table : TFDTable;
BEGIN
Table:=TFDTable.Create(NIL);
TRY
Table.Connection:=Connection;
Table.TableName:=TableName;
Table.FieldDefs.Updated:=FALSE;
Table.FieldDefs.Update;
Table.FieldDefs.Add(F.FieldName,F.FieldType,F.MaxLen,NOT F.Nullable);
// Commit my changes to the database //
FINALLY
FreeAndNIL(Table)
END
END;
where
TYPE
TFieldDefinition = CLASS
PUBLIC
FieldName : STRING;
FieldType : TFieldType;
MaxLen : Integer;
Nullable : BOOLEAN;
END;
but I can't seem to "Commit" my changes back to the database (ie. end up executing an ALTER TABLE ADD [COLUMN] statement).
How do I commit my changes to the FieldDefs list of the table? Or is there some other way - using plain FireDAC - that I can use to create a new field in an existing table?
Note: There are already data in the table, so I can't simply "DROP" and then "CREATE" the table again.
FireDAC should understand the sytax used by the supported databases and use the appropriate syntax and decoration. See the documentation here: http://docwiki.embarcadero.com/RADStudio/Sydney/en/Preprocessing_Command_Text_(FireDAC)
TFieldDef is an internal descriptor of the fields in a TDataSet, it's not going to be used to update the table structure automatically. (Although you could write your own procedure that compares your TFieldDefs to the FireDAC MEta Data and creates the DDL (Data Definition Language) statements you need to execute in a TFDCommand ... )
To alter that table structure you will need to provide the DDL (SQL) statement that you execute with TFDCommand - the 'preprocessing' link above will explain how to write it in a dialect abstracted way.
If you use the appropriate FireDAC description it will automatically put in the appropriate SQL decoration for you so the syntax is valid. Depending on your SQL dialect and the FireDAC driver you may hit limitations. (For example using the ODBC driver FireDAC generally won't know the specific details of the underlying database - we had to implement a solution for SAP HANA which had exactly this challenge).
Bear in mind that some SQL dialects support features that others don't - so for example it's not safe to assume that you can position a column when you add it (which MySQL supports for example) as not all dialects allow that in an ALTER TABLE statement.
can some body provide help me to use TFDTable.FireDac is completely new for me. I have used TTable in delphi 2010 for memory database. So i would like to use TFDTable in xe7 for temporary hold.
Well you need to read up on FireDAC generally if you are completely unfamiliar with it, and look at the examples that come with recent versions of Delphi.
But if you just want to know how to copy data from a FireDAC dataset that's connected to a database to an in-memory table, you can do it very simply, like this:
procedure TForm1.btnCopyToMemTableClick(Sender: TObject);
begin
FDMemTable1.Data := FDQuery1.Data;
FDQuery1.Close; // don't need it open any more
end;
Here, FDQuery1 is a TFDQuery, which is similar to a TQuery, in that it has a SQL TStrings property to allow you to specify what Sql query to execute to retrieve the data.
I just wanted to know what is the best practice to create and execute a stored procedure.
I have seen like below:-
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'Foo')
DROP PROCEDURE Foo
GO
CREATE PROCEDURE dbo.Foo
But I am thinking when we execute this stored procedure, it will drop the stored procedure and create a new one. But if there is error in the create stored procedure syntax, it won't recreate the stored procedure, right? So as a result our existing stored procedure is deleted and new stored procedure is not created. So what is the real reason for adding DROP here?
The reason is so that your scripts can be run in an idempotent way - they can be run as many times as needed, with the same result. Namely, your database will have the stored procedure you desire. Your procedure will be created, and dropped beforehand if needed. If you didn't do this, then you'd need separate drop and create scripts.
If you're concerned that your scripts have errors, well, fix them. Run your scripts a few times, and fix any problems that arise. The effort is worth not having to maintain separate sets of scripts.
BECAUSE it is execute in line by line manner so when it create procedure and then error comes and again you recreate that procedure then it gives error because it is already generated in your database with error code....
so for this it want recreate that procedure again.....
you can use alter instead of create....
Hope this help you...
I am working with Code First and using EF 4.1. I have a doubt in using stored procedure. Suppose if my stored procedure is taking values from 2 or 3 tables, how would i get the result ? How i can retrieve the result ? what will be the type of the result ?
Well I don't think, with Code First approach you will be able to get the stored procedures. Actually Code First/Stored procedures is like oxymoron. Check out this blog:
http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-release-candidate-available.aspx
In this blog, see the section.
What’s Not in EF 4.1?
Stored Procedure support in Code First
Also there is a school of thought of not using stored procedures at all, Check out this blog, its quite interesting :)
http://weblogs.asp.net/fbouma/archive/2003/11/18/38178.aspx
I have a Crystal Report, that is populated with a stored procedure, it also contains a sub report, that I am trying to populate with another stored procedure ... same parameters. I cannot figure out how to pass the parameter value to the sub report.
Any help would be appreciated!
When you add the stored proc to the sub-report CR will add the parameters automatically. Then when you set up the sub-report links you link the main report parameters to the sub-report parameters.
I understand this question is old but I didn't find any satisfactory answers to this. The simple solution I found is to implement the stored procedure from within a crystal command just like any other command sql. I could not get the parameters to show up in the bottom left drop downs no matter what. Something similar to below where ZNG_PROACTIVE_STREET_SWEEPS is the name of the stored procedure and the two parameters are what the stored procedure takes in.
[dbo].[ZNG_PROACTIVE_STREET_SWEEPS]
#StartDate ={?begindate},
#EndDate = {?enddate}
You can pass value to sub report like this:
oRpt.SetParameterValue("#InvNo", Session("InvoiceNo"), "rptInvoicePrintSub") ' parameter for subreport
Sounds all so simple, but unfortuanate it isn't that simple. I can link the parameters from main to sub -report, no problem. But when it comes to feeding it to the subreport procedure parameters it becomes rather difficult.
I'm using Crystal XI.
Same procedure main and subreport.
The aim is to let the user select the parameters only once. Currently, the user needs to select the parameters for both main and sub report.
Ok, I over-read the comment where to find the dropdown.
The drop down is in the screen subreport links. On the botton there are 2 dropdowns, use the one on the left.