Home Database Mysql Tutorial Ch 2 PL/SQL编程基础

Ch 2 PL/SQL编程基础

Jun 07, 2016 pm 03:43 PM
sql Base Assembly language programming programming language

编程语言划分如下: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变量分内部和外部

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1657
14
PHP Tutorial
1257
29
C# Tutorial
1230
24
Unleash Your Inner Programmer: C for Absolute Beginners Unleash Your Inner Programmer: C for Absolute Beginners Oct 11, 2024 pm 03:50 PM

C is an ideal language for beginners to learn programming, and its advantages include efficiency, versatility, and portability. Learning C language requires: Installing a C compiler (such as MinGW or Cygwin) Understanding variables, data types, conditional statements and loop statements Writing the first program containing the main function and printf() function Practicing through practical cases (such as calculating averages) C language knowledge

Problem-Solving with Python: Unlock Powerful Solutions as a Beginner Coder Problem-Solving with Python: Unlock Powerful Solutions as a Beginner Coder Oct 11, 2024 pm 08:58 PM

Pythonempowersbeginnersinproblem-solving.Itsuser-friendlysyntax,extensivelibrary,andfeaturessuchasvariables,conditionalstatements,andloopsenableefficientcodedevelopment.Frommanagingdatatocontrollingprogramflowandperformingrepetitivetasks,Pythonprovid

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

Demystifying JavaScript: What It Does and Why It Matters Demystifying JavaScript: What It Does and Why It Matters Apr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

The Key to Coding: Unlocking the Power of Python for Beginners The Key to Coding: Unlocking the Power of Python for Beginners Oct 11, 2024 pm 12:17 PM

Python is an ideal programming introduction language for beginners through its ease of learning and powerful features. Its basics include: Variables: used to store data (numbers, strings, lists, etc.). Data type: Defines the type of data in the variable (integer, floating point, etc.). Operators: used for mathematical operations and comparisons. Control flow: Control the flow of code execution (conditional statements, loops).

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

Python Power, Simplified: A Beginner-Friendly Approach to Programming Python Power, Simplified: A Beginner-Friendly Approach to Programming Oct 11, 2024 pm 04:53 PM

Getting Started with Python Programming Install Python: Download and install from the official website. HelloWorld!: Use print("HelloWorld!") to print the first line of code. Practical case: Calculate the area of ​​a circle: Use π (3.14159) and the radius to calculate the area of ​​the circle. Variables and data types: Use variables to store data. Data types in Python include integers, floating point numbers, strings, and Boolean values. Expressions and assignments: Use operators to connect variables, constants, and functions, and use the assignment operator (=) to assign values ​​to variables. Control flow: if-else statement: execute different code blocks based on conditions, determine odd

Demystifying C: A Clear and Simple Path for New Programmers Demystifying C: A Clear and Simple Path for New Programmers Oct 11, 2024 pm 10:47 PM

C is an ideal choice for beginners to learn system programming. It contains the following components: header files, functions and main functions. A simple C program that can print "HelloWorld" needs a header file containing the standard input/output function declaration and uses the printf function in the main function to print. C programs can be compiled and run by using the GCC compiler. After you master the basics, you can move on to topics such as data types, functions, arrays, and file handling to become a proficient C programmer.

See all articles