I was told by someone that when you create procedures in Oracle you should create a Package with procedures in it. Is this a true statement? Are procedures in MS the same as Oracle?
You do not have to put your procedures and functions inside a package, but it is generally considered a best practice. Bundle them by function and they are a lot easier to organize.
One exception to this is the AUTHID clause. That can only be specified for an entire package or a standalone procedure/function. Different procedures inside a single package cannot have different privileges.
Procedures in Oracle and MS are similar, but yes, in Oracle, you make a package declaring the procedure, then you define the procedure in the package body
This has some good info on how to build an Oracle package
Stored procedures and functions are very similar between Oracle and SQL Server (or MySQL, PostgreSQL, etc). A SQL function is intended to always return a SQL data type; a stored procedure can return a SQL data type but doesn't by default.
An Oracle package is an awesome tool.
SQL Server has assemblies, but they aren't as immediately accessible as Oracle packages.
Besides being a container for functions and stored procedures, Oracle packages support variable declaration when other alternatives would only expose via functions.
Oracle packages also allow for logical grouping of functionality, without needing to setup schemas (for namespacing). Because of what's contained in a package, you deploy the package -- not the functions/stored procedures individually.
My only regret was that IME (Oracle 9i, 10g), you could not drill into the specific function/stored procedure/line when tracing references.
There's nothing requiring you to use Oracle Packages, but you really stand to benefit by using them vs not. I don't understand why other vendors haven't reproduced the functionality in their own way.
There are a ton of reasons to use packages over standalone procedures/functions, and a few situations when you wouldn't use packages. Instead of trying to rehash them from memory, I'll point you to an excellent article from pl/sql guru Steve Feuerstein.
Note: The article is several years old, but the rationale still holds imo
Related
I need to create a localized environment for a SSIS package that would only have the objects and entities needed by tasks inside it.
It's a large & complex SSIS package and it connects to eight databases on the same sql server.
Is there a quick way to list all the tables, stored procedures, functions etc that will be utilized(directly or indirectly) when I execute this package.
Good thought by Nick, but even that will only get you objects that are used directly. There is no quick easy way to get all the objects that will be used indirectly.
I'll start off by saying I'm in no way a PL/SQL or T-SQL expert and I only really know the basics but I have been asked to undergo a project to migrate about 1,700 PL/SQL procedure packages to T-SQL. Even if I knew PL/SQL the best way is using an automated tool to at least cover the majority of the translation. I've been using Microsoft's SQL Server Migration Assistant. After reading this article. I Am under the impression it is possible to convert single pieces of PL/SQL.
When I'm migrating schema's its giving me 3 errors every time. The same 3 errors. And basically it doesn't do the migrating at all. It just seems to comment the whole thing out?
I just want to know what is going wrong and why it is not migrating. From the second error my impression is that it is not converting because it is looking for ''stage_sendup_nb' but that doesn't exist on the database because I just pasted the SQL in.
"Unparsed SQL" means that it didn't recognize the statement you tried to convert. Most likely CREATE PROCEDURE is not supported for SQL statements. When you have a procedure to convert it's better to find it in Procedures and convert from there. "Snippet" conversion is very limited, it's designed to convert a statement or two, usually some specific query you want to try on the migrated DB (e.g. SELECT or UPDATE).
Any conversion of SQL (including procedures and SQL statements) relies on proper metadata available in Oracle. So you have to connect to Oracle database with all referenced tables, procedures and so on to convert even one procedure. In that way SSMA knows details about the referenced objects.
I have to make my stored procedures written in SQL to be generic, so that they can be used in different versions of SQL (also MySQL if possible). I think it can be done if the scripts are written according to ANSI standards. But I have to convert large procedures. There is no tool for direct conversion. Is there any set of rules which can be followed to perform this conversion?
I have found a tool to validate scripts # http://developer.mimer.com
But this will be very time consuming as I have large SP's and I think by using some rule book, this task can be done in a shorter time.
There is no generic stored procedure language.
If you need something to work across database platforms, you would be better to implement the SP functionality in code, using ANSI standard SQL for the database access.
I have a SQL Server 2000 database with a lot of stored procedures. I want to migrate to a open source database and well I know I will have to re write the procedures but I would like to do this with as little effort as possible
Neither are a direct port, but of the two -- MySQL's syntax is more similar to SQL Server's than PostgreSQL.
SQL Server 2000 didn't have analytic/ranking/windowing functionality -- neither does MySQL currently. Also, no WITH/CTE support - again, MySQL doesn't support this either. If you were migrating away from SQL Server 2005+, I'd have recommended PostgreSQL 8.4+ for the sake of either of the two things I just mentioned.
MySQL's stored procs are really basic, for instance you cannot raise an exception from within a proc, which makes error handling REALLY PAINFUL. Also, debugging stored procs is a pain, the error messages are unclear, and the language itself is pretty limited.
Postgres is much more mature for this ; if your app has lots of stored procs, this pretty much rules out mysql.
MySQL supports stored procedures, per se; PostgreSQL supports stored functions, which are in practice very similar.
The first query language for PostgreSQL, PL/pgSQL, is similar to Oracle's PL/SQL. PostgreSQL supports SQL:2003 PSM stored procedures as well as many other general purpose programming languages such as Perl (PL/Perl), Python (PL/Python), TCL (PL/Tcl), Java (PL/Java) and C (PL/C).
MySQL follows the SQL:2003 syntax for stored routines, which is also used by IBM's DB2.
—MySQL AB , MySQL 5.1 Reference Manual :: 18 Stored Procedures and Functions
Via the plugin interface MySQL supports external language stored procedures in Java, Perl, XML-RPC with more language plugins in the works.
from link text
We are developing a Visual Studio.NET 2008 application with Oracle 9i as backend. Is it true that the usage of Stored procedures would be faster than Inline SQL ? This is a debate with my co-programmers.
We are using ODP.NET (Oracle Data Provider for .NET) from Oracle.
Thanks.
While I am tempted to answer "no" or "I don't think so", the only real way to know the answer to this question is to go and measure it yourself. Use a profiler like JetBrains dotTrace, and TOAD's own profiler, to find out.
All other answers are speculative.
It should be. When you send inline SQL to database, the engine must parse it and execute. Stored procedures are being parsed (and compiled) at creation time. So at least you are gaining parsing time.
I would expect stored procedures to be faster in almost all cases.
But it mainly depends on your code.
If for example you get a resultset from your database and then use this data to perform other queries, you'll end up with a lot of overhead in your network traffic. This is especially true if you forget to use a single connection for the requests.
It could then be more efficient to use a single stored procedure to return the agregated data (if possible of course).
It will be faster if you build your stored procs (PL/SQL packages) in such a way that less data will be transferred between the database and the client.
Jon Limjap said: "All other answers are speculative."
There's much truth to this statement. There are so many factors: how's the DB server set up? How's the network speed/reliability? How's the SQL? How's the PL/SQL? I could write really slow SQL and/or PL/SQL if I wanted to (and have, inadvertently, on past projects!). So if you can, try both out.