Oracle PL/SQL Code will not compile, ORA-06550: line 96, column 3:PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: - oracle

I have written the following PL/SQL code block and it uses a long array of 4 digit strings in the array.
The program block will loop over the array using the array(i) position as a query variable to return the the r_LDR_IORG record which is then printed with i, array(i), and r_LRD_IORG.PS_ORG_ID.
1 DECLARE
2 type array_t is varray(692) of varchar2(6);
3 array array_t := array_t('0118','0118','01R1','01R1','01R2','01R2','01R4','01R4',
4 '01R5','01R5','01R7','01R7','03BB','03BB','03BB','03BB',
5 '03R3','03R4','03R8','0684','0684','0684','0685','0685',
6 '0685','06CN','06CN','06CN','06GG','06GG','0799','0799',
7 '079T','079T','079T','079T','07R1','07R1','07R1','07R1',
8 '07R3','07R3','07R3','07R3','07R5','07R5','07R5','07R5',
9 '07R6','07R6','07R6','07R6','07R7','07R7','07R7','07R7',
10 '0954','0954','0954','0956','0956','0956','0959','0959',
11 '0959','09ZZ','09ZZ','09ZZ','14R1','14R1','14R1','14R2',
12 '14R2','14R2','16C4','16C4','16C4','16R3','16R3','16R5',
13 '16R5','16R5','16R5','16R7','16R7','16R7','16U4','16U4',
14 '16U4','16U4','1850','1850','1851','1852','1899','20R1',
15 '20R1','20R2','20R2','2181','2181','2181','2181','2182',
16 '2182','2182','2182','2184','2184','2184','2184','2186',
17 '2186','2186','2186','23C1','23C1','23C1','23C1','23C1',
18 '23C1','23C2','23C2','23C2','23C2','23C2','23C2','23FF',
19 '23FF','23FF','23FF','23R1','23R1','23R1','23R1','23R1',
20 '23R1','23R1','23R1','23R2','23R2','23R2','23R2','23R2',
21 '23R2','23R2','23R2','23R3','23R3','23R3','23R3','23R3',
22 '23R3','23R3','23R3','23R5','23R5','23R5','23R5','23R5',
23 '23R5','23R5','23R5','23R6','23R6','23R6','23R6','23R6',
24 '23R6','23R6','23R6','23R7','23R7','23R7','23R7','23R8',
25 '23R8','23R8','23R8','23R8','23R8','23R8','23VP','23VP',
26 '23VP','23VP','23X1','23X1','23X1','23X1','23X2','23X2',
27 '23X2','23X2','23X3','23X3','23X3','23X3','23X4','23X4',
28 '23X4','23X4','23XX','23XX','23XX','23XX','24MA','24MA',
29 '24MA','24MB','24MB','24MB','24MG','24MG','24MQ','24MQ',
30 '24MQ','24MR','24MR','24MR','26R2','26R2','26R4','26R4',
31 '299T','299T','299T','29R1','29R1','29R1','29R2','29R2',
32 '29R2','29R3','29R3','29R4','29R4','29R4','3071','3071',
33 '3071','3071','3072','3072','3072','3072','3075','3075',
34 '3075','3075','3083','3083','3083','3083','3084','3084',
35 '3084','3084','30XB','30XB','30XB','30XB','32M2','32M2',
36 '32M2','32M2','32M2','32M3','32M3','32M3','32M3','32M3',
37 '32M4','32M4','32M4','32M4','32M4','32M5','32M5','32M5',
38 '32M5','32M5','32M6','32M6','32M6','32M6','32M6','32M7',
39 '32M7','32M7','32M7','32M7','32M8','32M8','32M8','32M8',
40 '32M8','32MB','32MB','32MB','32MB','32MB','32MD','32MD',
41 '32MD','32MD','32MD','32ME','32ME','32ME','32ME','32ME',
42 '32MF','32MF','32MF','32MF','32MF','32MG','32MG','32MG',
43 '32MG','32MG','32MH','32MH','32MH','32MH','32MH','32MJ',
44 '32MJ','32MJ','32MJ','32MJ','32MK','32MK','32MK','32MK',
45 '32MK','32ML','32ML','32ML','32ML','32ML','32MM','32MM',
46 '32MM','32MM','32MM','32MN','32MN','32MN','32MN','32MN',
47 '32MP','32MP','32MP','32MP','32MP','32MV','32MV','32MV',
48 '32MV','32MV','32MW','32MW','32MW','32MW','32MW','32R2',
49 '32R2','32R2','32R2','32R2','32R3','32R3','32R3','32R3',
50 '32R3','32R4','32R4','32R4','32R4','32R4','32R5','32R5',
51 '32R5','32R5','32R5','32R6','32R6','32R6','32R6','32R6',
52 '32R7','32R7','32R7','32R7','32R7','32R8','32R8','32R8',
53 '32R8','32R8','32RA','32RA','32RA','32RA','32RA','32RB',
54 '32RB','32RB','32RB','32RB','32RC','32RC','32RC','32RC',
55 '32RC','32RD','32RD','32RD','32RD','32RD','32RE','32RE',
56 '32RE','32RE','32RE','32RF','32RF','32RF','32RF','32RF',
57 '32RG','32RG','32RG','32RG','32RG','32RH','32RH','32RH',
58 '32RH','32RH','32RJ','32RJ','32RJ','32RJ','32RJ','32RK',
59 '32RK','32RK','32RK','32RK','32RL','32RL','32RL','32RL',
60 '32RL','32RM','32RM','32RM','32RM','32RM','32RN','32RN',
61 '32RN','32RN','32RN','32RP','32RP','32RP','32RP','32RP',
62 '32RQ','32RQ','32RQ','32RQ','32RQ','32RW','32RW','32RW',
63 '32RW','32RW','341R','341R','341R','35R1','35R1','35R1',
64 '35R1','35R2','35R2','35R2','35R3','35R3','35R3','35R3',
65 '39Z1','4175','4175','4175','4175','4176','4176','4176',
66 '4176','4177','4177','4177','4177','4179','4179','4179',
67 '4179','41U1','41U1','41U1','41U1','41U2','41U2','41U2',
68 '41U2','41U3','41U3','41U3','41U3','41U4','41U4','41U4',
69 '41U4','41Z1','41Z1','41Z1','41Z1','4290','4290','4290',
70 '4290','4293','4293','4293','4293','42B7','42B7','42B7',
71 '42N7','42N7','42N7','42N7','4350','4350','4350','4351',
72 '4351','4351','4390','4390','4390','4390','4391','4391',
73 '4391','4391','43C9','43C9','43C9','43C9','44R1','44R1',
74 '44R1','44R1','46MM','46MM','46MM','46R1','46R1','46R1',
75 '46R2','46R2','46R2','46R2','489B','489B','48R1','48R1',
76 '48R3','48R3','5185','5185','5279','5279','5279','5297',
77 '5297','5297','521U','521U','521U','52R1','52R1','52R1',
78 '53R1','53R1','53R1','53R1','53R2','53R2','53R2','53R2',
79 '53R4','53R4','53R4','53R4','53R6','53R6','53R6','53R6',
80 '53R7','53R7','53R7','53R7','5480','5480','5481','5481',
81 '5482','5482','5501','5501','5501','5501','5501','5501',
82 '5501','5501','5501','5502','5502','5502','5502','5502',
83 '5502','5502','5502','5502','5502','5503','5503','5503',
84 '5503','5503','5503','5503','5503','5503','5503','55X6',
85 '55X6','55X6','55X6','560X','560X','560X','560X','561X',
86 '561X','561X','561X','56PP','56PP','56PP','56PP','62R2',
87 '62R2','65BT','65BT','65Z1','65Z1','65Z1','2R88','2R88',
88 '2S50','2S50','2S99','2S99','3E99','3E99','3E99','3E99',
89 '3EL1','3EL1','3EL1','3EL1'); -- Initialise it
90 BEGIN
91 for i in 1..array.count loop
92 for r_LRD_IORG IN (select * from LRDLicnse.LRD_IORG where IORG_TYP_DSC = 'BRANCH' and Record_status = 'A' and LGCY_IORG_ID = array(i)) loop
93 dbms_output.put_line(i, array(i), r_LRD_IORG.PS_ORG_ID);
94 end loop;
95 end loop;
96 END
97 /
After trying to compile the code block and run it I get the following error messages.
Error starting at line : 1 in command -
DECLARE
type array_t is varray(692) of varchar2(6);
array array_t := array_t('0118','0118','01R1','01R1','01R2','01R2','01R4','01R4',
'01R5','01R5','01R7','01R7','03BB','03BB','03BB','03BB',
'03R3','03R4','03R8','0684','0684','0684','0685','0685',
'0685','06CN','06CN','06CN','06GG','06GG','0799','0799',
'079T','079T','079T','079T','07R1','07R1','07R1','07R1',
'07R3','07R3','07R3','07R3','07R5','07R5','07R5','07R5',
'07R6','07R6','07R6','07R6','07R7','07R7','07R7','07R7',
'0954','0954','0954','0956','0956','0956','0959','0959',
'0959','09ZZ','09ZZ','09ZZ','14R1','14R1','14R1','14R2',
'14R2','14R2','16C4','16C4','16C4','16R3','16R3','16R5',
'16R5','16R5','16R5','16R7','16R7','16R7','16U4','16U4',
'16U4','16U4','1850','1850','1851','1852','1899','20R1',
'20R1','20R2','20R2','2181','2181','2181','2181','2182',
'2182','2182','2182','2184','2184','2184','2184','2186',
'2186','2186','2186','23C1','23C1','23C1','23C1','23C1',
'23C1','23C2','23C2','23C2','23C2','23C2','23C2','23FF',
'23FF','23FF','23FF','23R1','23R1','23R1','23R1','23R1',
'23R1','23R1','23R1','23R2','23R2','23R2','23R2','23R2',
'23R2','23R2','23R2','23R3','23R3','23R3','23R3','23R3',
'23R3','23R3','23R3','23R5','23R5','23R5','23R5','23R5',
'23R5','23R5','23R5','23R6','23R6','23R6','23R6','23R6',
'23R6','23R6','23R6','23R7','23R7','23R7','23R7','23R8',
'23R8','23R8','23R8','23R8','23R8','23R8','23VP','23VP',
'23VP','23VP','23X1','23X1','23X1','23X1','23X2','23X2',
'23X2','23X2','23X3','23X3','23X3','23X3','23X4','23X4',
'23X4','23X4','23XX','23XX','23XX','23XX','24MA','24MA',
'24MA','24MB','24MB','24MB','24MG','24MG','24MQ','24MQ',
'24MQ','24MR','24MR','24MR','26R2','26R2','26R4','26R4',
'299T','299T','299T','29R1','29R1','29R1','29R2','29R2',
'29R2','29R3','29R3','29R4','29R4','29R4','3071','3071',
'3071','3071','3072','3072','3072','3072','3075','3075',
'3075','3075','3083','3083','3083','3083','3084','3084',
'3084','3084','30XB','30XB','30XB','30XB','32M2','32M2',
'32M2','32M2','32M2','32M3','32M3','32M3','32M3','32M3',
'32M4','32M4','32M4','32M4','32M4','32M5','32M5','32M5',
'32M5','32M5','32M6','32M6','32M6','32M6','32M6','32M7',
'32M7','32M7','32M7','32M7','32M8','32M8','32M8','32M8',
'32M8','32MB','32MB','32MB','32MB','32MB','32MD','32MD',
'32MD','32MD','32MD','32ME','32ME','32ME','32ME','32ME',
'32MF','32MF','32MF','32MF','32MF','32MG','32MG','32MG',
'32MG','32MG','32MH','32MH','32MH','32MH','32MH','32MJ',
'32MJ','32MJ','32MJ','32MJ','32MK','32MK','32MK','32MK',
'32MK','32ML','32ML','32ML','32ML','32ML','32MM','32MM',
'32MM','32MM','32MM','32MN','32MN','32MN','32MN','32MN',
'32MP','32MP','32MP','32MP','32MP','32MV','32MV','32MV',
'32MV','32MV','32MW','32MW','32MW','32MW','32MW','32R2',
'32R2','32R2','32R2','32R2','32R3','32R3','32R3','32R3',
'32R3','32R4','32R4','32R4','32R4','32R4','32R5','32R5',
'32R5','32R5','32R5','32R6','32R6','32R6','32R6','32R6',
'32R7','32R7','32R7','32R7','32R7','32R8','32R8','32R8',
'32R8','32R8','32RA','32RA','32RA','32RA','32RA','32RB',
'32RB','32RB','32RB','32RB','32RC','32RC','32RC','32RC',
'32RC','32RD','32RD','32RD','32RD','32RD','32RE','32RE',
'32RE','32RE','32RE','32RF','32RF','32RF','32RF','32RF',
'32RG','32RG','32RG','32RG','32RG','32RH','32RH','32RH',
'32RH','32RH','32RJ','32RJ','32RJ','32RJ','32RJ','32RK',
'32RK','32RK','32RK','32RK','32RL','32RL','32RL','32RL',
'32RL','32RM','32RM','32RM','32RM','32RM','32RN','32RN',
'32RN','32RN','32RN','32RP','32RP','32RP','32RP','32RP',
'32RQ','32RQ','32RQ','32RQ','32RQ','32RW','32RW','32RW',
'32RW','32RW','341R','341R','341R','35R1','35R1','35R1',
'35R1','35R2','35R2','35R2','35R3','35R3','35R3','35R3',
'39Z1','4175','4175','4175','4175','4176','4176','4176',
'4176','4177','4177','4177','4177','4179','4179','4179',
'4179','41U1','41U1','41U1','41U1','41U2','41U2','41U2',
'41U2','41U3','41U3','41U3','41U3','41U4','41U4','41U4',
'41U4','41Z1','41Z1','41Z1','41Z1','4290','4290','4290',
'4290','4293','4293','4293','4293','42B7','42B7','42B7',
'42N7','42N7','42N7','42N7','4350','4350','4350','4351',
'4351','4351','4390','4390','4390','4390','4391','4391',
'4391','4391','43C9','43C9','43C9','43C9','44R1','44R1',
'44R1','44R1','46MM','46MM','46MM','46R1','46R1','46R1',
'46R2','46R2','46R2','46R2','489B','489B','48R1','48R1',
'48R3','48R3','5185','5185','5279','5279','5279','5297',
'5297','5297','521U','521U','521U','52R1','52R1','52R1',
'53R1','53R1','53R1','53R1','53R2','53R2','53R2','53R2',
'53R4','53R4','53R4','53R4','53R6','53R6','53R6','53R6',
'53R7','53R7','53R7','53R7','5480','5480','5481','5481',
'5482','5482','5501','5501','5501','5501','5501','5501',
'5501','5501','5501','5502','5502','5502','5502','5502',
'5502','5502','5502','5502','5502','5503','5503','5503',
'5503','5503','5503','5503','5503','5503','5503','55X6',
'55X6','55X6','55X6','560X','560X','560X','560X','561X',
'561X','561X','561X','56PP','56PP','56PP','56PP','62R2',
'62R2','65BT','65BT','65Z1','65Z1','65Z1','2R88','2R88',
'2S50','2S50','2S99','2S99','3E99','3E99','3E99','3E99',
'3EL1','3EL1','3EL1','3EL1'); -- Initialise it
BEGIN
for i in 1..array.count loop
for r_LRD_IORG IN (select * from LRDLicnse.LRD_IORG where IORG_TYP_DSC = 'BRANCH' and Record_status = 'A' and LGCY_IORG_ID = array(i)) loop
dbms_output.put_line(i, array(i), r_LRD_IORG.PS_ORG_ID);
end loop;
end loop;
END
Error report -
ORA-06550: line 97, column 0:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
; <an identifier> <a double-quoted delimited-identifier>
The symbol ";" was substituted for "end-of-file" to continue.
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
If you could help getting this pl/sql block up and running I would be much appreciative about it.
Thank you,
Steve Brooks

Obvious error, which causes this exception to be thrown: The END command, before the slash on a line by itself, must be ended in semicolon. Like this:
........
end loop;
END; -- notice the semicolon
/
After you fix this, you will run into another error. put_line takes only one argument, not three. If you want a string including those bits of data, and commas and spaces, you will have to build it using single-quotes for the parts that are hard-coded (comma, space) and the concatenation operator. The more common way would be something like this:
........
dbms_output.put_line('i = ' || i || ', array(i) = ' || array(i) ||
', PS_ORG_ID = ' || r.LRD_IORG.PS_ORG_ID);

Related

Replicat Abended with ORA-02290: check constraint (TABLE_NAME.CHK_JSON) violated

We see the below in my Discard file -
NOTE: I can see the record in my source db.
CI Error ORA-02002: error while writing to audit trail
ORA-22275: invalid LOB locator specified
ORA-02290: check constraint (SCHEMA_NAME.CHK_JSON) violated (status = 2002), SQL <INSERT /*+ RESTRICT_ALL_REF_CONS */ INTO "SCHEMA_NAME"."TABLE_NAME" ("INSTRUMENTID","INDEXDETAIL","CREATIONTIME","LASTUPDATEDTIME") VALUES (:a0,EMPTY_CLOB(),:a2,:a3) RETURNING "INDEXDETAIL" INTO :dl0>
Aborting transaction on /local/dbms/oracle/goldengate_dbfs/oggma/goldengate_trails/oggma_deployment/var/lib/data/tc beginning at seqno 22 rba 206,136,818
error at seqno 22 rba 206136818
Problem replicating CATALOG_NAME.SCHEMA_NAME.TABLE_NAME to SCHEMA_NAME.TABLE_NAME.
Mapping problem with insert record (target format) SCN:12.1.6904...
*
INSTRUMENTID = 11111111
000000: 42 32 37 41 42 37 42 31 |11111111 |
INDEXDETAIL = (LOB)
CREATIONTIME = 2022-05-30 06:20:15
000000: 32 30 32 32 2d 30 35 2d 33 30 20 30 36 3a 32 30 |2022-05-30 06:20|
000010: 3a 31 35 |:15 |
LASTUPDATEDTIME = NULL
*
Process Abending : 2022-06-01 07:32:44.534819
May I know what type of Replicat you are using? Whether Audit is enabled? Also, could you please share the full GG version.
You can also refer to this KM note which might help you.
ORA-2002 And ORA-22275 Encountered When SELECT Audit Is Turned On For A Table (Doc ID 2764792.1)

