value n)ELSERETURN (default)END IF 2. mysql If syntax descriptionFunction: IF expr1 is TRUE (expr1 Otherwise, the return value is expr3. The return value of IF () is a numeric value or a string value, depending on its locationContext.Usage:Mysql: select if (1> 2, 2, 3 );
19
Type conversion functions
TO_CHAR (SQLCODE)
Date_format/time_format
Different function namesSQL> select to_char (sysdate, 'yyyy-mm-dd') from dual;SQL>
When reading data in the cursor in Pro * C in batches, note: when reading data in the cursor in batches at the last time, the data is retrieved to hostarray, and sqlca. sqlcode is set to 1403 (no_data_found ). If you determine sqlca. sqlcode immediately after fetch, the last data may not be retrieved.
The insurance method is to define the number of last read records for a variable record:
If (sqlca.
Abnormal data network spread a lot, are some similar, induction is very detailed, the data is wandering, also not very clear the source of the original, to the unknown great God salute This article collated the information on the network, and re-typeset the next
Classification of exceptions
System comes with exception
User-defined exception
Exception throws
Plsql Engine Automatic Processing
Raise
Raise_application_error
Handl
pointer and read the current record. Use the fetch statement to forward the cursor pointer to a record and read the current record in the buffer to the variable. The fetch statement is usually used in a cyclic structure. The fetch statement is executed cyclically to retrieve rows in the result set one by one for processing. In many databases, the cursor pointer can be easily understood at any step in any direction, not just forward the cursor pointer to a row.Fetch
4. Close the cursor. Close t
processor option set the backend process wait time (seconds) (DB2BQTIME) = 1 Number of retries connected to the backend (DB2BQTRY) = 60 Request queue waiting time (seconds) (DB2RQTIME) = 5 input queue waiting time (seconds) (DB2IQTIME) = 5 Command Option (DB2OPTIONS) =-c www.2cto.com option description current settings ------ -------------------------------------------------- a display sqlca off-c automatically implement ON-d retrieval and display XML declaration OFF-e display
Problem: when using an implicit cursor like select into from tablename, if no data is found, an error in the ora-01403 is reported. Each time an explicit cursor is used, it is very troublesome to open the value. An experienced instructor suggested using aggregate functions like max min to avoid exceptions caused by select into and the trouble of using cursors each time.
Efficiency and feasibility tests:
① Temporary table
Create table edu. TEST(ID NUMBER NULL)TABLESPACE EDUCATIONNOLOGGINGPCTFREE
PL/SQL exceptions
The pre-defined exceptions and codes of PL/SQL are as follows:Exception Oracle error sqlcode Value MeaningAccess_into_null ORA-06530-6530 the referenced object is assigned directly to the object without InitializationCase_not_found ORA-06592-6592 if no case in the when clause contains no required branch and no else clauseCollection_is_null ORA-06531-6531 set element (nested table or varray) must be initialized first, if not, this err
Question:
Catch an error with Zero Divisor ("ORA-01476: divisor is equal to zero") and show "bad division" in this case"All other exceptions must be transmitted to the call block intact.In other words, if I add the following exception handling section and then execute the followingCodeBlock:
Begin plch_proc (0); plch_proc (-1); Exception when others then dbms_output.put_line ('all handled '); end ;/
Then I should see the following output on the screen:
Bad DivisionAll handled
(A) except
Description
Default Settings
-a
display SQLCA
OFF
-C
Auto-submit
on /tr>
-e
display sqlcode/sqlstate
OFF
-F
read from input file
off
-l
log Record command in history file
OFF
-n
remove newline characters
OFF
-o
show output
.
SQLCODE function can get the Exception Code of the last exception, SQLERRM: exception message
Declaremyexception exception; -- declare a naming exception v_row Sys_ACC_User % RowType; Pragma EXCEPTION_INIT (myexception,-20002 ); -- bind a naming exception and an exception code to begin select * into v_row from Sys_ACC_User where rownum = 1; raise myexception; -- manually throw an exception RAISE_APPLICATION_ERROR (-20001, ', which is an anonymous ex
';
Num: = num + 1; lc: = ' address ';
Num: = num + 1; n: = 10/0; insert into dept values (no, nm, lc );
Num: = num + 1;
Commit; exception
-- Custom exception
When e1 then
Dbms_output.put_line ('Number cannot be negative number ');
-- The data type is incorrect.
When value_error then
If num = 0 then
Dbms_output.put_line ('wrong numbered data type ');
Elsif num = 1 then
Dbms_output.put_line ('name data type incorrect ');
Elsif num = 2 then
Dbms_output.put_line ('address data type incorrect ');
En
of more than 5 to a varchar2 (5) field.
37. sqlcode and sqlerrmSqlcode contains the error status of the currently executed Oracle PL/SQL statement. If the SQL statement is correct, the sqlcode is 0;Sqlerrm includes sqlcode-related error messages. If the SQL statement is successfully executed, sqlcode is 0 and sqlerrm
How to Use the Loop Structure in SQL
The for, loop, while, repeat is an internal loop control of UDB/400, used to traverse each row of records that meet the conditions in the table.
For example:Objective: To update the employee database and increase the salary of all Beijing employees by 10%
Example 1: Use a For Loop--------------------------------------------Create procedure qgpl/test_forLanguage SQLBeginFor each_record--- Cur01 cursor------ Select * from code, salary, city from employee whe
Tags: res mysq def database fetchall encoding close resultset commPython2
can be used MySQLdb
The code is as followsclasssqlObject):def __init__( Self):Try: Self. conn=MySQLdb.Connect(Host=DB_IP, user=Db_user, passwd=Db_password, DB=Db_name,) Self. Conn.set_character_set (' UTF8 ') Self. cur= Self. Conn.cursor () Self. Cur.execute (' SET NAMES utf8; ') Self. Cur.execute (' Set CHARACTER set UTF8; ') Self. Cur.execute (' SET Character_set_connection=utf8; ')except Exception asE:RaiseE# Re
functionThe function Sqlcode is used to obtain the Oracle error number, while SQLERRM is used to obtain the error message associated with it.You can use Raise_application_error custom error numbers and error messages in stored procedures, functions, and packages.5.1 Sqlcode and SQLERRMDeclareV_ename Emp.ename%type;--V_code VARCHAR2 (100);--V_ERRM VARCHAR2 (100);BeginSelect Ename to V_ename from EMP where e
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.