先创建表:

CREATE TABLE TB_USER
(
    ID INTEGER PRIMARY KEY,
    USER_NAME VARCHAR2(20) NOT NULL,
    USER_AGE INTEGER NOT NULL
);

CREATE SEQUENCE SEQ_USER
INCREMENT BY 1
START WITH 1
NOMAXVALUE
NOCYCLE
CACHE 10;

CREATE OR REPLACE TRIGGER TR_USER BEFORE INSERT ON TB_USER FOR EACH ROW
BEGIN
    SELECT SEQ_USER.NEXTVAL INTO :NEW.ID FROM DUAL;
END;



插入些数据。

创建record:

CREATE OR REPLACE PROCEDURE PR_RECORD(USER_ID IN NUMBER) AS
TYPE USER_RECORD_TYPE IS RECORD(R_NAME TB_USER.USER_NAME%TYPE, R_AGE TB_USER.USER_AGE%TYPE);
V_RECORD USER_RECORD_TYPE;
BEGIN
  SELECT USER_NAME, USER_AGE INTO V_RECORD FROM TB_USER WHERE ID=USER_ID;
  DBMS_OUTPUT.PUT_LINE(V_RECORD.R_NAME);
END;



record类似于C语言里的结构体。

执行:

CALL PR_RECORD(1);