①输入参数:有调用者传递给存储过程,无论存储过程如何调用该参数,该参数的值都不能被改变,可以认为该参数的值是只读的。②输出
一 存储过程的基本应用
1 创建存储过程(SQL窗口)
create or replace procedure update_staff
as
begin
update staff set name = 'xy';
commit;
end update_staff;
存储过程适合做更新操作,,特别是大量数据的更新
2 查看存储过程在数据字典中的信息(SQL窗口)
select object_name,object_type,status from user_objects where lower(object_name) = 'update_staff'
3 查看存储过程语句(SQL窗口)
select * from user_source where lower(name) = 'update_staff'
4 执行存储过程(Command窗口)
execute update_staff;
5 存储过程的优点
① 提高数据库执行效率。使用SQL接口更新数据库,如果更新复杂而频繁,则需要频繁得连接数据库。
② 提高安全性。存储过程作为对象存储在数据库中,可以对其分配权限。
③ 可复用性。
二 带输入参数的存储过程
1 创建存储过程(SQL窗口)
create or replace procedure update_staff(in_age in number) as
begin
declare newage number;
begin
newage := in_age + 10;
update staff set age = newage;
commit;
end;
end update_staff;
2 执行存储过程(Command窗口)
execute update_staff(10);
3 默认值
只有in参数可以有默认值,比如
create or replace procedure update_staff(in_name in varchar2,in_age in number default 20)
调用时可只写execute update_staff('xy');
三 带输出参数的存储过程
1 创建存储过程(SQL窗口)
create or replace procedure update_staff (in_age in number,out_age out number) as
begin
update staff set age = in_age;
select age into out_age from student where num = 1;
commit;
end update_staff;
存储过程没有显示制定返回值,但输出参数可以输出
2 输出存储过程结果(Command窗口)
set serverout on;
declare age number;
begin
update_staff(20,age);
dbms.output.put_line(age);
end;
四 带输入输出的存储过程
其中最典型的应用是交换两个数的值
1 创建存储过程(SQL窗口)
create or replace procedure swap (param1 in out number, param2 in out number) as
begin
declare param number;
begin
param:=param1;
param1:=param2;
param2:=param;
end;
end swap;
2 输出存储过程结果(Command窗口)
set serverout on;
declare p1 number:= 25;
p2 number:=35;
begin
swap(p1,p2);
dbms_output.put_line(p1);
end;
五 参数总结
①输入参数:有调用者传递给存储过程,无论存储过程如何调用该参数,该参数的值都不能被改变,可以认为该参数的值是只读的。
②输出参数:可以作为返回值来用。可以认为可写。
③输入输出参数:这中类型的参数和java方法中的参数最像,传入方法,可读可写(final标识符除外)。
④参数顺序总结如下:具有默认值的参数应该位于参数列表的末尾,因为有时用户需要省略该参数。没有默认值的参数可以遵循"in -> out -> in out"。

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

The MySQL learning path includes basic knowledge, core concepts, usage examples, and optimization techniques. 1) Understand basic concepts such as tables, rows, columns, and SQL queries. 2) Learn the definition, working principles and advantages of MySQL. 3) Master basic CRUD operations and advanced usage, such as indexes and stored procedures. 4) Familiar with common error debugging and performance optimization suggestions, such as rational use of indexes and optimization queries. Through these steps, you will have a full grasp of the use and optimization of MySQL.

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.

SQL commands in MySQL can be divided into categories such as DDL, DML, DQL, DCL, etc., and are used to create, modify, delete databases and tables, insert, update, delete data, and perform complex query operations. 1. Basic usage includes CREATETABLE creation table, INSERTINTO insert data, and SELECT query data. 2. Advanced usage involves JOIN for table joins, subqueries and GROUPBY for data aggregation. 3. Common errors such as syntax errors, data type mismatch and permission problems can be debugged through syntax checking, data type conversion and permission management. 4. Performance optimization suggestions include using indexes, avoiding full table scanning, optimizing JOIN operations and using transactions to ensure data consistency.

InnoDB achieves atomicity through undolog, consistency and isolation through locking mechanism and MVCC, and persistence through redolog. 1) Atomicity: Use undolog to record the original data to ensure that the transaction can be rolled back. 2) Consistency: Ensure the data consistency through row-level locking and MVCC. 3) Isolation: Supports multiple isolation levels, and REPEATABLEREAD is used by default. 4) Persistence: Use redolog to record modifications to ensure that data is saved for a long time.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL is suitable for small and large enterprises. 1) Small businesses can use MySQL for basic data management, such as storing customer information. 2) Large enterprises can use MySQL to process massive data and complex business logic to optimize query performance and transaction processing.

InnoDB effectively prevents phantom reading through Next-KeyLocking mechanism. 1) Next-KeyLocking combines row lock and gap lock to lock records and their gaps to prevent new records from being inserted. 2) In practical applications, by optimizing query and adjusting isolation levels, lock competition can be reduced and concurrency performance can be improved.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment