楼主: ReneeBK
2492 12

Oracle PL/SQL Recipes [推广有奖]

  • 1关注
  • 62粉丝

VIP

学术权威

14%

还不是VIP/贵宾

-

TA的文库  其他...

R资源总汇

Panel Data Analysis

Experimental Design

威望
1
论坛币
49402 个
通用积分
51.7504
学术水平
370 点
热心指数
273 点
信用等级
335 点
经验
57815 点
帖子
4006
精华
21
在线时间
582 小时
注册时间
2005-5-8
最后登录
2023-11-26

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

Oracle PL/SQL Recipes


A Problem-Solution Approach



Book Description
Oracle PL/SQL Recipes is your go to book for PL/SQL programming solutions. It takes a task-oriented approach to PL/SQL programming that lets you quickly look up a specific task and see the pattern for a solution. Then it's as simple as modifying the pattern for your specific application and implementing it. And you're done and home for dinner.

Oracle PL/SQL Recipes is another in Apress' ongoing series of recipe books aimed at Oracle practitioners. The recipe format is ideal for the busy professional who just needs to get the job done.
Book Details
  • Publisher:        Apress
  • By:        Josh Juneau, Matt Arena
  • ISBN:        978-1-4302-3207-0
  • Year:        2010
  • Pages:        456
  • Language:        English
  • File size:        6.2 MB
  • File format:        PDF
  • Download:      

    本帖隐藏的内容

    Oracle PL-SQL Recipes.rar (2.59 MB, 需要: 20 个论坛币) 本附件包括:
    • Oracle PL-SQL Recipes.pdf




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Recipes Oracle Recipe ACL CIP Oracle

本帖被以下文库推荐

沙发
ReneeBK 发表于 2015-7-11 23:54:04 |只看作者 |坛友微信交流群
1-1. Creating a Block of Code

Problem

You are interested in creating an executable block of PL/SQL code.

Solution

Write the keywords BEGIN and END. Place your lines of code between those two keywords. Here's an example:

  1. BEGIN
  2.    Executable statements go here…
  3. END;
复制代码

If you want to introduce variables for your PL/SQL block, you must precede your block with a DECLARE section. Here's an example:

  1. DECLARE
  2.     One or more variable declarations
  3. BEGIN
  4.     One or more PL/SQL statements
  5. END;
复制代码




使用道具

藤椅
ReneeBK 发表于 2015-7-11 23:55:09 |只看作者 |坛友微信交流群
1-2. Executing a Block of Code in SQL*Plus

Problem

You want to execute a block of PL/SQL code within the SQL*Plus command-line utility.

Solution

The solution to this recipe is multitiered, in that executing a block of code in SQL*Plus incorporates at least two steps:

Enter the PL/SQL code into the SQL*Plus utility.

Execute the code block by simply placing a backslash (/) as the last line of code, and then press the Enter key.

The following is an example displaying a code block that has been typed into SQL*Plus:

  1. SQL> BEGIN
  2.   2 DBMS_OUTPUT.PUT_LINE('HELLO WORLD');
  3.   3  END;
复制代码

  4  /



使用道具

板凳
ReneeBK 发表于 2015-7-11 23:56:55 |只看作者 |坛友微信交流群
1-3. Storing Code in a ScriptProblem

Rather than typing your PL/SQL code into the SQL*Plus utility each time you want to run it, you want to store the code in an executable script.

Solution

Open your favorite text editor or development environment; type the PL/SQL code into a new file, and save the file using the .sql extension. The script can contain any number of PL/SQL statements, but the last line of the script must be a forward slash (/).

For example, you could place the following lines into a file named count_down.sql:

  1. SET SERVEROUTPUT ON;
  2. DECLARE
  3. counter   NUMBER;
  4. BEGIN
  5.   FOR counter IN REVERSE 0..10 LOOP
  6.     DBMS_OUTPUT.PUT_LINE (counter);
  7.   END LOOP;
  8. END;
复制代码

Now you have a file that you can execute from SQL*Plus any time you want to count down from ten to zero.

使用道具

