Is there any way to perform md5 hashing in oracle sql developer on every field of an column, and store the result hash in corresponding column(md5) - oracle

select standard_hash(‘text’,’MD5’) from dual.
The above script provides md5 hashing in oracle sql developer
But i want to do hashing on my table column and store the result in corresponding field.
I have also tried:
INSERT INTO TABLENAME(MD5)
SELECT standard_hash(TEXT,’MD5’) from TABLENAME
but it is giving error: ORA-01400 cannot insert into null

Normally, the standard_hash will give you an output which you perhaps can't store in the same column you had, because the length won't be the same. To avoid this, I recommend you use raw as data type for the column where you want to store the hash value.
MD5 processes an arbitrary-length message into a fixed-length output of 128 bits, typically represented as a sequence of 32 hexadecimal digits.
SQL> create table test_normal ( c1 varchar2(20) ) ;
Table created.
SQL> insert into test_normal values ( 'AbdiRSDAloPdi8978' ) ;
1 row created.
SQL> select standard_hash(c1) from test_normal ;
STANDARD_HASH(C1)
----------------------------------------
BD6062214847DB31BB40A0185E3F89B0FB6980BF
SQL> alter table test_normal add ( c2 raw(256) );
Table altered.
SQL> update test_normal set c2=standard_hash(c1) ;
1 row updated.
SQL> select * from test_normal ;
C1
--------------------
C2
--------------------------------------------------------------------------------
AbdiRSDAloPdi8978
BD6062214847DB31BB40A0185E3F89B0FB6980BF
SQL> select standard_hash(c1,'MD5') from test_normal ;
STANDARD_HASH(C1,'MD5')
--------------------------------
E404D2867EB21AD65827E2858A07CA65

Related

select from the table name values after _ using oracle sql

Suppose if the table name is ABC_XYZ_123. I want to extract the integer values after _.
The output should be integer values after _.
In the above case, the output should be 123.
I have used the below sql query.
select from table_name like 'XXX_%';
But I am not getting required output. Can anyone help me with this query.
Thanks
Using REGEXP_SUBSTR with a capture group we can try:
SELECT REGEXP_SUBSTR(name, '_(\d+)$', 1, 1, NULL, 1)
FROM yourTable;
The question is somewhat unclear:
it looks as if you're looking for table names that contain number at the end, while
query you posted suggests that you're trying to select those numbers from one of table's columns
I'll stick to
Suppose if the table name is ABC_XYZ_123
If that's so, it is the data dictionary you'll query. USER_TABLES contains that information.
Let's create that table:
SQL> create table abc_xyz_123 (id number);
Table created.
Query selects numbers at the end of table names, for all my tables that end with numbers.
SQL> select table_name,
2 regexp_substr(table_name, '\d+$') result
3 from user_tables
4 where regexp_like(table_name, '\d+$');
TABLE_NAME RESULT
-------------------- ----------
TABLE1 1
TABLE2 2
restore_point-001 001
ABC_XYZ_123 123 --> here's your table
SQL>
Apparently, I have a few of them.

Query select on varchar2 works without apex

I have a query on field type varchar2 that works also without apex.
E.g.
SELECT * FROM table WHERE field = 123456
where field is varchar2, and it returns the result and not the
ORA-01722: invalid number.
There is some setting on DB that make it possible? Thankx.
If that column's datatype is varchar2, then enclose its value with single quotes:
SELECT * FROM table WHERE field = '123456'
There's no setting that would "remove" invalid number error, as far as I can tell.
Query you posted works when there are only "numbers" in a table; though, when "something else" (it is a varchar2 after all) is stored in the column, it won't work any more:
Sample table:
SQL> create table test (id number, field varchar2(10));
Table created.
Numbers only:
SQL> insert into test (id, field) values (1, 123456);
1 row created.
SQL> select * from test where field = 123456;
ID FIELD
---------- ----------
1 123456
Enter value that contains e.g. letters in field:
SQL> insert into test (id, field) values (2, 'ABC');
1 row created.
SQL> select * from test where field = 123456;
ERROR:
ORA-01722: invalid number
no rows selected
SQL>
So, it is not "Apex" to blame, but you who tried to misuse what you have.

