Oracle column in table mysteriously changing value - oracle

I have a server_password column in my table server_services.
I'm using a package to encrypt/decrypt the password.
This sometimes fails with an internal Oracle error message and is what I am investigating. I believe the error message is oracle's way of telling me the password or encrypted value is wrong.
The password is stored in a type VARCHAR2(100 BYTE) column; the encode/decode functions work with utl_raw.cast_to_raw and utl_raw.cast_to_varchar2 and take and give a varchar2.
When looking at the password, it is looking strange, with many boxes indicating non-printable characters.
Now my problem is that the decryption works, but then starts failing.
To investigate this, I calculated a hash of the encrypted password:
select rawtohex(
DBMS_CRYPTO.Hash (
UTL_I18N.STRING_TO_RAW (SERVER_PASSWORD, 'AL32UTF8'),
2)
)
FROM SERVER_SERVICES;
What is strange is that suddenly the hash changes, and there is no code that is supposed to do that. And I'm also not touching the table data manually.
-- doesn't work:
-- D40D0635FAC75F47DE5164F0EF50A2DB
-- regenerated password
-- works
-- 41136DFB85EFEDAC08150A8959923422
-- waited some time
-- doesn't work again
-- D40D0635FAC75F47DE5164F0EF50A2DB
Do you have any idea what is causing this and how to prevent it?
The oracle error message and code:
ORA-06512: at "SYS.DBMS_CRYPTO_FFI", line 67
ORA-06512: at "SYS.DBMS_CRYPTO", line 44
ORA-06512: at "XXX_CONFIGURATION.ENCRYPT_DECRYPT_PASSWORD", line 32
ORA-06512: at "XXX_CONFIGURATION.ENCRYPT_DECRYPT_PASSWORD", line 65
ORA-06512: at line 1
I tried to look at the package, but it is "wrapped":
"PACKAGE BODY dbms_crypto_ffi wrapped
a000000
1
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
b
228a 312
2L+V7+Eg9BLQ+XmmDXawGjt9NCkwg811r9yGfC9ArU6O79zKUmj9ScZSugr0ScKkyrBaaS8K
RM2eU4oiAJ+r4d4lezkNE6wQ5Yqan2461E6wiGvHZQEvOHHdBvzuJjQ/5PjBOr9CEvi243t6
Nusbvg7sjKYbTVZlssZ/s90CpB2h0dzVXMQpZhJcAfTFvlB+l117gW6UHTxdwaXcMgkKFOu+
jmGw/I+etGPJCcg2NqGIdnOS/tLPTjDD8Mmi7CKC2I91UUJNDFVV10G4Y6hD7Sg8Wr7jrWyr
bE19xjlMFdvDcopkNK4XDwXyXv0yShDNbaQwiWB79aHGzH6gOUhVWqS6eHvGPCrT/4GrTPbt
bFS90BT3RMN3Cybzt62xAVVModFTWF5e9WFZnFlmAVLRMZjPzFy8cOI1ypXYqRavEaSGDhQQ
As+M/5avOclUIBg7+k0ST18JEIgBSpxwlEG5dPir5MlGdwiukLMO3PDLfUdLorLyDnU5Zhjx
5d2qj6rP5MQ7zEeDPIV5bUC6ZsSkmw3mbXACrJSDJpQj2dBk3gJva4421V2iVZoGNvkdtRLJ
AsmiXJk/hZ5CMXWYICcL+Q81D/1dLpzrF4zPtSkWu5tRBDi4NNnc47Qz7zzLk/KnREgMmtCH
7hLnDweY0QjvUyF750ixx+IvKebAnUiJZwkHGqS1mP2lkvIwDTrxott1qzSiQTMvBlwez/KQ
VUhaBP1VHM7LGFfBfna8hnu0SiD311nbL4AmxR4+t70k2jD7+XS+Vg==
"

Related

Oracle Text truncate words to 64 CHARS but token limit is 64 BYTES

I'm using Oracle 19c.
I have a table with a VARCHAR2(4000) column for which I'm creating a full-text index using Oracle Text.
The SQL creating the index is as follow:
begin
ctx_ddl.create_index_set('ix_iset');
ctx_ddl.create_preference('ix_pref', 'BASIC_LEXER');
ctx_ddl.set_attribute('ix_pref', 'skipjoins', '-');
ctx_ddl.set_attribute ( 'ix_pref', 'index_stems', 'portuguese');
ctx_ddl.set_attribute ( 'ix_pref', 'index_text', 'YES');
ctx_ddl.set_attribute ( 'ix_pref', 'base_letter', 'YES');
end;
CREATE INDEX ix_tx_column ON MYTABLE(tx_column)
INDEXTYPE IS CTXSYS.CTXCAT
PARAMETERS ('index set ix_iset lexer ix_pref');
Everything works very well, but when there is a word with more than 64 chars, an error is raised:
ORA-29855: error occurred in the execution of ODCIINDEXCREATE routine
ORA-20000: Oracle Text Error:
DRG-50857: oracle error in dreii1fsh
ORA-12899: value too large for column "CAD"."DR$IX_TX_COLUMN$I"."DR$TOKEN" (actual: 65, maximum: 64)
ORA-06512: em "CTXSYS.DRUE", line 186
ORA-06512: em "CTXSYS.CATINDEXMETHODS", line 102
29855. 00000 - "error occurred in the execution of ODCIINDEXCREATE routine"
*Cause: Failed to successfully execute the ODCIIndexCreate routine.
*Action: Check to see if the routine has been coded correctly.
I've looked into the documentation and the only reference to this limitation is this item:
2.14 Token Limitations for Oracle Text Indexes
After some research I realized that probably the Oracle-Text internal functions are truncating the words to 64 CHARS, but the token limit is 64 BYTES.
The text word causing this error have Diacritical Characters within its first 64 chars like ç ã õ é and so on... Each char are 2 bytes in size.
I tried to set NLS_LENGTH_SEMANTICS=BYTE with no success.
As long as I researched, there is no way how to change the size of the index token.
Edit:
The result of SELECT * FROM v$nls_parameters is:

Why does my SQL code tell me that paddling is not a good identifier?

I AM ON CLOUD VERSION OF ORACLE
so what I need to do is insert data from an already established table into a new table. I am a student and I pretty much copied what they told me to do, just changing the table and what i need to grab
here is my code:
INSERT INTO PADDLING
SELECT TRIP_ID, TRIP_NAME, STATE, DISTANCE,
MAX_GRP_SIZE,
SEASON
FROM TRIP
WHERE TYPE = Paddling;
and here is the error
ORA-00904: "PADDLING": invalid identifier
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_200200",
line 670
ORA-06512: at "SYS.DBMS_SYS_SQL", line 1658
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_200200",
line 656
ORA-06512: at
"APEX_200200.WWV_FLOW_DYNAMIC_EXEC", line 1768
4. WHERE TYPE = Paddling;
I tried PADDLING in all uppercase, however it is lowercase in the table i am grabbing from.
You want to quote the string literal :
INSERT INTO PADDLING
SELECT TRIP_ID, TRIP_NAME, STATE, DISTANCE,
MAX_GRP_SIZE,
SEASON
FROM TRIP
WHERE TYPE = 'Paddling';
If you do not have the quotes then Oracle assumes it is an identifier, typically for a column name. To show that it is a string literal and not an identifier you need to use single quotation marks.

How to update value with special character in oracle 11g

I want to update the password having special characters ''?# #C $4 ABC (starting two characters are two single quotes) in Xyz table.
I am trying the following query
UPDATE Xyz set password="''?# #C $4" where user_no like '%123%';
But I am getting error as
ORA-00911: invalid charachter
The q-quoting mechanism helps in such situations, when you have to work with multiple single quotes within the string.
SQL> desc xyz
Name Null? Type
----------------------------------------- -------- ----------------------------
USER_NO NUMBER
PASSWORD VARCHAR2(20)
SQL> select * From xyz;
USER_NO PASSWORD
---------- --------------------
123 a
SQL> update xyz set password = q'[''?# #C $3]' where user_no = 123;
1 row updated.
SQL> select * From xyz;
USER_NO PASSWORD
---------- --------------------
123 ''?# #C $3
SQL>
Are you pasting the query from a different editor or IDE ? or Maybe copying from windows applications to Linux? In that case, there may be non-printable characters present.
If so, you could retype (not copy-paste) the SQL statement and try.
Also, double quotes aren't commonly used in SQL. You may want to replace them with single quotes.

Oracle SQL: Stored procedure - object invalid

