Seven considerations for converting MySQL to Oracle

Source: Internet
Author: User

Http://database.51cto.com/art/201011/233370.htm

 

When the MySQL database does not meet our large demand, we need to migrate the data in the MySQL database to the Oracle database. In this process, some problems are worth noting.

AD:


    There are many application projects. At the beginning, MySQL Databases can basically meet various functional requirements. As the number of application users increases and the amount of data increases, MySQL gradually becomes overwhelmed: the connection is slow or even down, so there is a need for MySQL to switch to Oracle, ApplicationsProgramMake some modifications accordingly. The following are some considerations for converting MySQL to Oracle.

    1. Automatically increasing data type Processing

    MySQL has a data type that increases automatically. When you insert a record, you do not need to operate on this field. The data value is automatically obtained. Oracle does not have an auto-increasing data type. You need to create an auto-increasing serial number. When inserting a record, you need to assign the next value of the serial number to this field.

    Create sequence serial number name (preferably table name serial number mark) increment by 1 start with 1 maxvalue 99999 cycle nocache;

    The maximum value is determined by the length of the field. If the defined auto-increasing serial number (6) is used, the maximum value is 999999 insert statement to insert this field value: the name of the serial number. nextval

    2. Single quotes

    MySQL can use double quotes to enclose strings. Oracle can only use single quotes to enclose strings. You must replace single quotes before inserting and modifying strings: replace all the existing single quotes with two single quotes.

    3. Processing of paging SQL statements

    The SQL statement for MySQL to process paging is relatively simple. It uses limit to start the position and record the number. In PHP, you can also use seek to locate the result set. It is complicated for Oracle to process paging SQL statements. Each result set has only one rownum field to indicate its position, and only rownum & lt; 100 can be used, and rownum> 80 cannot be used. The following two SQL statements (ID is the field name of the unique keyword) are better after analysis ):

    Statement 1:

     
      
      
    1. Select ID, [field_name,...] From table_name where
    2. ID in (select ID from (select rownum as numrow,
    3. ID from table_name where Condition 1 order by condition 2)
    4. Where numrow>80 and numrow & lt; 100) order by Condition 3;

    Statement 2:

     
      
      
    1. Select * from (select rownum as numrow,
    2. C. * from (select [field_name,...]
    3. From table_name where Condition 1 order by condition 2) C)
    4. Where numrow>80 and numrow & lt; 100) order by Condition 3;

    4. Processing long strings

    Oracle processing of long strings also has some special features. The maximum length of a string that can be operated during insert and update is less than or equal to 4000 single bytes. If you want to insert a longer string, use the clob type for the field to use the dbms_lob package that comes with Oracle. Before inserting a modification record, you must make a non-null and length judgment. If the field value cannot be blank or the field value beyond the length is exceeded, a warning should be given, and the last operation is returned.

    5. Processing date fields

    MySQL date fields are divided into Date and time. The Oracle Date field is only date, which contains information about the year, month, day, hour, minute, and second. the system time of the current database is sysdate, accurate to seconds, or use a string to convert to the date type function to_date ('1970-08-01 ', 'yyyy-MM-DD') year-month-day 24 hours: minute: Second format YYYY-MM-DD hh24: MI: SS to_date ()

    The mathematical formula for converting a datetime field to a string function to_char ('1970-08-01 ', 'yyyy-MM-DD hh24: MI: ss') is very different. MySQL uses date_field_name> subdate (now (), interval 7 day) to locate the current time seven days from the current time and uses date_field_name> sysdate-7;

    6. Handling of null characters

    Non-empty fields in MySQL are also empty. empty fields are not allowed in Oracle. The Oracle table structure is defined based on the not null value of MySQL. errors may occur when data is imported. Therefore, when importing data, you need to judge the null character. If it is null or null, you need to change it to a space string.

    7. Fuzzy comparison of strings

    MySQL can also use the field name like in the field name likeoracle, but this method cannot use the index, and the speed is not as fast as using the string comparison function instr (field name, string)> 0 will get more accurate search result 8. in programs and functions, pay attention to the release of result sets and pointers after database operations are completed.
     

    The preceding considerations for converting MySQL to Oracle are for your reference.

     

     

    [Edit recommendations]

    Detailed description of the actual configuration of slowlog in MySQL

    Provides you with an in-depth understanding of MySQL string connection

    Take you to understand the features of MySQL

    MySQL table alias usage

    Hash-based MySQL table sharding

     

    Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.