报纸
ReneeBK 发表于 2015-7-11 23:58:05 |只看作者 |坛友微信交流群
1-4. Executing a Stored Script

Problem

You have stored an SQL script to your file system and want to execute it in SQL*Plus.

Solution

Assume you have a stored script named my_stored_script.sql and that it is saved within a directory named /Oracle/scripts/. You can execute that script using any one of the following approaches:

  • Traverse into the directory containing the script, then connect to a database via SQL*Plus, and finally issue the following command:@my_stored_script.sql
  • Open the command line or terminal, connect to the database via SQL*Plus, and issue the following command:@/Oracle/scripts/my_stored_script.sql
  • Open command line or terminal, and issue the following command:sqlplus username/password@database my_stored_script.sql




使用道具

地板
ReneeBK 发表于 2015-7-11 23:59:09 |只看作者 |坛友微信交流群
1-5. Accepting User Input from the Keyboard

Problem

You want to write a script that prompts the user for some input. You want your PL/SQL code to then use that input to generate some results.

Solution

SQL*Plus provides a facility to accept user input. Use ampersand (&) character to indicate that a particular value should be entered from the keyboard. Here's an example:

  1. DECLARE
  2.   emp_count   NUMBER;
  3. BEGIN
  4.   SELECT count(*)
  5.   INTO emp_count
  6.   FROM employees
  7.   WHERE department_id = &department_id;
  8. END;
复制代码

If the previous block is executed from SQL*Plus, you will see the following text, which prompts you to enter a department ID. In this case, the department ID of 40 is used.

Enter value for department_id: 40
old   7:   WHERE department_id = &department_id;
new   7:   WHERE department_id = 40;



使用道具

7
ReneeBK 发表于 2015-7-12 00:01:29 |只看作者 |坛友微信交流群
1-6. Displaying Results in SQL*Plus

Problem

You want to display query results at the SQL*Plus prompt.

Solution

Use the DBMS_OUTPUT package to assist in displaying query results or lines of text. The following example depicts both of these use cases:

  1. DECLARE            
  2.    first        VARCHAR2(20);
  3.    last         VARCHAR2(25);
  4. BEGIN
  5.   SELECT first_name, last_name
  6.   INTO first, last
  7.   FROM employees
  8.   WHERE email = 'VJONES';
  9.   DBMS_OUTPUT.PUT_LINE('The following employee matches your query:');
  10.   DBMS_OUTPUT.PUT_LINE(first || ' ' || last);
  11. END;
复制代码







使用道具

8
ReneeBK 发表于 2015-7-12 00:17:49 |只看作者 |坛友微信交流群
Commenting Your Code

Problem

You want to document your code with inline and multiline comments.

Solution

Place two dashes before any text to create a one-line comment. For example, in the following code there is a comment placed before the query to describe its functionality:

-- The following query obtains a count of rows from the employees
  1. table
  2. SELECT COUNT(*)
  3. FROM EMPLOYEES;
复制代码

Multiline comments can be created beginning with a slash and asterisk (/*) and ending with an asterisk and slash (*/). The following lines depict a multiple-line comment for a given code block:

  1. /* This comment describes the functionality
  2.       in the following code block. */
复制代码




使用道具

9
ReneeBK 发表于 2015-7-12 00:23:37 |只看作者 |坛友微信交流群
1-8. Referencing a Block of CodeProblem

You want to reference a block of code within a code segment later in your program.

Solution

Assign a label to the block of code that you want to reference. A PL/SQL label consists of a unique identifier surrounded by double angle brackets. For example, in the following code, you see that the block has been labeled dept_block:

  1. <<dept_block>>
  2. DECLARE
  3.   dept_name    varchar2(30);
  4. BEGIN
  5.   SELECT department_name
  6.   INTO dept_name
  7.   FROM departments
  8. WHERE department_id = 230;
  9.   DBMS_OUTPUT.PUT_LINE(dept_name);
  10. END;
复制代码

This code block can now be referenced by the label dept_block.



使用道具

10
Nicolle 学生认证  发表于 2015-7-17 08:12:36 |只看作者 |坛友微信交流群
提示: 作者被禁止或删除 内容自动屏蔽

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-20 05:29