Could not remove unicode character

I have a text string in Oracle table ("NGUYỄN NGỌC HOÀNG"). I have tried to replace the Unicode string (my expected result is "NGUYEN NGOC HOANG") but it didn't work.
Then I tried to convert it to HEX as below: select rawtohex(UnicodeColumn) from TestTable;
Here is the result: 4E 47 55 59 C3 8A CC 83 4E 20 4E 47 4F CC A3 43 20 48 4F 41 CC 80 4E 47
Following the Unicode table: The corresponding characters are: NGUYỄN NGỌC HOÀNG
Could anyone help me this case (Oracle script), I don't have experience about the encoding.
Update 1:
I have tried the solution from Barbaros Özhan but it didn't work
SQL> with tab as ( select '&i_str1' str1 from dual ) 2 select str1,
utl_raw.cast_to_varchar2((nlssort(str1,'nls_sort=binary_ai'))) str2
from tab SQL> / Enter value for i_str1: NGUYỄN NGỌC HOÀNG
SQL> with tab as ( select '&i_str1' str1 from dual )
2 select str1, utl_raw.cast_to_varchar2((nlssort(str1,'nls_sort=binary_ai'))) str2 from tab
SQL> /
Enter value for i_str1: NGUYỄN NGỌC HOÀNG
and you get the desired result.
If you are using Java for connecting to Oracle DBMS, try the Java code below to convert to unaccent character, after that update the row in DBMS.
public static String unAccent(String s) {
String temp = Normalizer.normalize(s, Normalizer.Form.NFD);
Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
return pattern.matcher(temp).replaceAll("").replaceAll("Đ", "D").replace("đ", "");
}
You can try this function to convert to non-accent character:
CREATE OR REPLACE FUNCTION FN_CONVERT_TO_VN
(
STRINPUT IN NVARCHAR2
)
RETURN NVARCHAR2
IS
STRCONVERT NVARCHAR2(32527);
BEGIN
STRCONVERT := TRANSLATE(
STRINPUT, 'áàảãạăắằẳẵặâấầẩẫậđéèẻẽẹêếềểễệíìỉĩịóòỏõọôốồổỗộơớờởỡợúùủũụưứừửữựýỳỷỹỵÁÀẢÃẠĂẮẰẲẴẶÂẤẦẨẪẬĐÉÈẺẼẸÊẾỀỂỄỆÍÌỈĨỊÓÒỎÕỌÔỐỒỔỖỘƠỚỜỞỠỢÚÙỦŨỤƯỨỪỬỮỰÝỲỶỸỴ', 'aaaaaaaaaaaaaaaaadeeeeeeeeeeeiiiiiooooooooooooooooouuuuuuuuuuuyyyyyAAAAAAAAAAAAAAAAADEEEEEEEEEEEIIIIIOOOOOOOOOOOOOOOOOUUUUUUUUUUUYYYYY'
);
RETURN STRCONVERT;
END;

After Sort in Python how to create new Index field

After I sort my data, I am trying to create a new index field.
Here is my code:
mydata_1=[[38,125,56],[98,23,150],[11,46,15],[23,87,81]]
cols= ['Col_A','Col_B','Col_C']
mydata_2= pd.DataFrame(mydata_1, columns=cols)
mydata_3= mydata_2.sort('Col_A')
So with my code above the output looks like this:
Col_A Col_B Col_C
2 11 46 15
3 23 87 81
0 38 125 56
1 98 23 150
I need to create a new column called "Col_D" as seen below:
Col_A Col_B Col_C Col_D
2 11 46 15 1
3 23 87 81 2
0 38 125 56 3
1 98 23 150 4
Also, I am going to be using this on many data sets. Is there a way to do this without specifying a range?
Here you go
import pandas as pd
mydata_1=[[38,125,56],[98,23,150],[11,46,15],[23,87,81]]
cols= ['Col_A','Col_B','Col_C']
mydata_2= pd.DataFrame(mydata_1, columns=cols)
mydata_3= mydata_2.sort('Col_A')
mydata_3["Col_D"] = range(len(mydata_3.index))
print(mydata_3)

How to update a column of a table using a function in ORACLE

Being a novice in ORACLE and programming in general I have difficulty in updating series of cells in a column of a table in oracle.
The table:
ad soyad not1 not1 not3 BN HN
Ayşe Yılmaz 28 65 82
Melih Türkmen 45 27 56
Cemile Kara 54 65 99
Ragıp Pekkan 62 48 85
Jale Kale 48 75 52
Vehbi Kemal 18 65 63
Mehmet Hamarat 54 62 70
Murat Çokbilir 25 28 32
Harun Reşit 85 84 92
Cemal Yamak 95 23 90
My function :
create or replace
function basariNotu (a NUMBER, b NUMBER, c NUMBER) RETURN NUMBER IS
rbn NUMBER;
BEGIN
rbn:=(a*0.2)+(b*0.2)+(c*0.6);
RETURN rbn;
END basariNotu;
MY code that is supposed to update column 'bn' with rbn returned from the function:
DECLARE
d NUMBER;
e NUMBER;
f NUMBER;
rbn NUMBER;
j NUMBER;
BEGIN
j:=1;
LOOP
SELECT not1 INTO d FROM student;
SELECT not2 INTO e FROM student;
SELECT not3 INTO f FROM student;
basariNotu(d, e, f);
UPDATE student SET bn=rbn WHERE bn= NULL;
j:= j+1;
IF j>10 THEN
EXIT;
END IF;
END LOOP;
END;
You don't have any appropriate WHERE clauses in your queries, and your LOOP has no relationship to the rows being processed. The j counter merely makes the loop do the same action 9 times. Not only that, but your predicate bn= NULL will always evaluate to FALSE so it will never update any rows.
I think you probably want something like this:
FOR r IN (
SELECT student_id, not1, not2, not3
FROM student
WHERE bn IS NULL
) LOOP
rbn := basariNotu(a => r.not1, b => r.not2, c = r.not3);
UPDATE student SET bn=rbn WHERE student_id = r.student_id;
END LOOP;
The above code assumes your table has a unique identifier of some sort such as student_id. If it doesn't, you have more problems to deal with.
However, this is the slow-by-slow (row-by-row) style of programming, the habit of which you need to shake. The above could be done much more simply and efficiently with a single UPDATE statement, e.g.:
UPDATE student
SET bn = basariNotu(a => not1, b => not2, c = not3)
WHERE bn IS NULL;
For even better performance, you would avoid the function call completely, e.g.:
UPDATE student
SET bn = (not1*0.2)+(not2*0.2)+(not3*0.6)
WHERE bn IS NULL;

oracle raw type iteration

I am working with a table that contains a raw(200) field. From my client application I manage to get the value and store it in a byte[] and so that I can loop over it and get all the samples.
My raw data would be like ...
2C2B2E2B2D2C2933283030332B2F2D302F2B272F312E2B2F2F28242A2F322E
... and from there I would like to go from hex to decimal values and get an array such as 44,43,46,43
However, I would like to do a similar thing in a procedure but I don't know how to iterate over a raw field or how to cast it to byte array.
I tried with UTL_RAW.CAST_TO_BINARY_INTEGER but that would only give me the first sample
Given this data ...
SQL> select col1
2 from t23
3 /
COL1
--------------------------------------------------------------------------------
32433242324532423244324332393333323833303330333332423246324433303246324232373246
33313245324232463246323832343241324633323245
SQL>
... a SELECT like this will produce the requisite output...
SQL> select regexp_substr(utl_raw.cast_to_varchar2(col1), '([A-Z0-9]{2})', 1, level)
2 from t23
3 connect by level <= ceil(utl_raw.length(col1)/2)
4 /
REGEXP_SUBSTR(UTL_RAW.CAST_TO_VARCHAR2(COL1),'([A-Z0-9]{2})',1,LEVEL)
--------------------------------------------------------------------------------
2C
2B
2E
2B
...
2B
2F
2F
28
24
2A
2F
32
2E
31 rows selected.
SQL>
Use TO_NUMBER with the 'XX' mask to convert the hex into decimal ...
SQL> select to_number(
2 regexp_substr(utl_raw.cast_to_varchar2(col1), '([A-Z0-9]{2})', 1, level)
3 , 'XX')
4 from t23
5 connect by level <= ceil(utl_raw.length(col1)/2)
6 /
TO_NUMBER(REGEXP_SUBSTR(UTL_RAW.CAST_TO_VARCHAR2(COL1),'([A-Z0-9]{2})',1,LEVEL),
--------------------------------------------------------------------------------
44
43
46
43
45
44
41
...
Finally, to populate an array, and populate it in PL/SQL with the bulk collection syntax:
create type int_nt as table of integer
/
declare
ints int_nt;
begin
select to_number(
regexp_substr(utl_raw.cast_to_varchar2(col1), '([A-Z0-9]{2})', 1, level)
, 'XX')
bulk collect into ints
from t23
connect by level <= ceil(utl_raw.length(col1)/2);
end;
/
Probably there's a more efficient way to solve this but I managed to get my result by using utl_raw.length and utl_raw.substr over my raw data and iterating with an standard plsql loop and converting each substring to decimal with utl_raw.cast_to_binary_integer

Resources