Common oracle code errors

Source: Internet
Author: User

1. insert into t1 values (...)
Should be: insert into t1 (...) values (...)
2. to_char (sysdate, 'yyyymmddhhmms ')
Changed:
To_char (sysdate, 'yyyymmddhh24mis ')
3. select count (*) into v_count from t1 where c1 = ?;
No_data_found error will never be triggered. v_count = 0
4. Return Value Problems
Reasonable solution:
Result: = false at the beginning of the process;
Result: = true at the end of the process;
You do not need to assign values to the result.
Unreasonable solution:
Result: = true at the beginning of the process;
Result: = false is required when the judgment of each part of the intermediate code is incorrect.
You do not need to assign a value to the result at the end of the process.
5. select c1, c2 in from t1 where c3 = v_c3;
If v_c1 = 0 or v_c2 = 0 then
If no value is found, an error is returned. No value is returned.
Use when no_data_found to determine
6. '... where c1 = '| v_c1; the c1 field is of the dense type and must be enclosed in single quotation marks. Otherwise, the c1 index cannot be used, and oracle is converted '... where c1 = '| chr (39) | to_char (v_c1) | chr (39 );
Change to: where c1 = '| chr (39) | v_c1 | chr (39 );
7. If only data exists, add and rownum <2 faster
Select count (*)
Into v_count
From t1
Where c1 = v_c1;
Addition condition: and rownum <2

7. where exists (SELECT *
FROM t1
Should be:
Where exists (SELECT 'x'
FROM t1
8. RAISE_APPLICATION_ERROR (-20000, infoMsg); do not use the 20000 error code.
The available error number of RAISE_APPLICATION_ERROR ranges from-20000 to-20999.

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.