Home > Database > Mysql Tutorial > body text

Ch 2 PL/SQL编程基础

WBOY
Release: 2016-06-07 15:43:20
Original
939 people have browsed it

编程语言划分如下:1GL是汇编语言; 2GL是高级程序设计语言,如FORTRAN,ALGOL,BASIC,LISP等;3GL是增强性的高级程序设计语言,如PASCAL, ALGOL68,FORTRAN77等;4GL是按计算机科学理论指导设计出来的结构化语言,如ADA,MODULA-2,SMALLTALK-80等 PL/S

编程语言划分如下:1GL是汇编语言; 2GL是高级程序设计语言,如FORTRAN,ALGOL,BASIC,LISP等;3GL是增强性的高级程序设计语言,如PASCAL, ALGOL68,FORTRAN77等;4GL是按计算机科学理论指导设计出来的结构化语言,如ADA,MODULA-2,SMALLTALK-80等

PL/SQL基本程序单元是。分:匿名块、过程块(子程序1)、函数块(子程序2)

--块1:匿名块,编译时候自动运行
declare
v_str varchar(50);
v_name varchar(50);
begin
     select ename into v_str from emp where empno = 7369;
     dbms_output.put_line(v_str);
end;
select * from emp;

--块2:过程
--1、生成伪代码见左边,编译,不产生日志文件
create or replace procedure --or replace 在一个过程里面
--变量声明
       pro_emp_getinfo_byId(v_num int) is
       v_name varchar(50);
begin
      select ename into v_name
      from emp where empno = v_num;
      dbms_output.put_line(v_name);
end;
--2、执行
call pro_emp_getinfo_byId(7369);
select *  from emp where empno = 7369;
--块3、函数
create or replace function
       fun_getinfo(v_empno int) return varchar is
       v_name varchar(50);
   begin
       select ename into v_name
         from emp where empno = v_empno;
         return v_name;
   end;
declare
       v_name varchar(50);
   begin
       v_name := fun_getinfo(7369);
       dbms_output.put_line(v_name);
   end;

数据类型

a、标量变量:varchar2(n)同varchar(n)             char(n)固定长度   Number(p,s) p总个数,s小数位数  boolean

     定义:c constant number not null(3,2):=5.5;不能修改c,且非空必须赋值  default**默认

     可以使用“表.列%type”定义类型
b、复合变量可以存放多个变量值

      1、PL/SQL记录   declare
type mytype is record(
  myname f.f_name%type,
  myphoneNo f.f_phoneno%type
  );
my mytype;--自定义类型
mytable f%rowtype;--与表的成员类型一样
begin
    my.myname :='wo';--赋值
select * into mytable from f where myname = 'john';--赋值
end

c、引用变量

d、LOB变量分内部和外部

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!