I was just about to create a store procedure and it worked so far.
(For learning purposes I want to hand a credit card number over to a stored procedure which should return the associated customer identification number.)
But when I wanted to test this procedure using
BEGIN CC_TO_CID(:p1, :p2);
END;
(the input data was submitted via a dialogue of my SQL IDE)
it just returned:
SQL Error [6550][65000]: ORA-06550: Row 1, Column 7: PLS-00905
Object xyz.CC_TO_CID is invalid ORA-06550: Row 1, Column 7:
PL/SQL: Statement ignored
This basically means that my stored procedure isn't well formatted but I really don't have any clue.
My stored procedure:
CREATE OR REPLACE PROCEDURE CC_TO_CID(in_cc_nr IN NUMBER(16,0), out_cid OUT NUMBER) IS
BEGIN
SELECT PM.CUSTOMER_ID INTO cid FROM "2_PAYMENT_M" PM,
"2_CREDITCARD" CC
WHERE CC.CC_NR=in_cc_nr AND CC.PAYMENT_M_NR=PM.PAYMENT_M_NR;
END;
My table structure with some test data:
Table: "2_CREDITCARD"
CC_NR PAYMENT_M_NR NAME CVV EXPIRES
------------------ -------------- -------------- ----- ---------------------
5307458270409047 1 Haley Harrah 52 2019-11-01 00:00:00
Table: "2_PAYMENT_M"
PAYMENT_M_NR CUSTOMER_ID CREATED TRANSACTION_LIMIT
-------------- ------------- --------------------- -------------------
1 100 2018-01-21 00:00:00 1.000
Thanks in advance!
I appreciate any useful hints.
You will have seen an error when you compiled the procedure, but it would probably have been quite generic. Your client may support show errors, or you can query the user_errors view to see the details.
You can’t give a size or precision restriction for the data type of a formal parameter to a function or procedure, so NUMBER(10,0) should just be NUMBER; and you have got the name of the argument wrong in your into clause.
CREATE OR REPLACE PROCEDURE CC_TO_CID(in_cc_nr IN NUMBER, out_cid OUT NUMBER) IS
BEGIN
SELECT PM.CUSTOMER_ID
INTO out_cid
FROM "2_PAYMENT_M" PM
JOIN "2_CREDITCARD" CC
ON CC.PAYMENT_M_NR=PM.PAYMENT_M_NR
WHERE CC.CC_NR=in_cc_nr;
END;
I’ve switched to ANSI join syntax because... well, just because. Untested as I don’t have your tables; if it still gets errors then check user_errors again.

What can I do to ensure fields longer than column width go to the BAD File?

When creating Oracle external tables, how should I phrase the reject rows clause to ensure that any field which exceeds its column width rejects and goes in the BADFILE?
This is my current design and I don't want records greater than 20 characters. I do want them to go BADFILE instead. Yet, they still appear when I select * from foobar
DROP TABLE FOOBAR CASCADE CONSTRAINTS;
CREATE TABLE FOOBAR
(
FOO_MAX20 VARCHAR2(20 CHAR)
)
ORGANIZATION EXTERNAL
( TYPE ORACLE_LOADER
DEFAULT DIRECTORY FOOBAR
ACCESS PARAMETERS
( RECORDS DELIMITED BY NEWLINE
BADFILE 'foobar_bad_rec.txt'
DISCARDFILE 'foobar_discard_rec.txt'
LOGFILE 'foobar_logfile.txt'
FIELDS
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
(
FOO_MAX20 POSITION(1:20)
)
)
LOCATION (foobar:'foobar.txt') )
REJECT LIMIT UNLIMITED
PARALLEL ( DEGREE DEFAULT INSTANCES DEFAULT )
NOMONITORING;
Here is my external file foobar.txt
1234567
1234567890123456
126464843750476074218751012345678901234567890
7135009765625
048669433593
7
527
You can't do this with the reject rows clause, as it only accepts one form.
You have a variable-length (delimited) record, but a fixed-length field. Everything after the last position you specify, which is 20 in this case, is seen as filler that you want to ignore. That isn't an error condition; you might have rubbish at the end that isn't relevant to your table. There is nothing that says chars 21-45 in your third record shouldn't be there - just that you aren't interested in them.
It would be nice if you could discard them with the load when clause, but you don't seem to be able to compare , say, (21:21) to null or an empty string - the former isn't recognised and the latter causes an internal error, which isn't good.
You can make the longer records be sent to the bad file by forcing an SQL error when it tries to put a longer parsed value from the file into the field, by changing:
FOO_MAX20 POSITION(1:20)
to
FOO_MAX20 POSITION(1:21)
Values that are up to 20 characters are still loaded:
select * from foobar;
FOO_MAX20
--------------------
1234567
1234567890123456
7135009765625
048669433593
7
527
6 rows selected
but for anything longer than 20 characters it'll try to put 21 chars in to the database's 20-char field, which gets this in the log:
error processing column FOO_MAX20 in row 3 for datafile /path/to/dir/foobar.txt
ORA-12899: value too large for column FOO_MAX20 (actual: 21, maximum: 20)
And the bad file gets that record:
126464843750476074218751012345678901234567890
Have a CHECK CONSTRAINT on the column to not allow any value exceeding the `LENGTH'.

Resources