FAQs about Oracle Development

Source: Internet
Author: User
Tags base 10 logarithm mathematical functions
FAQs about Oracle Development

SQL Server and Oracle are the most common databases in daily project development, but more beginners may be more familiar with SQL Server, because Microsoft is easy to use, it is silly. However, Oracle's position in the market cannot be ignored, while Oracle and SQL Server are still very different. This section describes some issues that beginners often encounter when using Oracle for development.

5.5.1 comparison of common functions of Oracle and SQL Server

1. mathematical functions

 
 
  1. ① Absolute value
  2. S: Select ABS (-1) Value
  3. O: Select ABS (-1) value from dual
  4. ② INTEGER (large)
  5. S: Select ceiling (-001) Value
  6. O: Select Ceil (-001) value from dual
  7. ③ Round (small)
  8. S: Select floor (-001) Value
  9. O: Select floor (-001) value from dual
  10. ④ INTEGER (truncation)
  11. S: Select cast (-002As Int) Value
  12. O: Select trunc (-002) value from dual
  13. ⑤ Rounding
  14. S: Select round (23456,4) value 23460
  15. O: Select round (23456,4) value from dual 2346
  16. ⑥ E is the base power
  17. S: Select exp (1) Value
  18. O: Select exp (1) value from dual
  19. 7. Take the base logarithm of E.
  20. S: Select log (7182818284590451) Value
  21. O: Select Ln (7182818284590451) value from dual;
  22. Returns the base 10 logarithm of a shard.
  23. S: Select log10 (10) Value
  24. O: Select log (10, 10) value from dual;
  25. Returns the square of a shard.
  26. S: Select square (4) Value
  27. O: Select power (4, 2) value from dual
  28. Returns the square root of a shard.
  29. S: Select SQRT (4) Value
  30. O: Select SQRT (4) value from dual
  31. Evaluate the base power of any number
  32. S: Select power (3, 4) Value
  33. O: Select power (3, 4) value from dual
  34. Random Number
  35. S: Select rand () Value
  36. O: select Sys. dbms_random.value (0, 1) value from dual;
  37. Get the symbol
  38. S: Select sign (-8) Value-1
  39. O: Select sign (-8) value from dual-1

2. Numerical Comparison

 
 
  1. ① Calculate the maximum value of a set
  2. S: Select max (value) value from
  3. (Select 1 value Union
  4. Select-2 value Union
  5. Select 4 value Union
  6. Select 3 value)
  7. O: Select greatest (1,-2, 4, 3) value from dual
  8. ② Calculate the minimum value of a set
  9. S: select Min (value) value from
  10. (Select 1 value Union
  11. Select-2 value Union
  12. Select 4 value Union
  13. Select 3 value)
  14. O: Select least (1,-2, 4, 3) value from dual
  15. ③ How to handleNullValue (in the F2 FieldNullReplace with 10)
  16. S: Select F1, isnull (F2, 10) value from TBL
  17. O: Select F1, nvl (F2, 10) value from TBL

3. String Functions

 
 
  1. ① Calculate the character serial number
  2. S: Select ASCII ('A') Value
  3. O: Select ASCII ('A') Value from dual
  4. ② Calculate characters from the serial number
  5. S: selectChar(97) Value
  6. O: Select CHR (97) value from dual
  7. ③ Connection
  8. S: select'11'+'22'+'33'Value
  9. O: Select Concat ('11','22') | 33 value from dual
  10. ④ Substring position -- return 3
  11. S: Select charindex ('S','Dsq', 2) Value
  12. O: Select instr ('Dsq','S', 2) value from dual
  13. ⑤ Position of the fuzzy substring -- 2 is returned. If % is removed from the parameter, 7 is returned.
  14. S: Select patindex ('% D % Q %','Sdsfasdqe') Value
  15. O: no oracle found, but instr can use the fourth parameter to control the number of occurrences.
  16. Select instr ('Sdsfasdqe','Sd', 1, 2) value from dual returns 6
  17. 6. substring
  18. S: Select substring ('Abcd', 2, 2) Value
  19. O: Select substr ('Abcd', 2, 2) value from dual
  20. 7. substring substitution -- Return aijklmnef
  21. S: select stuff ('Abcdef', 2, 3,'Ijklmn') Value
  22. O: Select Replace ('Abcdef','Bcd','Ijklmn') Value from dual
  23. Trim left space filling (the 1st parameters of lpad are spaces, which is the same as the space function)
  24. S: Select space (10) +'Abcd'Value
  25. O: Select lpad ('Abcd', 14) value from dual
  26. Trim right fill space (the 1st parameters of rpad are spaces, which is the same as the space function)
  27. S: select'Abcd'+ Space (10) Value
  28. O: Select rpad ('Abcd', 14) value from dual
  29. Comparative pronunciation similarity (the two words return the same value and have the same pronunciation)
  30. S: Select soundex ('Smith'), Soundex ('Smy')
  31. O: Select soundex ('Smith'), Soundex ('Smy') From dual
  32. SQL Server uses select difference ('Smithers','Smythers')
    Returns 0 to compare the soundex difference ~ 4, 4 is the same tone, 1 is the highest

