Wednesday, January 18, 2017

MySQL Error Handling


Three type of Handler_Action:

CONTINUE
EXIT
UNDO

Type of Condition Value:

mysql_error_code
sqlstate_value
SQLWarning
SQLException
NotFound



GET DIAGNOSTICS, you can get all of the error information, and you should, if not already.

If you were going to use GET DIAGNOSTICS from the command line, you could use something like this (immediately following your query):

GET DIAGNOSTICS CONDITION 1
 @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
SELECT @sqlstate, @errno, @text;

MySQL error code: 1175 during UPDATE in MySQL Workbench

Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Queries and reconnect. 0.000 sec


Try disabling that using these steps -
Edit > Preferences > Sql Editor > uncheck the "Safe Updates"
Note - try reconnecting the server (Query > Reconnect to Server) and than run your query again.

Monday, July 4, 2016

MySQL date and time functions


MySQL date and time functions
ADDDATE()
ADDTIME()
CONVERT_TZ()
CURDATE()
CURRENT_DATE()
CURRENT_TIME()
CURRENT_ TIMESTAMP()
CURTIME()
DATE_ADD()
DATE_FORMAT()
DATE_SUB()
DATE()
DATEDIFF()
DAY()
DAYNAME()
DAY OF MONTH()
DAY OF WEEK()
DAY OF YEAR()
EXTRACT()
FROM_DAYS()
FROM_UNIXTIME()
GET_FORMAT()
HOUR()
LAST_DAY()
LOCALTIME()
LOCALTIMESTAMP()
MAKEDATE()
MAKETIME()
MICROSECOND()
MINUTE()
MONTH()
MONTHNAME()
NOW()
PERIOD_ADD()
PERIOD_DIFF()
QUARTER()
SEC_TO_TIME()
SECOND()
STR_TO_DATE()
SUBDATE()
SUBTIME()
SYSDATE()
TIME_FORMAT()
TIME_TO_SEC()
TIME()
TIMEDIFF()
TIMESTAMP()
TIMESTAMPADD()
TIMESTAMPDIFF()
TO_DAYS()
UNIX_TIMESTAMP()
UTC_DATE()
UTC_TIME()
UTC_TIMESTAMP()
WEEK()
WEEKDAY()
WEEK OF YEAR()
YEAR()
YEARWEEK()

Thursday, April 28, 2016

MySQL Functions



1)  The MySQL LAST_INSERT_ID function to get the last insert id that MySQL has been generated.
2)  STR_TO_DATE() function to convert strings into a date and/or time values.

   SELECT STR_TO_DATE('20130101 113012','%Y%m%d %h%i%s') ;

      2013-01-01 11:30:12

Monday, March 28, 2016

Ref Cursors Oracle

Ref Cursors Oracle

Example :-

Declare
TYPE honni IS REF CURSOR RETURN emp%ROWTYPE;
refcur1  honni;
Begin
Open refcur1 for select * from emp;
Open refcur1 for select * from dept;
End;

REF CURSOR can be categorized into three

1. Strong Ref Cursor
Ref Cursors which has a return type is classified as Strong Ref Cursor.

Example :-

Declare
TYPE honni IS REF CURSOR RETURN emp%ROWTYPE;
…..
End;

Here honni is a Strong Ref Cursor

2. Weak Ref Cursor
Ref Cursors which has no return type is classified as Weak Ref Cursor.

Example :-

Declare
TYPE honni IS REF CURSOR;
…..
End;

Here honni is a Weak Ref Cursor

3. System Ref Cursor
This is a system defined Ref Cursor. This also considered weak. System Ref Cursor need not declare explicitly.

Declare
honni SYS_REFCURSOR;
…..
End;

Advantages
1. Ref Cursor it self is a data type and easy to declare
2. More flexible because it is not tied to a specific query
3. Easily pass as arguments from subroutine to subroutine.
4. Very handy in transferring data between multi-language application (ex:- Java and Oracle, Dot.net and Oracle, Oracle Forms and Oracle). Since it is a pointer to the result set any client and server program can use the pointer to access the data.
5. Cursor variables are bind variables ( Read more about BIND VARIABLES )

Dis-advantages
1. Ref Cursors are not efficient as StatiC Cursor
2. Need additional code to print Ref Cursor values

In general Ref Cursors are only be used when static cursor cannot do the work

Thursday, March 17, 2016

How to change the table name during import from impdp oracle



The following is an example of using the REMAP_TABLE parameter to rename the emp table to a new name of emp1:


impdp honnikery/honnikery directory=dpump_dir1 dumpfile=honni.dmp
tables=honnikery.emp remap_table=honnikery.emp:emp1  table_exists_action =append