#!d:/python/bin/python__author__ = ' Stone ' #引入oracle支持包import cx_oracleimport tracebackfrom pip.backwardcompat import raw_input# Defining Functions #+++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++def querysal (conn, empnum): cur= Conn.cursor () #执行语句 cur.prepare (' select * from Emp where empno = to_number (: ID) ') #传递绑定变量到对应的语句 cur.execute (none, {' id ': empnum}) #print (cur) # Puts all the selected rows into Res res = cur.fetchall () # print ( Len (res)) #迭代打印出查询到的内容 for r in res: print ("Name:" +str (r[1]) + " Work No.:" +str (r[0]) + " Salary:" +str (r[5]) + " Monthly bonus: "+str (R[6]) +" ") &Nbsp; if (Len (res) ==0): cur.close () return false cur.close () return true#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++conn= Cx_oracle.connect (' SCOTT/[EMAIL PROTECTED]/ORCL ') while (1): empnum=raw_input (" Please data your work number "0: Exit": "). Strip (" \ n ") if (Empnum.isdigit ()): #如果输入值为数字, execute program if (empnum is not "0"): #如果输入值不为0, execute program if (Querysal (Conn,empnum)): #执行查询程序 continue# execution successfully continued circulation else: &nBsp; print ("Work number does not exist") #执行失败时提示工号不存在 else: #输入结果为0, exiting the program break #跳出循环, and end script else: #如果输入不为数字, you are prompted to enter a number and continue to loop print ("Please enter four digit number") continueprint ("End of Script") Conn.close ()
The Loop and Control section is primarily concerned with the use of if elif else and while. Compare the previous program, add, and more control to prevent the exception from appearing. Because the Empno field is a number type, adding control is primarily to prevent the input of character types, which causes the program to fail.
Also in Python, you no longer use (), [],{} to divide the level of the statement, but use tab (or four spaces) to control the structure of the program.
Example execution
Logic
Enter the employee's employee number and query for the corresponding salary and bonus information. Numeric string with a four-digit employee number.
Mode one, call the system default Python
650) this.width=650; "title=" 10.png "alt=" wkiom1tcabnaysahaad4cfxq-di215.jpg "src=" http://s3.51cto.com/wyfs02/M01/ 59/b6/wkiom1tcabnaysahaad4cfxq-di215.jpg "/>
Mode two, run the file using the Python file location specified in the Python file
650) this.width=650; "title=" Goose Goose. png "alt=" wkiol1tca4uxnae7aadhiqxt9gs317.jpg "src=" http://s3.51cto.com/wyfs02/ M02/59/b3/wkiol1tca4uxnae7aadhiqxt9gs317.jpg "/>
Perl Link Oracle Database Learning "one": loop control