【转】oracle 9i存储过程详解1.块结构:
【转】oracle 9i存储过程详解PL
/SQL程序被分割为称为块(block)的结构,块中包含PL/SQL程序语句。典型的PL/SQL块具有
【转】oracle 9i存储过程详解以下的结构:
【转】oracle 9i存储过程详解
[DECLARE
【转】oracle 9i存储过程详解    declaration_statements 
【转】oracle 9i存储过程详解
]
【转】oracle 9i存储过程详解
BEGIN
【转】oracle 9i存储过程详解    executable_statements
【转】oracle 9i存储过程详解
[EXCEPTION
【转】oracle 9i存储过程详解    exception_handling_statements
【转】oracle 9i存储过程详解
]
【转】oracle 9i存储过程详解
END;
【转】oracle 9i存储过程详解语法元素:
【转】oracle 9i存储过程详解declaration_statement : 
【转】oracle 9i存储过程详解  声明了在块的其余部分中使用的变量。这些变量是块的局部变量。
【转】oracle 9i存储过程详解executable_statment:
【转】oracle 9i存储过程详解  块的实际可执行语句。
【转】oracle 9i存储过程详解exeception_handling_statement:
【转】oracle 9i存储过程详解  处理可执行语句可能发生的错误。
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解注意:每条语句都要有(;)分号结尾,块使用END关键字结尾。
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解例程:
【转】oracle 9i存储过程详解
DECLARE
【转】oracle 9i存储过程详解    width 
INTEGER :=2;
【转】oracle 9i存储过程详解    height 
INTEGER ;
【转】oracle 9i存储过程详解    area 
INTEGER ;
【转】oracle 9i存储过程详解
BEGIN
【转】oracle 9i存储过程详解    height :
=3 ;
【转】oracle 9i存储过程详解    area :
=width*height ;
【转】oracle 9i存储过程详解    DBMS_OUTPUT.PUT_LINE(
'Area='||area); //表示在屏幕上显示;
【转】oracle 9i存储过程详解
END;
【转】oracle 9i存储过程详解
/   //表示执行这个PL/SQL块;
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解注意:必须在SQL
*PLUS中提前输入:SET SERVEROUTPUT ON 才能显示的输出。
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解
2.变量类型:
【转】oracle 9i存储过程详解变量名   变量类型 ;
/ : = [初始数值] ;
【转】oracle 9i存储过程详解  id   
INTEGER ;
【转】oracle 9i存储过程详解name   
VARCHAR2(20) :='BinMing';
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解  
* proname product.price%TYPE ; // (%TYPE) 表示proname 的类型要和product表中的price的类型一致。
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解
3.条件逻辑:
【转】oracle 9i存储过程详解
1.IF [条件1] THEN
【转】oracle 9i存储过程详解    
[语句段]
【转】oracle 9i存储过程详解  ELSEIF 
[条件2] THEN
【转】oracle 9i存储过程详解      .
【转】oracle 9i存储过程详解.
【转】oracle 9i存储过程详解.
【转】oracle 9i存储过程详解  
END IF ;
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解
2.循环(简单循环/WHILE/FOR)
【转】oracle 9i存储过程详解  单循环:
【转】oracle 9i存储过程详解LOOP 
【转】oracle 9i存储过程详解  statements
【转】oracle 9i存储过程详解
END LOOP;
【转】oracle 9i存储过程详解
//一直循环语句段,除非显示的输入EXIT / EXIT WHEN 语句结束循环
【转】oracle 9i存储过程详解      
【转】oracle 9i存储过程详解  WHILE循环:
【转】oracle 9i存储过程详解
WHILE condition LOOP
【转】oracle 9i存储过程详解    statements
【转】oracle 9i存储过程详解
END LOOP;
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解example:
【转】oracle 9i存储过程详解  
count:=0;
【转】oracle 9i存储过程详解  
WHILE counter<6 LOOP 
【转】oracle 9i存储过程详解    
count :=count + 1 ;
【转】oracle 9i存储过程详解  
END LOOP ;
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解
3.FOR循环:
【转】oracle 9i存储过程详解
FOR loop_variable IN [REVERSE] lower_bound..upper_bound LOOP
【转】oracle 9i存储过程详解  statements;
【转】oracle 9i存储过程详解
END LOOP;
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解example:
【转】oracle 9i存储过程详解  
FOR id IN 3..6 LOOP
【转】oracle 9i存储过程详解  DBMS_OUTPUT.PUT_LINE(id);
【转】oracle 9i存储过程详解  
END LOOP;
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解
4.游标的使用:
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解步骤一: 声明变量来存储例值 :
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解
DECLARE
【转】oracle 9i存储过程详解  id products.id
%TYPE;
【转】oracle 9i存储过程详解  【转】oracle 9i存储过程详解【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解  【转】oracle 9i存储过程详解【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解步骤二: 声明游标 :
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解游标要放在声明部分中。
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解
CURSOR product_cursor IS   
【转】oracle 9i存储过程详解  
Select 
【转】oracle 9i存储过程详解  id,name,price
【转】oracle 9i存储过程详解  
FROM
【转】oracle 9i存储过程详解  products
【转】oracle 9i存储过程详解  
ORDER BY
【转】oracle 9i存储过程详解  id;
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解        
//声明了游标的类型或着说方法
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解步骤三:打开游标 :
【转】oracle 9i存储过程详解使用OPEN语句打开游标,必须放在块的可执行部分中。
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解  
OPEN product_cursor ;
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解步骤四: 从游标中获取行:
【转】oracle 9i存储过程详解使用 
FETCH 语句读取游标中的行:
【转】oracle 9i存储过程详解  
FETCH:
【转】oracle 9i存储过程详解  product_cursor;
【转】oracle 9i存储过程详解  
INTO
【转】oracle 9i存储过程详解  id,name,price;   
//把值存储到上面声明的三个变量中.
【转】oracle 9i存储过程详解
// 如果游标返回可能包含很多行的话,就要循环取出每一行数据,
【转】oracle 9i存储过程详解  可以使用product_cursor
%NOTFOUND决定虚幻何时结束。
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解步骤五: 关闭游标:
【转】oracle 9i存储过程详解
CLOSE product_cursor;
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解
5.过程:
【转】oracle 9i存储过程详解    使用PL
/SQL创建包含一组SQL语句和PL/SQL语句的过程。
【转】oracle 9i存储过程详解    可以使用这些过程将业务逻辑集中在数据库中,访问数据
【转】oracle 9i存储过程详解    库的任何程序都可以使用这些过程。
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解    使用Create 
PROCEDURE 语句创建PL/SQL过程:
【转】oracle 9i存储过程详解
Create[OR REPLACE] PROCEDURE procedure_name     //过程名字
【转】oracle 9i存储过程详解
[(parameter_name)[IN|OUT|IN OUT] type[【转】oracle 9i存储过程详解])] //过程使用的参数
【转】oracle 9i存储过程详解{
IS|AS}
【转】oracle 9i存储过程详解{
【转】oracle 9i存储过程详解  body
【转】oracle 9i存储过程详解};
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解.
IN 参数的默认模式。如果在过程运行时参数以有一个值,而且这个值在过程体中不能修改,
【转】oracle 9i存储过程详解  那么就应该指定这种模式。
【转】oracle 9i存储过程详解.OUT 如果参数的值只在过程体中设置,那么就应该指定这种模式。
【转】oracle 9i存储过程详解.
IN OUT 如果在过程被调用时参数可能已经有一个值,但是这个值可以在过程体中修改,那
【转】oracle 9i存储过程详解么就应该指定这种模式。
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解例子程序:
【转】oracle 9i存储过程详解
Create PROCEDURE update_product_price(
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解  p_product_id 
IN products.id%TYPE ;
【转】oracle 9i存储过程详解  p_factor   
IN NUMBER ;
【转】oracle 9i存储过程详解  
【转】oracle 9i存储过程详解  ) 
AS
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解  product_count 
INTEGER ;
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解  
BEGIN 
【转】oracle 9i存储过程详解  
Select 
【转】oracle 9i存储过程详解  
COUNT(*)
【转】oracle 9i存储过程详解  
INTO
【转】oracle 9i存储过程详解  product_count
【转】oracle 9i存储过程详解  
FROM 
【转】oracle 9i存储过程详解  products
【转】oracle 9i存储过程详解  
Where
【转】oracle 9i存储过程详解  id 
= p_product_id;
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解  
IF product_count = 1 THEN
【转】oracle 9i存储过程详解  
Update
【转】oracle 9i存储过程详解      products
【转】oracle 9i存储过程详解  
SET
【转】oracle 9i存储过程详解      price 
= price * p_factor ;
【转】oracle 9i存储过程详解  
COMMIT ;
【转】oracle 9i存储过程详解  
END IF ;
【转】oracle 9i存储过程详解
【转】oracle 9i存储过程详解  
END update_product_price ;
【转】oracle 9i存储过程详解  
/
【转】oracle 9i存储过程详解

相关文章:

  • 2021-07-16
  • 2022-12-23
  • 2022-12-23
  • 2021-08-31
  • 2022-12-23
  • 2021-12-23
  • 2022-01-03
  • 2022-12-23
猜你喜欢
  • 2021-05-31
  • 2022-01-30
  • 2022-12-23
  • 2021-07-18
  • 2022-02-07
相关资源
相似解决方案