【发布时间】:2020-01-28 10:31:03
【问题描述】:
只是想寻求帮助,我创建了一个脚本,它将首先检查表是否已经存在。如果表不存在,那么我需要创建一个表,然后我将在光标中选择它。我只需要创建一次表,然后如果表存在,我应该只插入数据。这应该只是一个 sql 脚本中的地址。
问题是当我尝试执行我的脚本时,它显示“表或视图不存在”,似乎当我运行我的脚本时光标正在尝试验证它。有没有办法解决这个问题?
DECLARE
tbl_exist_s1 PLS_INTEGER;
tbl_exist_s2 PLS_INTEGER;
total_were_updated_sc2 NUMBER(10,0);
total_need_to_update_sc2 NUMBER(10,0);
total_were_updated_sc1 NUMBER(10,0);
total_need_to_update_sc1 NUMBER(10,0);
run_date Date := SYSDATE;
BEGIN
DBMS_OUTPUT.ENABLE(NULL);
--Checking if the table is already existing, create table if not existing.
select count(*) into tbl_exist_s2
from all_tables
where owner = 'cent' AND table_name = 'serv_req';
DBMS_OUTPUT.PUT_LINE('Cleanup run: ' || SYSDATE);
if (tbl_exist_s2 = 0) THEN
DBMS_OUTPUT.PUT_LINE('Start Creating table cent.serv_req');
EXECUTE IMMEDIATE 'CREATE TABLE cent.serv_req (
association_type NUMBER(10,0),
association_id NUMBER(10,0),
association_id_serv NUMBER(10,0),
request_id NUMBER(10, 0)
record_audit_datet DATE,
CONSTRAINT pk_sc1 PRIMARY KEY(association_type, association_id, association_id_serv))';
END IF;
-- this is to insert the new data to the table.
EXECUTE IMMEDIATE 'INSERT INTO cent.serv_req
VALUES(12, 13, 14, 1172, SYSDATE)';
commit;
DECLARE
v_err_comp CHAR(2000);
c SYS_REFCURSOR;
CURSOR sample_cursor IS
select *
from cent.serv_req
where record_audit_date = run_date;
sample_cursor_rec sample_cursor%ROWTYPE;
BEGIN
-- This will count the no of the records that are getting updated
total_need_to_update_sc2 := 0;
total_were_updated_sc2 := 0;
DBMS_OUTPUT.PUT_LINE('===Starting process to activate the component element record associated to the active member instance record===');
-- this loop is to update the component element
OPEN sample_cursor ;
LOOP
FETCH sample_cursor INTO sample_cursor_rec;
EXIT WHEN sample_cursor % NOTFOUND;
DBMS_OUTPUT.PUT_LINE('===sample===');
--Logic should be here
END;
END LOOP;
CLOSE sample_cursor;
END;
END;
【问题讨论】:
标签: oracle oracle-sqldeveloper plsqldeveloper