Posts

Showing posts with the label oracle

Oracle Varchar2 DateTime Experassions - yyyy-mm-dd HH24:MI:SS

There is a verchar2 Date Time Filed  in the table which now need to get Results with the given rnage eg : up to 3 days of the past from today. Eg Field DONE_TIME SELECT  * substr(DONE_TIME,0,19) FROM EG_TABLE Convert to date : SELECT  *  TO_DATE(substr(DONE_TIME,0,19),'yyyy-mm-dd HH24:MI:SS') FROM EG_TABLE Reduce From the System Time : SELECT  *  (systimestamp-TO_DATE(substr(substr(DONE_TIME,0,19),0,19), 'yyyy-mm-dd HH24:MI:SS')) FROM EG_TABLE RANGE Comparison  : WHERE trunc(to_number(substr((systimestamp-TO_DATE(substr(substr(DONE_TIME,0,19),0,19), 'yyyy-mm-dd HH24:MI:SS')),1,instr(systimestamp-TO_DATE(substr(substr(DONE_TIME,0,19),0,19), 'yyyy-mm-dd HH24:MI:SS'),' '))))>3

Oracle Updagte if Exhist else Insert

merge into A outl   using (select 1 id, 'A' ran,3 beat from dual) s   on (outl.ID = s.id and outl.RANG=s.ran )   when matched then update set BEAT = s.beat   when not matched then insert (ID, RANG,BEAT)    values ( s.id , s.ran,s.beat);

ORACLE unique constraint (%s.%s) violated

Image
I fase following error number of time when I try to insert a set of rows to a table where primary key got changed . ORA-00001: unique constraint ( ATTRIBUTE_PK) violated When I re run the quary in SQL developer I got more information as below. SQL Error: ORA-00001: unique constraint (ATTRIBUTE_PK) violated 00001. 00000 -  "unique constraint (%s.%s) violated" *Cause:    An UPDATE or INSERT statement attempted to insert a duplicate key.            For Trusted Oracle configured in DBMS MAC mode, you may see            this message if a duplicate entry exists at a different level. *Action:   Either remove the unique restriction or do not insert the key. When I'm searching   it on the google I got the follwing , give me a hint  Oracle Reference Documents   http://oraref.tistory.com/entry/ORA-00001-unique-constraint-ss-violated I found that there is a index on the table with the same name of the primary key already deleted ,which rise

Oracle SQL Developer 'Enter value for action:'

Image
I have given the following prompt message in SQL Developer wile executing quarries like below Insert into MENU (MENUID,MENUNAME,MENULINK)  values  (64,'Add - e','index.php?controller= product & action=changePage') ; The for the prompt message is & sign indicated which expect a value as a parameter.  This will tell the story : https://asktom.oracle.com/pls/asktom/f?p=100:11:0::NO::P11_QUESTION_ID:4549764300346084350  In Order Bypass the prompt  you need to indicate   set define off at the beginning of the code.

Trick to Debug Oracle Procedure

In the Production Environment an oracle procedure can lead to Exception or Error which cannot be backtrack if a proper logging machanisam not adopted. Take the following Example Procedure, create or replace PROCEDURE DEPOSIT_INSRT (   APLICTON_ID IN VARCHAR2 , DEP01_ID IN  VARCHAR2 , tempdbexc IN OUT INTEGER ) AS BEGIN --APLICTON_ID:='1383'; --DEP01_ID :='1234567v';   tempdbexc :=1;     INSERT INTO CF_FXD_DEPOSIT ("APPLCTION_ID",  "DEP01_ID",)   VALUES (APLICTON_ID, DEP01_ID);   INSERT INTO CF_FXD_DEP_RECPT ("APPLCTION_ID") VALUES (APLICTON_ID);   DBMS_OUTPUT.put_line('COMMITTED INSERT');   COMMIT; END DEPOSIT_INSRT; In a testing Environment, Example I will use the SQLDeveloper as the web Client to Oracle ,,We can run and verify weather produce is error free for the values given hard corded values i have commented (APLICTON_ID:='1383', DEP01_ID :='1234567v';) However when procedure executi