Oracle中的数组
--固定数组 declare type type_array is varray(10) of varchar2(20); var_array type_array:=type_array('ggs','jjh','wsb','csl','dd','bb'); begin for i in 1..var_array.count loop dbms_output.put_line(var_array(i)); end loop; end; --可变数组 dec
--固定数组
declare
type type_array is varray(10) of varchar2(20);
var_array type_array:=type_array('ggs','jjh','wsb','csl','dd','bb');
begin
for i in 1..var_array.count loop
dbms_output.put_line(var_array(i));
end loop;
end;
--可变数组
declare
type type_array is table of varchar2(20) index by binary_integer;
var_array type_array;
begin
var_array(1):='aa';
var_array(2):='bb';
for i in 1..var_array.count loop
dbms_output.put_line( var_array(i));
end loop;
end;
--可变数组取表
declare
begin
end;
create or replace procedure proc_stock(n number)
as
var_stock_code varchar2(10);
var_stock_price number;
begin
for i in 1..n loop
var_stock_code:= lpad(STR1 =>i ,LEN =>6 ,PAD =>'0' ) ;
var_stock_price:=trunc(dbms_random.value*100)+1;
--dbms_output.put_line(var_stock_code);
--dbms_output.put_line(var_stock_price);
insert into t_stock (stockcode,stockprice)
values(var_stock_code,var_stock_price);
commit;
end loop;
end;
declare
begin
proc_stock(1000000);
end;
--用游标访问 14.578秒 13.5 13.8
declare
cursor cur is select * from t_stock;
row_stock t_stock%rowtype;
begin
open cur;
loop
fetch cur into row_stock;
exit when cur%notfound;
null;
end loop;
close cur;
end;
--用数组实现 4.813 1.953 2
declare
type type_array is table of t_stock%rowtype index by binary_integer;
var_array type_array;
begin
select * bulk collect into var_array from t_stock;
for i in 1..var_array.count loop
null;
end loop;
end;
--访问自定义表
declare
type type_record is record(
username varchar2(20),
sex varchar2(2)
);
type_record_user type_record;
type type_array is table of type_record_user%type index by binary_integer;
var_array type_array;
begin
select username,sex bulk collect into var_array from tuser;
for i in 1..var_array.count loop
dbms_output.put_line(var_array(i).username);
dbms_output.put_line(var_array(i).sex);
end loop;
end;

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



Oracle RAC hard disk new and replacement operations: Add hard disk: Add new disks, create ASM disk groups, add to clusters, move data files. Replace hard disk: Identify the failed hard disk, close the disk group, replace the hard disk, reopen the disk group, repair the failed disk, and move the data files.

Oracle garbled problems are usually caused by improper character set settings. Solutions include: Checking the server, database, and client character sets. Set up the server, database, and client character sets as needed. Use the CONVERT function or the DBMS_LOB.CONVERT_LOB function to fix garbled data. Always specify the character set and set the NLS parameters correctly.

Oracle provides multiple deduplication query methods: The DISTINCT keyword returns a unique value for each column. The GROUP BY clause groups the results and returns a non-repetitive value for each group. The UNIQUE keyword is used to create an index containing only unique rows, and querying the index will automatically deduplicate. The ROW_NUMBER() function assigns unique numbers and filters out results that contain only line 1. The MIN() or MAX() function returns non-repetitive values of a numeric column. The INTERSECT operator returns the common values of the two result sets (no duplicates).

To query the Oracle tablespace size, follow the following steps: Determine the tablespace name by running the query: SELECT tablespace_name FROM dba_tablespaces; Query the tablespace size by running the query: SELECT sum(bytes) AS total_size, sum(bytes_free) AS available_space, sum(bytes) - sum(bytes_free) AS used_space FROM dba_data_files WHERE tablespace_

The steps to connect to a cloud server through an Oracle client are as follows: Create an SSH key and copy the public key to the cloud server. Configure the Oracle client and add the connection information of the cloud server to the tnsnames.ora file. Create a new database connection in the Oracle client, enter the username, password, and DSN. Click OK and verify that the connection is successful.

Oracle Database is a reliable, scalable and feature-rich relational database management system (RDBMS). Its architecture follows the client-server model, including server-side components (Oracle Net), instances, shared memory areas (SGAs), background processes, and database files that store data. Basic concepts include tables, rows, columns, primary keys, foreign keys, indexes and cursors. The database is known for its advantages such as high availability, big data support, rich features, strong security and ease of use.

To modify the Oracle character set, you need to: back up the database; modify the character set settings in the init.ora file; restart the database; modify existing tables and columns to use the new character set; reload the data; modify the database link (optional).

A stored procedure is a set of SQL statements that can be stored in a database and can be called repeatedly as a separate unit. They can accept parameters (IN, OUT, INOUT) and provide the advantages of code reuse, security, performance and modularity. Example: Create a stored procedure calculate_sum to calculate the sum of two numbers and store them in the OUT parameter.
