2017-11-19 17 views
-2

cx_Oracle.DatabaseError:ORA-00984:列ここPythonのデータベース・エラー(列ここでは使用できません)

cur.execute(挿入...)許可されていませんが、ここで

を許可されていない列のエラーを示しています
import cx_Oracle 

class Student: 
    def __init__(self,studentname,studentperformance): 

     connection = cx_Oracle.connect('saif/saif') 
     cur = connection.cursor() 

     cur.execute('create table student (studentrollno number(10),studentname varchar2(20),studenttype varchar2(20),studentperformance number(5,2),category varchar2(20),bookbank number(1))') 

     self.rollno = 171641000 
     self.studentname = studentname 
     self.studentperformance = studentperformance 
     # Line below is showing database error 
     cur.execute('insert into student(studentrollno,studentname,studentperformance) values(self.rollno,self.studentname,self.studentperformance)') 

s = Student("saif",75) 
+2

のいくつかを見るバインド変数を使用します。 – MikaS

+0

に質問が追加されました – saif

+0

まだ質問はありません、ただエラーです。 –

答えて

0

この行は、SQL文でPythonの変数self.rollnoなどを使用しようとします:

cur.execute('insert into student(studentrollno,studentname,studentperformance) values(self.rollno,self.studentname,self.studentperformance)') 

しかし、彼らはしているので、内部の引用しますPythonの値は代用されません。文字列はそのままデータベースに送られますが、理解できません。

は、以下の各変数のテキストで使用されて :bvidのようなプレースホルダは、あなたが質問をされていません examples例えば:

sql = 'select * from SampleQueryTab where id = :bvid' 

print("Query results with id = 4") 
for row in cursor.execute(sql, bvid = 4): 
    print(row) 
print()