4. Date Functions

 
 
  1. ① System time
  2. S: Select getdate () Value
  3. O: Select sysdate value from dual
  4. ② Calculate the date
  5. S: Select convert (Char(10), getdate (), 20) Value
  6. O: Select trunc (sysdate) value from dual
  7. Select to_char (sysdate,'Yyyy-mm-dd') Value from dual
  8. ③ Time
  9. S: Select convert (Char(8), getdate (), 108) Value
  10. O: Select to_char (sysdate,'Hh24: mm: ss') Value from dual
  11. ④ Last day of the month
  12. S: Unknown
  13. O: Select last_day (sysdate) value from dual
  14. ⑤ One day of the week (such as Sunday)
  15. S: Unknown
  16. O: Select next_day (sysdate, 7) vaule from dual;
  17. ⑥ String Conversion time
  18. S: Select cast ('2017-09-08'AsDatetime) Value
  19. O: Select to_date ('2017-01-05 22:09:38','Yyyy-mm-dd Co., hh24-mi-ss')
    Vaule from dual;
  20. 7. Calculate the difference of a part of the date (for example, the second)
  21. S: Select datediff (SS, getdate (), getdate () + 3) Value
  22. O: Subtract directly with two dates (for example, d1-d2 = 3)
  23. Select (d1-d2) * 24*60*60 vaule from dual;
  24. Seek a new date (for example, minute) based on the difference value)
  25. S: Select dateadd (MI, 8, getdate () Value
  26. O: Select sysdate + 8/60/24 vaule from dual;
  27. Differences between Oracle statements and SQL Server statements

    1. How to Implement Auto-increment columns in Oracle

    If you have always used SQL Server for database development and new projects require Oracle databases, you will suddenly find that SQL Server and Oracle are still very different. First of all, the self-increasing fields that I use in SQL Server cannot be found in Oracle. Instead, Oracle can be implemented using sequences. Example.

          
        
    1. (1) create a test data table.
    2. Create Table Test
    3. (
    4. ID number,
    5. Name varchar2 (20 ),
    6. Primary Key (ID)
    7. );
    8. (2) create a sequence.
    9. Create sequence seq_test;
    10. (3) create a trigger.
    11. Create or replace trigger autoincrement
    12. Before insert on Test
    13. For each row
    14. When (New. ID is null)
    15. Begin
    16. Select seq_test.nextval into: New. ID from dual;
    17. End;
    18. (4) Insert data.
    19. Insert into test (name) values ('Name1');
    20. (5) view the insert result.
    21. Select * from test;

    2. parameter differences

    In SQL Server, we can use the SQL statement as follows: "insert into table (field1, field2) values (@ value1, @ value2)", and then we will create several new paramters: new sqlparameter ("@ value1", value )...

    The @ + character is used in the query string to describe the parameter. The parameter name in sqlparameter must also use the "@" symbol. In Oracle, SQL statements cannot use the @ symbol instead of the colon ":", for example:

           
         
    1. -- SQL statement of SQL Server
    2. Insert into table (column1, column2) values (@ value1, @ value2)
    3.  
    4. -- SQL statement in cmdel
    5. Insert into table (column1, column2) values (: value1,: value2)

    3. Different stored procedures

    The stored procedure in Oracle is called packages. A package is divided into a packet header and a package body, similar to class declaration in C ++. The header defines the name and parameters of a stored procedure. Besides the name and parameters, the package body also includes all statements of the stored procedure. Unlike SQL Server, stored procedures in Oracle are generally written as functions rather than procedure. Oracle stored procedures do not directly return record sets. Record Sets are returned through parameters in the form of cursors. A package can contain multiple stored procedures. stored Procedure name: The following is a typical Oracle stored procedure, which is located in the packages named "test". Its usage should be test. getlist.

          
        
    1. Function getlist (keywords in varchar2, p_info_list_cursorOut 
      Get_data_cur_type)
    2. Return number
    3. As
    4. Begin
    5. Open p_info_list_cursor
    6. Select * from test where key = keywords
    7. ;
    8. Return 0;
    9. End;
    10. Solution for ASP. NET connection to Oracle failure

      After the ASP. NET Oracle client is installed, ASP. NET ApplicationsProgramUse System. data. if this error occurs when the oracleclient accesses the Oracle database: system. exception: system. data. oracleclient requires Oracle client software version 8.1.7 or greater. however, on the same machine, the winform client can access the database normally.

      The reason is:

      When the Oracle 9i client is installed in the NTFS partition of windows, the Security Authentication Settings are incorrect. As a result, the authenticated users user on the local machine cannot see the contents in the ORACLE_HOME directory. net to authenticated users permission to use system. data. the preceding error is reported when the oracleclient connects to the Oracle database.

      The solution is as follows:

      (1) log on as an administrator.

      (2) Find the ORACLE_HOME folder (my name is c: \ oracle \ ora92), right-click it, and choose "properties"> "security" from the shortcut menu, select the "Authenticated Users" option in the group or user column, remove the "read and run" permission from the permission list below, and then click the "application" button; reselect the "read and run" option, click the "application" button, click the "advanced" button under the permission box, and select the application following the "Authenticated Users" option, select the "folder, subfolders, and files" option and click "OK" to apply the permission change to the folder.

      (3) restart the computer to make the permission settings take effect (this step is important ).

      (4) log on and run the ASP. NET application to connect to the Oracle database.

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.