12.07.2015 Views

Oracle SQL Developer

Oracle SQL Developer

Oracle SQL Developer

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Entering and Executing PL/<strong>SQL</strong> CodeYou can nest blocks in the executable and exception-handling parts of a PL/<strong>SQL</strong> blockor subprogram, but not in the declarative part. You can define local subprograms inthe declarative part of any block. You can call local subprograms only from the blockin which they are defined.■■■Anonymous blockAn anonymous block is a PL/<strong>SQL</strong> block that appears in your application and isnot named or stored in the database. In many applications, PL/<strong>SQL</strong> blocks canappear wherever <strong>SQL</strong> statements can appear. A PL/<strong>SQL</strong> block groups relateddeclarations and statements.Stored or standalone subprogramA stored or standalone subprogram is a PL/<strong>SQL</strong> block that <strong>Oracle</strong> stores in thedatabase and can be called by name from an application. Subprograms can beprocedures or functions; the difference is that functions return a value whenexecuted. When you create a stored subprogram, <strong>Oracle</strong> parses the subprogramand stores its parsed representation in the database. See Subprograms andPackages: Usage Information.PackageA package is a group of subprograms and variable definitions that <strong>Oracle</strong> stores inthe database. Subprograms and variables in packages can be called from otherpackages or subprograms. See Subprograms and Packages: Usage Information.7.2 Entering and Executing PL/<strong>SQL</strong> CodePL/<strong>SQL</strong> code can be entered and executed from the <strong>SQL</strong> Workshop or the <strong>SQL</strong>*Pluscommand line.In the <strong>SQL</strong> Workshop, you can save your <strong>SQL</strong> statements as a script file that can be runas a <strong>SQL</strong> script with <strong>SQL</strong>*Plus.If you use <strong>SQL</strong>*Plus, simply type in each line of code at the <strong>SQL</strong> prompt. Forinformation on using <strong>SQL</strong>*Plus, see <strong>SQL</strong>*Plus: Usage Information.You can create a text file of the PL/<strong>SQL</strong> code and run that as a <strong>SQL</strong> script. Using ascript makes correcting mistakes much easier because you only need to make thenecessary updates to correct the problem rather than retyping all the PL/<strong>SQL</strong> code.For information on running <strong>SQL</strong> scripts from <strong>SQL</strong>*Plus, see Running Scripts From<strong>SQL</strong>*Plus.7.3 Utilizing the Main Features of PL/<strong>SQL</strong>PL/<strong>SQL</strong> combines the data-manipulating power of <strong>SQL</strong> with the processing power ofprocedural languages. You can control program flow with statements like IF andLOOP. As with other procedural programming languages, you can declare variables,define procedures and functions, and trap runtime errors.PL/<strong>SQL</strong> lets you break complex problems down into easily understandableprocedural code, and reuse this code across multiple applications. When a problemcan be solved through plain <strong>SQL</strong>, you can issue <strong>SQL</strong> commands directly inside yourPL/<strong>SQL</strong> programs, without learning new APIs. PL/<strong>SQL</strong> data types correspond with<strong>SQL</strong> column types, making it easy to interchange PL/<strong>SQL</strong> variables with data inside atable.■■Using PL/<strong>SQL</strong> Block StructureUsing Comments7-2 <strong>SQL</strong> <strong>Developer</strong> Online Help

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!