Migrate relational table to Redis - redis

Currently, I have a system that record records at oracle database, a specific table. I'm want change to Redis, but I'm with some doubts.
Field's table:
BRAS_INTERFACE VARCHAR2(30 BYTE) No 1
CLVAN NUMBER(10,0) No 2
NAS_IDENTIFIER VARCHAR2(100 BYTE) No 3
NAS_IP_ADDRESS VARCHAR2(15 BYTE) No 4
SVLAN NUMBER(10,0) No 5
FRAMED_IP_ADDRESS VARCHAR2(15 BYTE) Yes 6
CLASS VARCHAR2(100 BYTE) Yes 7
MAC_ADDRESS VARCHAR2(20 BYTE) Yes 8
PROFILE VARCHAR2(100 BYTE) Yes 9
TIME_STAMP TIMESTAMP(6) Yes 10
TYPE_TICKET VARCHAR2(10 BYTE) Yes 11
SMART_INTERFACE VARCHAR2(100 BYTE) Yes 12
CVLAN NUMBER(10,0) Yes 13
Constraint's table:
"BRAS_INTERFACE" IS NOT NULL
"CLVAN" IS NOT NULL
"NAS_IDENTIFIER" IS NOT NULL
"NAS_IP_ADDRESS" IS NOT NULL
"SVLAN" IS NOT NULL
The table keep PPPoE sessions, when a subscriber go to up, then insert a record, when a subscriber go to down, then delete a record, both cases, the fields: BRAS_INTERFACE, CLVAN, NAS_IDENTIFIER, NAS_IP_ADDRESS and SVLAN useds as constraint.
I do querys at table by constraints or by any another field.
With Redis how I can to do some thing like relational table?

If you have questions about what Redis can do I would think you should look at the vendor site: https://redis.io/topics/introduction. Oracle and SQL Server both support in-memory tables by the way.

Related

i want to update same table's value through trigger

columns data_type nullable default
ID VARCHAR2(30 BYTE) No
PASSWORD VARCHAR2(20 BYTE) No
NAME VARCHAR2(20 BYTE) No
BIRTH CHAR(11 BYTE) No
PHONE VARCHAR2(11 BYTE) No
CBD_1 VARCHAR2(20 BYTE) Yes
CBD_2 VARCHAR2(20 BYTE) Yes
CBD_3 VARCHAR2(20 BYTE) Yes
CBD_4 VARCHAR2(20 BYTE) Yes
CBD_5 VARCHAR2(20 BYTE) Yes
CDATE VARCHAR2(20 BYTE) Yes to_char(sysdate, 'dd-Mon-YYYY')
UDATE VARCHAR2(20 BYTE) Yes to_char(sysdate, 'dd-Mon-YYYY')
My question is: I want to insert update time when I update existed record in this table through a trigger
and here is my code
create or replace trigger udate
before update or delete on member for each row
declare
u_id varchar2(30);
begin
u_id := :old.id;
update member set udate = to_char(sysdate, 'dd-Mon-YYYY') where id = u_id;
end;
error message
One error saving changes to table "JSP"."MEMBER":
Row 6: ORA-04091: table JSP.MEMBER is mutating, trigger/function may not see
it
ORA-06512: at "JSP.UDATE", line 5
ORA-04088: error during execution of trigger 'JSP.UDATE'
I already tried :new.id but it didn't work
Don't use update, simply assign the value:
create or replace trigger udate
before update on member for each row
begin
:new.udate := to_char(sysdate, 'dd-Mon-YYYY');
end;
Doing that "before delete" doesn't make sense, as the row will be deleted anyway.
You should never store DATE values in a varchar column. That is a horrible idea. Don't do that.

SQL Query to count entire duplicate row

I am looking for help with a query to do the following:
Before the insert of a row, find how many rows in 2 tables have the same information as is being inserted.
So basically I am looking to see if this row will be a complete duplicate.
I want to base this on all the columns, not just the PK, because if there is even one column different then this is a valid insert.
This is something along the lines of what I need, although incorrect:
SELECT COUNT(*)
FROM ORDER_TRF_HEADER
WHERE
((SELECT * FROM ORDER_TRF_HEADER_COMPLETE WHERE MA_PONUM = '29608207') = (SELECT * FROM ORDER_TRF_HEADER WHERE MA_PONUM = '29608207'));
Table - ORDER_TRF_HEADER
MA_CUST VARCHAR2(8 BYTE)
MA_PONUM VARCHAR2(30 BYTE)
MA_ODATE VARCHAR2(8 BYTE)
MA_ITEMS NUMBER(3,0)
MA_SALEM VARCHAR2(2 BYTE)
MA_PDAYS NUMBER(3,0)
MA_CURR VARCHAR2(3 BYTE)
Table - ORDER_TRF_HEADER_COMPLETE
MA_CUST VARCHAR2(8 BYTE)
MA_PONUM VARCHAR2(30 BYTE)
MA_ODATE VARCHAR2(8 BYTE)
MA_ITEMS NUMBER(3,0)
MA_SALEM VARCHAR2(2 BYTE)
MA_PDAYS NUMBER(3,0)
MA_CURR VARCHAR2(3 BYTE)
Thanks
I want to base this on all the columns, not just the PK, because if there is even one column different then this is a valid insert.
then your issue is that you have NOT defined your primary key correctly.
Certainly there are good reasons for not maintaining a primary key consisting of every attribute in the record, however a better solution than checking for duplicates in such a clumsy way before inserting would be to maintain a has of the data as a unique key.
You can try INTERSECT.
SELECT COUNT(*)
FROM (SELECT *
FROM order_trf_header_complete
WHERE ma_ponum = '29608207'
INTERSECT
SELECT *
FROM order_trf_header
WHERE ma_ponum = '29608207') ;
Note:: You better use all column names explicitly instead of select *

