Oracle basic knowledge accumulation-oracle for recycling

Scene:
Basic Knowledge Query
Motivation:
Pure basic knowledge is accumulated to facilitate follow-up inquiries. In many occasions, people in charge are talking about going to IOE.
Therefore, inevitably, the use of occasions will be more or less reduced, so according to the customary thinking record.
Environment:
    Oracle Database 11g; PL/SQL Developer
1.for loop fetches cursor data

CREATE OR REPLACE PROCEDURE PRO_TEST_CURSOR_FOR(ERRORMSG OUT VARCHAR2) IS
BEGIN
  DECLARE
    --Define cursors
    CURSOR LOG_INFO_CUR IS
      SELECT * FROM F_LOG_INFO;
  BEGIN
    ERRORMSG := '';
    --Take out a row of data
    FOR F_LOG_INFO_ROW IN LOG_INFO_CUR LOOP
       INSERT INTO F_LOG_INFO_TEMP
        (TASK_ID,
         BEGIN_TIME,
         END_TIME,
         FLAG,
         FAIL_INFO,
         DATA_COUNT,
         TABLE_NAME)
      VALUES
        (F_LOG_INFO_ROW.TASK_ID,
         F_LOG_INFO_ROW.BEGIN_TIME,
         F_LOG_INFO_ROW.END_TIME,
         F_LOG_INFO_ROW.FLAG,
         F_LOG_INFO_ROW.FAIL_INFO,
         F_LOG_INFO_ROW.DATA_COUNT,
         F_LOG_INFO_ROW.TABLE_NAME);
      COMMIT;
    END LOOP;
    END;
EXCEPTION
  WHEN OTHERS THEN
    ERRORMSG := 'PRO_TEST_CURSOR_FOR Throw exception: ' || SQLERRM;
END PRO_TEST_CURSOR_FOR;

2.for loop fetches values

CREATE OR REPLACE PROCEDURE PRO_TEST_CURSOR_FOR2(ERRORMSG OUT VARCHAR2) IS
BEGIN
  BEGIN
    ERRORMSG := '';
    --Take out a row of data
    FOR V_TASK_ID IN 1 .. 100 LOOP
      INSERT INTO F_LOG_INFO_TEMP
        (TASK_ID,
         BEGIN_TIME,
         END_TIME,
         FLAG,
         FAIL_INFO,
         DATA_COUNT,
         TABLE_NAME)
      VALUES
        (V_TASK_ID,
         SYSDATE,
         SYSDATE,
         'FLAG',
         'FAIL_INFO',
         100,
         'TABLE_NAME');
      COMMIT;
    END LOOP;
  END;
EXCEPTION
  WHEN OTHERS THEN
    ERRORMSG := 'PRO_TEST_CURSOR_FOR Throw exception: ' || SQLERRM;
END PRO_TEST_CURSOR_FOR2;

2. Appendix to Table 1 of the Use of this Example

create table F_LOG_INFO
(
  task_id    NUMBER(16) not null,
  begin_time DATE,
  end_time   DATE,
  flag       VARCHAR2(8),
  fail_info  VARCHAR2(512),
  data_count NUMBER(16),
  table_name VARCHAR2(256)
);
alter table F_LOG_INFO
  add constraint PK_F_LOG_INFO primary key (TASK_ID);

3. Appendix to Table 2 of the Use of this Example

create table F_LOG_INFO_TEMP
(
  task_id    NUMBER(16) not null,
  begin_time DATE,
  end_time   DATE,
  flag       VARCHAR2(8),
  fail_info  VARCHAR2(512),
  data_count NUMBER(16),
  table_name VARCHAR2(256)
);
alter table F_LOG_INFO_TEMP
  add constraint PK_F_LOG_INFO_TEMP primary key (TASK_ID);
  

Thank you.

Keywords: less Oracle Database SQL

Added by Randomizer on Fri, 04 Oct 2019 06:38:06 +0300