Benefit of the dynamic sql pl sql, PL-SQL Programming

Benefit of the dynamic SQL:

This part shows you how to take full benefit of the dynamic SQL and how to keep away from some of the common pitfalls.

Passing the Names of Schema Objects:

Assume that you require a procedure which accepts the name of any database table, and then drop that table from your schema. By using the dynamic SQL, you may write the stand-alone procedure as shown below:

CREATE PROCEDURE drop_table (table_name IN VARCHAR2) AS

BEGIN

EXECUTE IMMEDIATE 'DROP TABLE :tab' USING table_name;

END;

Though, at run time, this procedure fails with an invalid table name error. That is as you cannot use the bind arguments to pass the names of the schema objects to a dynamic SQL statement. Rather, you should embed parameters in the dynamic string, and then pass the names of the schema objects to those parameters.

To debug the last illustration, you should revise the EXECUTE IMMEDIATE statement. Rather of using the placeholder and bind the argument, you can use the concatenation operator to embed the parameter table_name in the dynamic string, which is as shown below:

CREATE PROCEDURE drop_table (table_name IN VARCHAR2) AS

BEGIN

EXECUTE IMMEDIATE 'DROP TABLE ' || table_name;

END;

Posted Date: 10/6/2012 8:30:21 AM | Location : United States







Related Discussions:- Benefit of the dynamic sql pl sql, Assignment Help, Ask Question on Benefit of the dynamic sql pl sql, Get Answer, Expert's Help, Benefit of the dynamic sql pl sql Discussions

Write discussion on Benefit of the dynamic sql pl sql
Your posts are moderated
Related Questions
Using PRIOR and NEXT The PRIOR(n) returns the index number that precede index n in a collection. The NEXT(n) returns the index number which succeed the index n. If n has no pr

Creating and Destroying Base Tables: Example shows an SQL command to create the base table counterpart of the ENROLMENT variable ExampleĀ  Creating a base table. CREATE T

Dynamic SQL: The Most PL/SQL programs do a predictable, specific job. For illustration, a stored procedure may accept an employee number and salary increase, and then update t

Datatype Conversion At times it is necessary to convert a value from one datatype to another. For e.g. if you want to inspect a rowid, you should convert it to a character stri

Declaring Objects: You can use the object types wherever built-in types like CHAR or NUMBER can be used. In the block below, you can declare object r of type Rational. Then, yo

Operators on Tables and Rows Row Extraction TUPLE FROM r, SQL has row subqueries. These are just like scalar subqueries except that they may specify more than one column.

User-Defined Exceptions The PL/SQL defines the exceptions of your own. Dissimilar to the predefined exceptions, the user-defined exceptions should be declared and should be rai


BEGIN Parameter Description in pl sql: BEGIN: This keyword signals the beginning of the executable section of a PL/SQL block, that contains executable statements. The execut

THEORY OF SPONTANEOUS GENERATION - ABIOGENESIS OR AUTOGENESIS - According to this theory, the existing living communities have originated from non-living organic matter with