I have been following this tutorial : https://www.youtube.com/watch?v=ngOm5uBP1uE&feature=emb_title.
I followed all the codes with my needed variables and they are as follows :
-Creating Table
CREATE TABLE "TB_USERS" ( "S_ID" NUMBER GENERATED ALWAYS AS IDENTITY(START with 1 INCREMENT by 1), "S_FNAME" varchar2(30) NOT NULL ENABLE, "S_LNAME" varchar2(30) NOT NULL ENABLE, "S_Password" varchar2(30) NOT NULL ENABLE, "S_DOB" date NOT NULL ENABLE, "EMAIL" varchar2(255) NOT NULL ENABLE, PRIMARY KEY ("S_ID") USING INDEX ENABLE, CONSTRAINT "USERS_U1" UNIQUE ("EMAIL") USING INDEX ENABLE );
-Creating Encrypt Function
CREATE OR REPLACE FUNCTION ENCRYPT_PASSWORD ( p_username in varchar2, p_password in varchar2) return varchar2 is l_password varchar2(255); l_salt varchar2(30) := 'RANDOM_SALT_STRING'; begin l_password := DBMS_OBFUSCATION_TOOLKIT.MD5(input_string => UPPER(p_username) || l_salt || UPPER(p_password)); return l_password; end ENCRYPT_PASSWORD;
Both of these sql scripts have been successful but when it comes to declaring the trigger, it gives me the error “ORA-04070: invalid trigger name ORA-06512: at “SYS.WWV_DBMS_SQL_APEX_200100“. The code I wrote for this script was :
CREATE OR REPLACE TRIGGER 'TB_USERS_TRIGGER' BEFORE INSERT ON TB_USERS for each row BEGIN :new.EMAIL := upper(:new.EMAIL); :new.s_fname := lower(:new.s_fname); :new.s_password := ENCRYPT_PASSWORD(upper(:new.email), :new.s_password); END; / Insert into TB_USERS ("EMAIL","S_Password") values ('VASCODIGAMA@GMAIL.COM','rainuma_16'); /
Any ideas where I made a mistake or went wrong?
Advertisement
Answer
I think you should remove double quotation all together.
SQL> CREATE TABLE TB_USERS ( S_ID NUMBER GENERATED ALWAYS AS IDENTITY(START with 1 INCREMENT by 1), S_FNAME varchar2(30) NOT NULL ENABLE, S_LNAME varchar2(30) NOT NULL ENABLE, S_Password varchar2(30) NOT NULL ENABLE, S_DOB date NOT NULL ENABLE, EMAIL varchar2(255) NOT NULL ENABLE, PRIMARY KEY (S_ID) USING INDEX ENABLE, CONSTRAINT USERS_U1 UNIQUE (EMAIL) USING INDEX ENABLE ); Table created. SQL> CREATE OR REPLACE FUNCTION ENCRYPT_PASSWORD ( p_username in varchar2, p_password in varchar2) return varchar2 is l_password varchar2(255); l_salt varchar2(30) := 'RANDOM_SALT_STRING'; begin l_password := DBMS_OBFUSCATION_TOOLKIT.MD5(input_string => UPPER(p_username) || l_salt || UPPER(p_password)); return l_password; end ENCRYPT_PASSWORD; / Function created. SQL> CREATE OR REPLACE TRIGGER TB_USERS_TRIGGER BEFORE INSERT ON TB_USERS for each row BEGIN :new.EMAIL := upper(:new.EMAIL); :new.s_fname := lower(:new.s_fname); :new.s_password := ENCRYPT_PASSWORD(upper(:new.email), :new.s_password); END; / Trigger created.