Home Database Mysql Tutorial Oracle中的数组

Oracle中的数组

Jun 07, 2016 pm 03:31 PM
oracle fixed array

--固定数组 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;

 

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

How to add and replace hard disks in oracle rac How to add and replace hard disks in oracle rac Apr 11, 2025 pm 05:39 PM

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.

How to deal with oracle garbled code How to deal with oracle garbled code Apr 11, 2025 pm 07:00 PM

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.

How to re-query oracle How to re-query oracle Apr 11, 2025 pm 07:33 PM

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).

How to check tablespace size of oracle How to check tablespace size of oracle Apr 11, 2025 pm 08:15 PM

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_

How to connect to a cloud server How to connect to a cloud server Apr 11, 2025 pm 06:51 PM

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.

Summary of basic knowledge of oracle database Summary of basic knowledge of oracle database Apr 11, 2025 pm 06:33 PM

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.

How to modify oracle character set How to modify oracle character set Apr 11, 2025 pm 06:57 PM

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).

How to use stored procedures for oracle How to use stored procedures for oracle Apr 11, 2025 pm 07:03 PM

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.

See all articles