Generate Alphanumber field and Increment

i have a transaction form in oracle apex within that form has a page item called transactioncode.
what i will like, is to generate a alphanumeric code on page load for eg. AA110 which will increment everytime they create a new transaction.
table: transactioncode, transactiondate, productcode, productname.
I have not tried any sql or pl/sql or trigger
You can use a SEQUENCE and assign the sequence.nextval to the field transactioncode or define the field as IDENTITY if you are using 12.1 onwards. If your version is prior to 12.1, then you need a trigger to associate the sequence.
Example below will show you column c1 as identity, column c2 using sequence
SQL> create sequence my_example start with 1000 increment by 1 maxvalue 9999999999999999 ;
Sequence created.
SQL> create table my_test ( c1 NUMBER GENERATED BY DEFAULT AS IDENTITY , c2 number default my_example.nextval , c3 varchar2(1) ) ;
Table created.
SQL> insert into my_test ( c3 ) values ( 1 ) ;
1 row created.
SQL> commit;
Commit complete.
SQL> select * from my_test ;
C1 C2 C
---------- ---------- -
1 1000 1
The following restrictions applied to IDENTITY fields
One identity column per table.
Identity columns must be numeric types, and can't be user-defined
data types.
Identity columns can't have a default clause.
Identity columns are implicitly have NOT NULL and NOT DEFERRABLE constraints.
They can't be explicitly alter to anything else. From the doc, "If an
identity column is encrypted, then the encryption algorithm may be
inferred. Oracle recommends that you use a strong encryption
algorithm on identity columns."
The CREATE TABLE ... AS SELECT will not inherit the identity property on a column. This is true for several structural definitions. If you care about structure, you
should always CREATE TABLE, then use INSERT INTO ... SELECT to
populate it.

How to increment the value of the unique constraint column value in ORACLE

How to increment the value of the unique constraint column value in ORACLE, in the select statement.
For example, in a table 'BILLING_TABLE' - column BLNG_Sk is the unique key (Autoincremented).
So while inserting a new record into the BILLING_TABLE, for the column BLNG_SK we need to give the value (Which is the increment by 1 from the present max value.)
For example, if BLNG_SK max value is 12321.
new record should be 12322.
how to achieve this in Oracle?
Oracle has a SEQUENCE object which provides the functionality you require.
You create one using the CREATE SEQUENCE SQL statement.
The Oracle documentation provides all the required information and the documentation is available via Oracle's Web site.
Assuming you are on Oracle 12.1 or later, define it as an identity column and do not pass any value when inserting:
create table testtable
( test_id number generated always as identity
constraint testtable_pk primary key
, othercol varchar2(10) );
insert into testtable (othercol) values ('Demo');
select * from testtable;
TEST_ID OTHERCOL
---------- ----------
1 Demo
insert into testtable (othercol) values ('Demo #2');
select * from testtable;
TEST_ID OTHERCOL
---------- ----------
1 Demo
2 Demo #2
Try creating a sequence and a trigger. This is the case when you provide the value manually.
CREATE SEQUENCE dept_seq START WITH 12322;
Trigger definition:
CREATE OR REPLACE TRIGGER dept_bir
BEFORE INSERT ON BILLING_TABLE
FOR EACH ROW
BEGIN
SELECT dept_seq.NEXTVAL
INTO :new.id
FROM dual;
END;
/

Data Type issue in one of the filelds in Table

One of my field has Data Type as Numeric and the size is (16,8). If I give the value as 0.000000012 will it take and load it in the table? As there are 9 places after the decimal.
It will accept and round the values (at least in 11g):
SQL> CREATE TABLE tst (c1 NUMBER(10,2));
Table created
SQL> INSERT INTO tst VALUES (9.123);
1 row inserted
SQL> INSERT INTO tst VALUES (9.129);
1 row inserted
SQL> SELECT * FROM tst;
C1
------------
9.12
9.13

Resources