I am experiencing this error when trying to run the procedure from the codes.
"ORA-01843: not a valid month ORA-06512: at "NOSTAS_OWNER.INSERT_EXPORTMATRIX", line 68 ORA-06512: at line 1"
I'm passing the date as "DD/MM/YYYY" string. Not sure what caused the error. When running it in SQL Developer, it gives this error
ORA-06502: PL/SQL: numeric or value error: character to number conversion error
ORA-06512: at "NOSTAS_OWNER.INSERT_EXPORTMATRIX", line 68
ORA-06512: at line 17
create or replace PROCEDURE INSERT_EXPORTMATRIX
(
keyClass export_matrix.EXM_KEY_CLASS%type,
keyClassValue export_matrix.EXM_KEYCLASS_VALUE%type,
changedClass export_matrix.EXM_CHANGED_CLASS%type,
changedClassValue export_matrix.EXM_CHANGEDCLASS_VALUE%type,
dtTo IN VARCHAR2,
dtFrom IN VARCHAR2,
-- dtTo export_matrix.EXM_DATEFROM%type,
-- dtFrom EXPORT_MATRIX.EXM_DATETO%type,
vresult OUT NUMBER
) AS
iskeyClass number;
--today varchar2(50);
--today date;
fvvECCN number;
fvvALNR number;
BEGIN
iskeyClass := 0;
fvvECCN := 0;
fvvALNR := 0;
SAVEPOINT start_tran;
SELECT count(*) into iskeyClass FROM EXPORT_MATRIX
WHERE EXM_KEY_CLASS=keyClass and EXM_KEYCLASS_VALUE=keyClassValue;
-- SELECT to_date(SYSDATE,'DD/MM/YYYY') into today FROM DUAL;
SELECT count(*) into fvvECCN FROM FIELDS_VALUE_VALIDATION WHERE
--FVV_FAVL_NAME = 'ECCN' and FVV_VALUE = keyClassValue and (dtTo > trunc(sysdate));
FVV_FAVL_NAME = 'ECCN' and FVV_VALUE = keyClassValue and (sysdate between dtFrom and dtTo) or dtTo is null;
SELECT count(*) into fvvALNR FROM FIELDS_VALUE_VALIDATION WHERE
FVV_FAVL_NAME = 'ALNR' and FVV_VALUE = changedClassValue and (sysdate between dtFrom and dtTo) or dtTo is null;
BEGIN
-- if (iskeyClass = 1 and (dtTo < trunc(sysdate))) or iskeyClass = 0 then
if (iskeyClass = 1 and (dtTo between DtFrom and sysdate)) or iskeyClass = 0 then
Insert into EXPORT_MATRIX (EXM_KEY_CLASS, EXM_KEYCLASS_VALUE, EXM_CHANGED_CLASS,
EXM_CHANGEDCLASS_VALUE, EXM_DATEFROM)
values (keyClass,keyClassValue,changedClass,changedClassValue,trunc(sysdate));
if fvvECCN = 0 then
Insert into FIELDS_VALUE_VALIDATION (FVV_FAVL_NAME,FVV_VALUE,FVV_DATEFROM)
values ('ECCN',keyClassValue,trunc(sysdate));
end if;
if fvvALNR = 0 then
Insert into FIELDS_VALUE_VALIDATION (FVV_FAVL_NAME,FVV_VALUE,FVV_DATEFROM)
values ('ALNR',changedClassValue,trunc(sysdate));
end if;
end if;
-- if keyClass = 1 and (dtTo > trunc(sysdate)) then
if keyClass = 1 and (sysdate between dtFrom and dtTo) or dtTo is null then
update EXPORT_MATRIX set
EXM_DATETO=to_date(dtTo)
WHERE EXM_KEY_CLASS=keyClass and EXM_KEYCLASS_VALUE=keyClassValue;
end if;
END;
commit;
vresult := 1;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK TO start_tran;
RAISE;
END INSERT_EXPORTMATRIX;
You should add a mask when you convert a string to date:
to_date(dtTo,'DD/MM/YYYY')
Moreover, you should also convert string to date when you comparing with sysdate, so:
sysdate between to_date(dtFrom,'DD/MM/YYYY') and to_date(dtTo,'DD/MM/YYYY')
Related
I am attempting to run this code, I know the elements of the Loop are working, and I know the update statement does update. When I run the script with some print statements, it prints the UPDATE information first, then the LOOP information, therefore the update has no information.
PROCEDURE UpdateGridStats(p_grid_name VARCHAR2, p_region_name VARCHAR2) IS
CURSOR c1 IS
SELECT grd.globalid grid_globalid, wp.globalid workpoint_globalid, wp.feature_class_name workpoint_fcname,
tt.work_order_task_type task_type_name
FROM workorderpoint_evw wp, rpt_grid grd, workordertasktype_evw tt
WHERE grd.grid_name = p_grid_name
AND wp.work_order_task_type_globalid = tt.globalid
AND grd.rpt_region = p_region_name
AND sde.st_relation_operators.st_within_f(wp.shape, grd.shape) = 1;
v_count NUMBER := 0;
v_pole_insp_count NUMBER := 0;
v_pole_damage_count NUMBER := 0;
v_cond_damage_count NUMBER := 0;
BEGIN
FOR work_rec IN c1
LOOP
BEGIN
v_count := v_count + 1;
IF work_rec.task_type_name = 'Pole Inspection'
THEN
v_pole_insp_count := v_pole_insp_count + 1;
END IF;
IF work_rec.task_type_name = 'Pole Damage'
THEN
v_pole_damage_count := v_pole_damage_count + 1;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
dbms_output.put_line('==> No data found for work record ');
END;
END LOOP;
dbms_output.put_line(v_pole_damage_count || ',' ||v_pole_insp_count);
UPDATE rpt_grid grd SET da_pole_count = v_pole_damage_count, ins_structure_count = v_pole_insp_count
WHERE grd.grid_name = p_grid_name
AND grd.rpt_region = p_region_name;
END UpdateGridStats;
Maybe you just forgot to commit your changes?
Here is a simpler version of your stored procedure.
CREATE OR REPLACE PROCEDURE update_grid_stats(p_grid_name VARCHAR2, p_region_name VARCHAR2)
IS
v_ins_structure_count rpt_grid.ins_structure_count%TYPE;
v_da_pole_count rpt_grid.da_pole_count%TYPE;
BEGIN
UPDATE rpt_grid grd
SET (ins_structure_count, da_pole_count) =
(
SELECT
COUNT(CASE WHEN tt.work_order_task_type = 'Pole Inspection' THEN 1 END),
COUNT(CASE WHEN tt.work_order_task_type = 'Pole Damage' THEN 1 END)
FROM workorderpoint_evw wp
JOIN workordertasktype_evw tt ON wp.work_order_task_type_globalid = tt.globalid
WHERE sde.st_relation_operators.st_within_f(wp.shape, grd.shape) = 1
)
WHERE grd.grid_name = p_grid_name
AND grd.rpt_region = p_region_name
RETURNING ins_structure_count, da_pole_count
INTO v_ins_structure_count, v_da_pole_count;
dbms_output.put_line(
SQL%ROWCOUNT || ' rows got updated. Values: ' ||
'ins_structure_count = ' || v_ins_structure_count ||
', da_pole_count = ' || v_da_pole_count
);
COMMIT;
END update_grid_stats;
The variables and the RETURNING clause are merely needed for the output. If you don't need the output, you can remove them.
if I understand correcatally, the proc works OK, but the print statemnts are not. I beleve the print operations are on a different thread. To overcome this issue, try to replace your pront statment with raiserror function :
declare #mag varchar(max) = 'Hllo world'
raiserror ( #ERR_MSG ,0, 1) with nowait;
I have the following block of code. Can someone help me in rectifying the same.
CREATE OR REPLACE package body NMS.ResourceBindDistribute_withfile is
v_date date :=sysdate ;
v_user varchar2(10) := 'NMS';
procedure create_SIMDMLNK_new(v_SIMRANGE varchar2 , v_MSISDN varchar2,v_TECH varchar2) is
v_SIM_count integer;
v_dlink_dn_cnt integer;
v_dlink_dn integer;
v_counter integer;
v_new_dn_cnt integer;
v_free_count integer := 0;
sm_count integer;
ms_count integer;
cursor sim_curr is
select sim from temp_SIM_MSISDN;
cursor msisdn_curr is
select msidn from temp_SIM_MSISDN;
/* Cursor to selecet SIM for linking*/
cursor simcusrsor_3G (l_SIMRANGE varchar2) is
select sm_id,SM_SERIALNUM from storage_medium where SM_SERIALNUM in
(select SM_SERIALNUM from storage_medium
where SM_SERIALNUM = l_SIMRANGE and SM_STATUS='r' and SMC_ID in (1,2)
minus
(select SM_SERIALNUM from NMS.SIMDMSLNK where SM_SERIALNUM = l_SIMRANGE
union
select SM_SERIALNUM from NMS.SIMULNK where SM_SERIALNUM = l_SIMRANGE));
cursor simcusrsor_4G (l_SIMRANGE varchar2) is
select sm_id,SM_SERIALNUM from storage_medium where SM_SERIALNUM in
(select SM_SERIALNUM from storage_medium
where SM_SERIALNUM = l_SIMRANGE and SM_STATUS='r' and SMC_ID in (3)
minus
(select SM_SERIALNUM from NMS. SIMDMSLNK where SM_SERIALNUM = l_SIMRANGE
union
select SM_SERIALNUM from NMS.SIMULNK where SM_SERIALNUM = l_SIMRANGE));
type t_simcursor is table of simcusrsor_3G%rowtype index by PLS_INTEGER;
v_simsoure t_simcursor;
/* Cursor to select Dlinked MSISDN for linking with New SIM*/
cursor dlinkdn_cur (l_MSISDN varchar2) is
select distinct DN_ID,DN_NUM from NMS.SIMDMSLNK where DN_NUM = l_MSISDN and status='D';
type t_dlinkdn_cur is table of dlinkdn_cur %rowtype index by PLS_INTEGER;
v_dlinkdn_cur_source t_dlinkdn_cur ;
/* Cursor to select new Dummy MSISDN for linking with New SIM*/
cursor dummydn_cur (l_MSISDN varchar2) is
select distinct DN_ID, DN_NUM from directory_number where DN_NUM = l_MSISDN
and dn_status = 'f' and evcode is null and rscode=2 and DN_TYPE=3
minus
select distinct DN_ID,DN_NUM from NMS.SIMDMSLNK where DN_NUM = l_MSISDN;
type t_dummydn_cur is table of dummydn_cur%rowtype index by PLS_INTEGER;
v_dummydn_source t_dummydn_cur;
type t_SIMDMSLNK is table of NMS.SIMDMSLNK%rowtype index by PLS_INTEGER;
v_SIMDM_target t_SIMDMSLNK;
v_simdml_count PLS_INTEGER :=1;
NO_SIM_WITH_RANGE exception;
NO_DUMMY_DN_WITH_RANGE exception;
BEGIN
select count(1) into v_new_dn_cnt from
(select distinct DN_NUM from directory_number where DN_NUM = v_MSISDN
and dn_status = 'f' and evcode is null and rscode=2 and DN_TYPE=3
minus
select distinct DN_NUM from NMS.SIMDMSLNK where DN_NUM = v_MSISDN );
select count(distinct DN_NUM) into v_dlink_dn from NMS.SIMDMSLNK where DN_NUM = v_MSISDN and status='D';
if ( v_dlink_dn =0 and v_new_dn_cnt = 0) then
raise NO_DUMMY_DN_WITH_RANGE;
end if;
v_free_count := v_new_dn_cnt + v_dlink_dn;
/* Cusrsor opened Dlinked MSISDN, to assign first DLINKED MSISDN */
BEGIN
open msisdn_curr;
for i in msisdn_curr
LOOP
select count(*) into ms_count from directory_number where dn_num = i.msisdn;
if
ms_count > 0
then
open dlinkdn_cur (v_MSISDN);
fetch dlinkdn_cur bulk collect into v_dlinkdn_cur_source;
IF v_dlinkdn_cur_source.count = 0 THEN
RAISE NO_DATA_FOUND;
ELSE
v_dlink_dn_cnt := v_dlinkdn_cur_source.count;
DBMS_OUTPUT.PUT_LINE ( 'FIRST D-LINKED MSISDN ARE LINKED TO SIM.');
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE ( 'NO FREE D-LINKED MSISDN ARE AVAILABLE, FREE DUMMY MSISDN WILL BE USED FOR ASSOSOIATION.');
END IF;
END LOOP;
END;
open sim_curr
for i in sim_curr
LOOP
select count(*) into sm_count from storage_medium where sm_serialnum=i.sim;
if
sm_count > 0
then
IF v_TECH = 3 THEN
open simcusrsor_3G (v_SIMRANGE);
fetch simcusrsor_3G bulk collect into v_simsoure;
END IF;
IF v_TECH = 4 THEN
open simcusrsor_4G (v_SIMRANGE);
fetch simcusrsor_4G bulk collect into v_simsoure;
END IF;
v_SIM_count := v_simsoure.count;
IF v_SIM_count = 0 then
raise NO_SIM_WITH_RANGE;
END IF;
END IF;
END LOOP;
/* Cusrsor opened NEW DUMMY MSISDN, to assign NEW DUMMY MSISDN */
BEGIN
open msisdn_curr;
for i in msisdn_curr
LOOP
select count(*) into ms_count from directory_number where dn_num = i.msisdn;
if
ms_count > 0
then
open dummydn_cur (v_MSISDN);
fetch dummydn_cur bulk collect into v_dummydn_source;
IF v_dummydn_source.count = 0 THEN
RAISE NO_DATA_FOUND;
ELSE
DBMS_OUTPUT.PUT_LINE ( 'NEW DUMMY MSISDN ARE LINKED TO SIM.');
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE ( 'NO NEW DUMMY MSISDN IS AVAILABL FOR ASSOSOIATION.');
END IF;
END LOOP;
END;
v_counter :=1;
for l_sim_counter in v_simsoure.first .. v_simsoure.last
loop
if l_sim_counter = ( v_free_count) then
if l_sim_counter <= v_dlink_dn_cnt then
v_SIMDM_target(v_simdml_count).DN_ID := v_dlinkdn_cur_source(l_sim_counter).DN_ID;
v_SIMDM_target(v_simdml_count).DN_NUM := v_dlinkdn_cur_source(l_sim_counter).DN_NUM;
DELETE from NMS.SIMDMSLNK where DN_ID=v_dlinkdn_cur_source(l_sim_counter).DN_ID and STATUS='D';
else
v_SIMDM_target(v_simdml_count).DN_ID := v_dummydn_source(v_counter).DN_ID;
v_SIMDM_target(v_simdml_count).DN_NUM := v_dummydn_source(v_counter).DN_NUM;
v_counter := v_counter +1 ;
end if;
v_SIMDM_target(v_simdml_count).SM_SERIALNUM := v_simsoure(l_sim_counter).SM_SERIALNUM;
v_SIMDM_target(v_simdml_count).SM_ID := v_simsoure(l_sim_counter).SM_ID;
v_SIMDM_target(v_simdml_count).USER_LASTMOD := v_user;
v_SIMDM_target(v_simdml_count).LAST_UPDATE := v_date;
v_SIMDM_target(v_simdml_count).STATUS := 'L';
exit;
end if;
if l_sim_counter <= v_dlink_dn_cnt then
v_SIMDM_target(v_simdml_count).DN_ID := v_dlinkdn_cur_source(l_sim_counter).DN_ID;
v_SIMDM_target(v_simdml_count).DN_NUM := v_dlinkdn_cur_source(l_sim_counter).DN_NUM;
DELETE from NMS.SIMDMSLNK where DN_ID=v_dlinkdn_cur_source(l_sim_counter).DN_ID and STATUS='D';
else
v_SIMDM_target(v_simdml_count).DN_ID := v_dummydn_source(v_counter).DN_ID;
v_SIMDM_target(v_simdml_count).DN_NUM := v_dummydn_source(v_counter).DN_NUM;
v_counter := v_counter +1 ;
end if;
v_SIMDM_target(v_simdml_count).SM_SERIALNUM := v_simsoure(l_sim_counter).SM_SERIALNUM;
v_SIMDM_target(v_simdml_count).SM_ID := v_simsoure(l_sim_counter).SM_ID;
v_SIMDM_target(v_simdml_count).USER_LASTMOD := v_user;
v_SIMDM_target(v_simdml_count).LAST_UPDATE := v_date;
v_SIMDM_target(v_simdml_count).STATUS := 'L';
v_simdml_count := v_simdml_count+1;
end loop;
FORALL i IN v_SIMDM_target.FIRST .. v_SIMDM_target.LAST SAVE EXCEPTIONS
INSERT INTO NMS.SIMDMSLNK
VALUES v_SIMDM_target (i);
COMMIT;
close dlinkdn_cur;
close dummydn_cur;
IF v_TECH =3 THEN
close simcusrsor_3G;
ELSE
close simcusrsor_4G;
END IF;
DBMS_OUTPUT.PUT_LINE ( 'SIM & DUMMY MSISDN LINKING PROCESS IS COMPLETED SUCCESSFULLY.');
EXCEPTION
WHEN NO_SIM_WITH_RANGE THEN
DBMS_OUTPUT.PUT_LINE ( 'THERE ARE NO SIMS AVAILABLE FOR TECHNOLOGY WITH GIVEN RANGE = '||v_SIMRANGE);
WHEN NO_DUMMY_DN_WITH_RANGE THEN
DBMS_OUTPUT.PUT_LINE ( 'THERE ARE NO DUMMY MSISDN AVAILABLE FOR GIVEN RANGE = '||v_MSISDN);
WHEN OTHERS THEN
DBMS_OUTPUT.put_line ('SQLCODE : ' || SQLCODE);
DBMS_OUTPUT.put_line ('ERROR MESSAGE : ' || SQLERRM);
ROLLBACK;
END create_SIMDMLNK;
procedure create_REALDN (v_MSISDN varchar2) is
v_DN_count integer;
v_count integer;
NO_DN_WITH_RANGE exception;
DN_WITH_PREPROVISION exception;
BEGIN
select count(DN_ID) into v_DN_count from NMS.SIMDMSLNK
where DN_NUM = v_MSISDN;
if v_DN_count > 0 then
raise DN_WITH_PREPROVISION;
end if;
select count(1) into v_count from
(select DN_ID from DIRECTORY_NUMBER
where DN_NUM = v_MSISDN
MINUS
select DN_ID from NMS.REALDN
where REAL_DN like v_MSISDN||'%');
if v_count = 0 then
raise NO_DN_WITH_RANGE;
end if;
insert into NMS.REALDN (DN_ID,REAL_DN,DN_TYPE,USER_LASTMOD,LAST_UPDATE,STATUS )
select DN_ID,DN_NUM ,DN_TYPE,v_user,v_date,'L' from Directory_number where DN_ID in
((select DN_ID from DIRECTORY_NUMBER
where DN_NUM = v_MSISDN and dn_type not in (1,2) and evcode is null
MINUS
select DN_ID from NMS.REALDN
where REAL_DN = v_MSISDN));
COMMIT;
DBMS_OUTPUT.PUT_LINE ( 'REAL DIRECTORY NUMBER CREATION PROCESS IS COMPLETED SUCCESSFULLY.');
EXCEPTION
WHEN DN_WITH_PREPROVISION THEN
DBMS_OUTPUT.PUT_LINE ( 'MSISDN RANGE IS WITH PREPROVISION POOL ' || v_MSISDN);
WHEN NO_DN_WITH_RANGE THEN
DBMS_OUTPUT.PUT_LINE ( 'NO DN AVAILABLE WITH RANGE ' || v_MSISDN);
WHEN OTHERS THEN
DBMS_OUTPUT.put_line ('SQLCODE : ' || SQLCODE);
DBMS_OUTPUT.put_line ('ERROR MESSAGE : ' || SQLERRM);
ROLLBACK;
END create_REALDN;
procedure create_FREESIM (v_SIMRANGE varchar2) is
v_SIM_count integer;
v_count integer;
NO_SIM_WITH_RANGE exception;
BEGIN
select count(1) into v_count from
(select SM_SERIALNUM from storage_medium
where SM_SERIALNUM = v_SIMRANGE and SM_STATUS='r' and SMC_ID in (3)
minus
(select SM_SERIALNUM from NMS. SIMDMSLNK where SM_SERIALNUM = v_SIMRANGE
union
select SM_SERIALNUM from NMS.SIMULNK where SM_SERIALNUM = v_SIMRANGE));
if v_count = 0 then
raise NO_SIM_WITH_RANGE;
end if;
insert into NMS.SIMULNK (SM_SERIALNUM,SM_ID, USER_LASTMOD, LAST_UPDATE, STATUS)
select SM_SERIALNUM,sm_id,v_user,v_date,'U' from storage_medium where SM_SERIALNUM in
(select SM_SERIALNUM from storage_medium
where SM_SERIALNUM = v_SIMRANGE and SM_STATUS='r' and SMC_ID in (3)
minus
(select SM_SERIALNUM from NMS. SIMDMSLNK where SM_SERIALNUM = v_SIMRANGE
union
select SM_SERIALNUM from NMS.SIMULNK where SM_SERIALNUM = v_SIMRANGE));
COMMIT;
DBMS_OUTPUT.PUT_LINE ( 'FREE 4G SIM CREATION PROCESS IS COMPLETED SUCCESSFULLY.');
EXCEPTION
WHEN NO_SIM_WITH_RANGE THEN
DBMS_OUTPUT.PUT_LINE ( 'SIM NOT AVAILABLE WITH RANGE ' ||v_SIMRANGE ||'TO INCLUDE IN FREE SIM POOL.');
WHEN OTHERS THEN
DBMS_OUTPUT.put_line ('SQLCODE : ' || SQLCODE);
DBMS_OUTPUT.put_line ('ERROR MESSAGE : ' || SQLERRM);
ROLLBACK;
END create_FREESIM;
procedure dummy_dlink is
v_count integer;
NO_ACTIVE exception;
begin
select count(distinct cd.CD_SM_NUM) into v_count from CONTR_DEVICES cd, contract_all coa , NMS.SIMDMSLNK SIMD
where coa.CH_STATUS='a' and COA.CO_ID=cd.co_id and SIMD.SM_serialnum=cd.cd_SM_NUM and SIMD.STATUS <> 'D';
If v_count =0 then
raise NO_ACTIVE;
else
update NMS.SIMDMSLNK set status='D' , Last_update=v_date where status <> 'D' and SM_SERIALNUM in
(select distinct CD_SM_NUM from CONTR_DEVICES cd, contract_all coa
where coa.CH_STATUS='a' and COA.CO_ID=cd.co_id);
COMMIT;
DBMS_OUTPUT.PUT_LINE ( v_count ||' DUMMY MSISDN D-LINKED');
end if;
EXCEPTION
when NO_ACTIVE then
NULL;
WHEN OTHERS THEN
DBMS_OUTPUT.put_line ('SQLCODE : ' || SQLCODE);
DBMS_OUTPUT.put_line ('ERROR MESSAGE : ' || SQLERRM);
end dummy_dlink;
procedure update_port_kind
is
v_port_id number;
v_smc_id number;
v_sm_id number;
v_vend_code varchar2 (10);
BEGIN
FOR cur
IN (SELECT port_id, sm_id
FROM port
WHERE TRUNC (PORT_STATUSMODDAT) = TRUNC (SYSDATE)
AND port_kind IS NULL and port_status = 'r')
LOOP
SELECT smc_id
INTO v_smc_id
FROM storage_medium
WHERE sm_id = cur.sm_id;
SELECT vendcode
INTO v_vend_code
FROM storage_medium
WHERE sm_id = cur.sm_id;
IF v_smc_id IN (1, 2) AND v_vend_code = 'DZ'
THEN
UPDATE port
SET port_kind = 1
WHERE port_id = cur.port_id;
ELSIF v_smc_id IN (1, 2) AND v_vend_code = 'MORPHO'
THEN
UPDATE port
SET port_kind = 2
WHERE port_id = cur.port_id;
ELSIF v_smc_id IN (1, 2) AND v_vend_code = 'GD'
THEN
UPDATE port
SET port_kind = 3
WHERE port_id = cur.port_id;
ELSIF v_smc_id = 3 AND v_vend_code = 'DZ'
THEN
UPDATE port
SET port_kind = 4
WHERE port_id = cur.port_id;
ELSIF v_smc_id = 3 AND v_vend_code = 'ORN'
THEN
UPDATE port
SET port_kind = 5
WHERE port_id = cur.port_id;
ELSIF v_smc_id = 3 AND v_vend_code = 'MORPHO'
THEN
UPDATE port
SET port_kind = 6
WHERE port_id = cur.port_id;
END IF;
END LOOP;
COMMIT;
END;
END ResourceBindDistribute;
/
On running the above I am getting the following error :
ERROR line 112, col 12, ending_line 112, ending_col 20, Found 'EXCEPTION', Expecting: ( SELECT -or- END -or- $IF : AT BEGIN CASE CLOSE COMMIT CONTINUE CURSOR DAY DECLARE DELETE ELSE ELSIF EXECUTE EXIT FETCH FOR FORALL GOTO identifier IF INSERT LOCK LOOP MERGE MOD MODEL MULTISET NULL OPEN RAISE REM RETURN ROLLBACK SAVEPOINT SET SQL THE UPDATE WHILE WITH YEAR -or- <<”
In the section
-- Cusrsor opened Dlinked MSISDN, to assign first DLINKED MSISDN
You start your loop inside the begin section but end the loop after the exception.
If you start a if or loop inside a anonymous block you need to ensure that it is fully contained within it.
I am trying to fill a database with random data, but the primary key needs to still be unique. I can fill the database with random data, but now I am trying to solve the primary key issue.
When running this code I get errors.
set SERVEROUTPUT on
create or replace
PROCEDURE fillDatabase(TableIn IN varchar2, Amount IN NUMBER) IS
columnData varchar2(50);
columnNR number(10);
str varchar2(500);
sqlStatement varchar2(500);
l_ran_time TIMESTAMP;
intlol NUMBER(38);
prmname varchar2(50);
prmtab varchar2(50);
prmkey number(10);
temp number(30);
tempstr varchar2(50);
lolnr number(10);
strq varchar2(50);
BEGIN
lolnr := 1;
select count(*) into columnNR
from user_tab_columns where table_name=TableIn;
FOR counter IN 1..Amount
LOOP
sqlStatement := 'insert into '|| TableIn ||' values (';
FOR counter2 IN 1..columnNR
LOOP
SELECT cols.table_name, cols.column_name into prmtab, prmname
FROM all_constraints cons, all_cons_columns cols
WHERE cols.table_name = TableIn
AND cons.constraint_type = 'P'
AND cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
ORDER BY cols.table_name, cols.position;
tempstr := 'select count(*) into temp from '|| prmtab;
dbms_output.put_line('test');
dbms_output.put_line(temp);
EXECUTE IMMEDIATE tempstr;
IF temp = 0
THEN
strq := 'SELECT max(' || prmname || ') into prmkey from '|| prmtab || ' order by '|| prmname;
dbms_output.put_line(strq);
EXECUTE IMMEDIATE strq;
END IF;
select dbms_random.value(0, 20) into intlol from dual;
select dbms_random.string('U', 20) into str from dual;
SELECT SYSDATE + dbms_random.value(0, SYSDATE - SYSDATE+1)
INTO l_ran_time
FROM dual;
Select DATA_TYPE INTO columnData
FROM user_tab_columns
WHERE table_name= TableIn
AND COLUMN_ID = counter2;
dbms_output.put_line(columnData);
CASE
WHEN columnData = 'VARCHAR2' THEN sqlStatement := sqlStatement ||''''|| str ||''', ';
WHEN columnData = 'NUMBER' THEN sqlStatement := sqlStatement || intlol ||', ';
WHEN columnData = 'TIMESTAMP(6)' THEN sqlStatement := sqlStatement ||''''|| l_ran_time ||''', ';
ELSE sqlStatement := sqlStatement || NULL || ', ';
END CASE;
END LOOP;
sqlStatement := SUBSTR(sqlStatement, 0, LENGTH(sqlStatement) -2);
sqlStatement := sqlStatement || ')';
dbms_output.put_line(sqlStatement);
EXECUTE IMMEDIATE sqlStatement;
END LOOP;
END fillDatabase;
Can you guys help me solve this?
use the pattern
str := 'select x from t where...';
execute immediate str into var;
instead of
str := 'select x into var from t where...';
execute immediate str;
I creatd a stored procedure. And a global temporary table inside it.
Now i am inserting data into this table by fatching cursor into local variables.
create or replace PROCEDURE "DEMO"
(
PARM_YEAR IN NUMBER,
PARM_PERIOD IN NUMBER,
PARM_PERIOD_TYPE IN CHAR,
PARM_PERIOD_ROLL IN CHAR,
PARM_TYPE IN VARCHAR2,
P_CURSOR IN OUT types.cursorType
)
IS
LOC_EXISTS NUMBER;
LOC_TYPE_PERIOD CHAR(2);
LOC_CURSOR_YEAR INTEGER;
LOC_CURSOR_PERIOD INTEGER;
LOC_CURSOR_TYPE_PERIOD CHAR(2 BYTE);
LOC_CURSOR_DEV_COPCL NUMBER(10,1);
LOC_CURSOR_DIST_GRP NUMBER(3,0);
CURSOR DIST_CHART IS
SELECT X.YEAR , X.PERIOD, X.TYPE_PERIOD, X.COST AS DEV_COPCL
FROM
SMY_PRVDR_TYPE_PRVDR X;
BEGIN
/* Set Period type */
IF (PARM_PERIOD_TYPE = 'Q' AND PARM_PERIOD_ROLL = 'A') THEN
LOC_TYPE_PERIOD := 'Q';
ELSE IF (PARM_PERIOD_TYPE = 'Q' AND PARM_PERIOD_ROLL = 'R') THEN
LOC_TYPE_PERIOD := 'RQ';
ELSE IF (PARM_PERIOD_TYPE = 'M' AND PARM_PERIOD_ROLL = 'A') THEN
LOC_TYPE_PERIOD := 'M';
ELSE
LOC_TYPE_PERIOD := 'RM';
END IF;
END IF;
END IF;
LOC_EXISTS := 0;
SELECT 1 INTO LOC_EXISTS
FROM ALL_TABLES
WHERE TABLE_NAME LIKE '%DEMO1%';
IF LOC_EXISTS = 1 THEN
EXECUTE IMMEDIATE 'TRUNCATE TABLE DEMO1';
END IF;
OPEN DIST_CHART;
LOOP
FETCH DIST_CHART INTO LOC_CURSOR_YEAR, LOC_CURSOR_PERIOD, LOC_CURSOR_TYPE_PERIOD,
LOC_CURSOR_DEV_COPCL;
EXIT WHEN DIST_CHART%NOTFOUND;
SELECT DIST_GRP(LOC_CURSOR_DEV_COPCL) INTO LOC_CURSOR_DIST_GRP FROM DUAL;
EXECUTE IMMEDIATE 'INSERT INTO DEMO1 VALUES ('|| LOC_CURSOR_YEAR ||', '''||
LOC_CURSOR_PERIOD || ''', '''|| LOC_CURSOR_TYPE_PERIOD ||''', '|| LOC_CURSOR_DEV_COPCL
||', '|| LOC_CURSOR_DIST_GRP || ')';
END LOOP;
CLOSE DIST_CHART;
EXCEPTION
WHEN NO_DATA_FOUND THEN
LOC_EXISTS:=0;
END;
Problem is that..
When i am executing this stored procedure into sql developer data is inserted successfuly into the global temporary table.
But
When i run same execute command into SQLPLUS, procedure run successfully, but data is not inserted into the global temporary table.
Code of GTT is
CREATE GLOBAL TEMPORARY TABLE "ICUSER"."DEMO1"
( "YEAR" NUMBER(4,0),
"PERIOD" NUMBER(2,0),
"TYPE_PERIOD" CHAR(2 BYTE),
"DEV_COPCL" NUMBER(*,1),
"DIST_GRP" NUMBER(3,0)
) ON COMMIT PRESERVE ROWS ;
procedure pod_tag_name (p_TAG_NAME in varchar2,
p_status out varchar2,
p_status_dtl out varchar2)
is
v_tag_name varchar2(100);
begin
v_tag_name := get_tag_name(p_TAG_NAME);
if v_tag_name = '' THEN
insert into pod_tagmaster (TAG_ID,TAG_NAME_NEW , CREATEDBY,
CREATEDDATE,UPDATED_BY, UPDATED_DATE,TAG_NAME_OLD)
values (POD_UNIQUE_VAL_SEQ.NEXTVAL,p_TAG_NAME , null ,
sysdate,null, sysdate, v_tag_name);
v_rec_cnt := sql%rowcount;
commit;
p_status_dtl := v_rec_cnt||' Record Inserted Successfully';
else
update pod_tagmaster
set TAG_NAME_NEW = p_TAG_NAME,
TAG_NAME_OLD = v_tag_name,
UPDATED_BY = null,
UPDATED_DATE = sysdate
where TAG_NAME_NEW = p_TAG_NAME;
v_rec_cnt := sql%rowcount;
commit;
p_status_dtl := v_rec_cnt||' Record Updated Successfully';
end if;
p_status := 'SUCCESS';
end;
function get_tag_name(p_TAG_NAME varchar2) return varchar2
is
v_tag_name varchar2(200);
begin
select TAG_NAME_NEW
into v_tag_name
from pod_tagmaster
where TAG_NAME_NEW = p_TAG_NAME ;
return v_tag_name;
exception
when others then
return '';
end;
end POD_PKG_TAG_MASTER;
Change
if v_tag_name = '' THEN
to
if v_tag_name IS NULL THEN
Also, change
return '';
to
RETURN NULL;
In Oracle a zero-length string is the same as NULL; thus, the equality comparison fails. You must use IS NULL in this case.
Share and enjoy.