Home > database >  The oracle stored procedure error, please the great god
The oracle stored procedure error, please the great god

Time:01-15

Manufacturer writing stored procedures:
The create or replace procedure PDataSavedWithRelation_Sp (p_string in Varchar2, p_relation Varchar2 in
) as

V_num number;
V_haverelation number;
V_ERRMSG varchar2 (80);
V_ERRNO number;
- v_isinsert number;
V_pkfield varchar2 (50);
V_temp varchar2 (50);
V_PKValuetemp varchar2 (100);
V_pkvalue number;
V_FieldSQL varchar2 (2000);
V_ValueSQL varchar2 (2000);
V_strarry ty_str_split:=new ty_str_split ();

CURSOR ctables IS
SELECT *
FROM the TABLE (CAST (fn_split (p_string, ';; ') AS
Ty_str_split));

CURSOR cRelation is SELECT *
FROM the TABLE (CAST (fn_split (p_relation, ';; ') AS
Ty_str_split));

Cursor find_pk_field (var_tablename varchar2) is
The select col. Column_name
The from user_cons_columns col,
User_constraints con
Where col. Constraint_name=con. Constraint_name
And con. Constraint_type='P'
And upper (col. Table_name)=upper (var_tablename);



R ctables % ROWTYPE;
R1 cRelation % ROWTYPE;
The BEGIN
The savepoint V_SP_0000;
V_ERRNO:=2000;
V_FieldSQL:=';
V_temp:='-';
V_ValueSQL:=';

Select count (1) into v_num from user_tables where table_name='T_TEMP';

If v_num & lt; 1 then
The execute immediate 'CREATE GLOBAL TEMPORARY TABLE T_TEMP (
Tablename varchar2 (50),
Fieldname varchar2 (50),
Fieldvalue varchar2 (3000),
DataType varchar2 (20)
) ON the COMMIT delete ROWS ';
End the if;

The OPEN ctables;
The FETCH ctables
INTO r;
LOOP
EXIT the WHEN ctables % NOTFOUND;
DBMS_OUTPUT. Put_line (r.C olumn_value);
The execute immediate 'insert into T_TEMP values (',' | | the replace (r.C olumn_value, 'and,', ' ' ' ' ' ') | | ' ' ') '.
The FETCH ctables
INTO r;
END LOOP;

The CLOSE ctables;

Select count (1) into v_num from user_tables where table_name='T_RELATION';

If v_num & lt; 1 then
The execute immediate 'CREATE GLOBAL TEMPORARY TABLE T_RELATION (
Ptablename varchar2 (50),
Pfieldname varchar2 (50),
Ctablename varchar2 (50),
Cfieldname varchar2 (50),
Fieldvalue varchar2 (3000),
DataType varchar2 (20)
) ON the COMMIT delete ROWS ';
End the if;

The OPEN cRelation;
The FETCH cRelation
INTO r1.
LOOP
EXIT the WHEN cRelation % NOTFOUND;
If r1. Column_value is not null then
The execute immediate 'insert into T_RELATION values (',' | | the replace (r1) Column_value, 'and,', ' ' ' ' ' ') | | ' ' ') '.
End the if;
The FETCH cRelation
INTO r1.
END LOOP;

The CLOSE cRelation;

For emm in (select tablename from (select min (the Rowid) xh, tablename from T_TEMP group by tablename) order by xh) loop
The open find_pk_field (emm) tablename);
The fetch find_pk_field into v_pkfield;
The close find_pk_field;
The select fieldvalue into v_PKValuetemp from T_TEMP where tablename=emm. The tablename and fieldname=v_pkfield;
If v_PKValuetemp is null or v_PKValuetemp='null' then
V_num:=0;
The else
V_num:=1;
End the if;
If v_num & lt; 1 then
The select GetSequenceValue (emm) tablename) into v_pkvalue from dual;
The update T_TEMP set fieldvalue=https://bbs.csdn.net/topics/v_pkvalue where tablename=emm. Tablename and upper (fieldname)=upper (v_pkfield);
End the if;

For fee (in the select fieldname, fieldvalue, datatype from T_TEMP where tablename=emm. The tablename) loop
If fee fieldname!=v_temp then
V_temp:=fee. Fieldname;
If v_num & lt; 1 then


Case fee. The datatype
When the 'V' then
V_FieldSQL:=v_FieldSQL | | ', '| | fee. The fieldname;
V_ValueSQL:=v_ValueSQL | | ', ' '| | case when fee. The fieldvalue=' https://bbs.csdn.net/topics/null 'then' else fee. The fieldvalue end | | ' ' ' ';
When the 'v' then
V_FieldSQL:=v_FieldSQL | | ', '| | fee. The fieldname;
V_ValueSQL:=v_ValueSQL | | ', ' '| | case when fee. The fieldvalue=' https://bbs.csdn.net/topics/null 'then' else fee. The fieldvalue end | | ' ' ' ';
When the 'N' then
V_FieldSQL:=v_FieldSQL | | ', '| | fee. The fieldname;
V_ValueSQL:=v_ValueSQL | | ', '| | case when fee. The fieldvalue is null then' null 'the else fee. The fieldvalue end;
When the 'n' then
V_FieldSQL:=v_FieldSQL | | ', '| | fee. The fieldname;
V_ValueSQL:=v_ValueSQL | | ', '| | case when fee. The fieldvalue is null then' null 'the else fee. The fieldvalue end;
When 'D' then
V_FieldSQL:=v_FieldSQL | | ', '| | fee. The fieldname;
V_ValueSQL:=v_ValueSQL | | ', to_date (' ' '| | fee. The fieldvalue | |' ' ', '- dd yyyy - mm hh24: mi: ss') '.
When 'd' then
V_FieldSQL:=v_FieldSQL | | ', '| | fee. The fieldname;
V_ValueSQL:=v_ValueSQL | | ', to_date (' ' '| | fee. The fieldvalue | |' ' ', '- dd yyyy - mm hh24: mi: ss') '.
The else
V_FieldSQL:=v_FieldSQL | | ', '| | fee. The fieldname;
V_ValueSQL:=v_ValueSQL | | ', '| | fee. The fieldvalue;
End a case;
The else
If fee. Fieldname=v_pkfield then
V_pkvalue:=fee. Fieldvalue;
End the if;
Case fee. The datatype
When the 'V' then
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related