Oracle auto increment - newbie so go easy please [duplicate]

This question already has answers here:
Auto-increment in Oracle without using a trigger
(9 answers)
Auto Increment for Oracle
(7 answers)
Closed 9 years ago.
Hi all I am looking to create an auto increment in the following table using GUEST_ID as the column that would increment.
CREATE TABLE "HOTEL_BOOKINGS"."GUEST" (
"GUEST_ID" NUMBER,
"LASTNAME" VARCHAR2(100 BYTE),
"FIRSTNAME" VARCHAR2(100 BYTE),
"ADDRESS" VARCHAR2(255 BYTE),
"TOWN" VARCHAR2(100 BYTE),
"PHONE" NUMBER,
"POSTCODE" VARCHAR2(10 BYTE),
"EMAIL" VARCHAR2(255 BYTE)
);
I have tried nearly everything to get this working and am at my wits end
once again sorry if this is a newbie question but I need coursework handed in tomorrow
Oracle doesn't have an autoincrement property, but you could use a sequence and an ON INSERT trigger to utilize its value:
CREATE SEQUENCE hotel_bookings_seq
START WITH 1
INCREMENT BY 1
NOMAXVALUE;
CREATE TRIGGER hotel_bookings_tr
BEFORE INSERT ON hotel_bookings
FOR EACH ROW
BEGIN
SELECT hotel_bookings_seq.nextval INTO :new.guest_id FROM dual;
END;
/

ALTER statement: Why VARCHAR2(50 BYTE) instead of VARCHAR2(50 CHAR)? [duplicate]

This question already has answers here:
varchar2(n BYTE|CHAR) default -> CHAR or BYTE
(2 answers)
Closed 9 years ago.
I executed the following (Oracle 11g) SQL statement to increase an existing column's length from VARCHAR2(20 CHAR) to VARCHAR2(50 CHAR):
ALTER TABLE USERX.MY_TABLE MODIFY (LASTNAME VARCHAR2(50));
It succeeded without incident, but when I look at the new Data Type column, I see: VARCHAR2(50 BYTE) instead of VARCHAR2(50 CHAR).
My questions are:
Why BYTE and not CHAR? What have I done incorrectly?
How do I fix the column's length to be VARCHAR2(100 CHAR)?
Answering myself (thanks to the tip provided by this other answer):
I should have executed instead:
ALTER TABLE USERX.MY_TABLE MODIFY (LASTNAME VARCHAR2(50 CHAR));
(note the extra CHAR after 50)

SQL server: retrieve grouped data from a table

Write SQL query based on info below Table TRACK_BY_WCN
CREATE TABLE CONTRACTOPS.TRACK_BY_WCN(
CLAIM_TYPE CHAR(1 BYTE)
,LOBID CHAR(3 BYTE)
,WCN VARCHAR2(10 BYTE)
,RECEIVED_DATE DATE
,FOUND_DATE DATE
,CLAIM_NUMBER VARCHAR2(10 BYTE) DEFAULT NULL
,HOLD_FLAG CHAR(1 BYTE) DEFAULT NULL
,LOCK_FLAG VARCHAR2(3 BYTE) DEFAULT NULL
,BILLED NUMBER(16,2))
There are data in first 3 columns, CLAIM_TYPE, LOBID, WCN, and there is program doing match by WCN. When found, the program will update all other fields. Please use one SQL to get count on how many WCN and how many matched claims, by claim type.
It's hard to tell what you are asking exactly. This might be what you want:
Count rows per WCN:
SELECT WCN, count(*) AS row_count
FROM CONTRACTOPS.TRACK_BY_WCN
GROUP BY WCN;
Count rows per CLAIM_TYPE
SELECT CLAIM_TYPE, count(*) AS row_count
FROM CONTRACTOPS.TRACK_BY_WCN
GROUP BY CLAIM_TYPE;
Count claims per WCN and CLAIM_TYPE
SELECT WCN, CLAIM_TYPE, count(*) AS row_count
FROM CONTRACTOPS.TRACK_BY_WCN
GROUP BY WCN, CLAIM_TYPE;