Thread: [cx-oracle-users] INSERT INTO -- cx_Oracle
Brought to you by:
atuining
From: broletto <te...@br...> - 2012-04-28 21:44:04
|
Hello list, please i found someone can help me to resolve a problem between python and cx_Oracle i must insert some data inside my Oracle Express, i use python to do this. try: self.c.execute('''INSERT INTO MODELLO (title, descrizione, url, prezzo, sconto) VALUES(:1, :2, :3, :4, :5 )''', (item['title'], item['descrizione'], item['url'], item['prezzo'], item['sconto'] )) self.db.commit() except cx_Oracle.DatabaseError, exception: error, = exception print "Oracle error: ", error.message ** item are list of data when run this code i received an output error: Oracle error: ORA-01484: arrays can only be bound to PL/SQL statements thanks marco |
From: Anthony T. <ant...@gm...> - 2012-04-29 04:12:11
|
Hi, You'll have to tell us what the actual values are that you are passing. Looks like one of them is a list or tuple which cx_Oracle automatically binds to an array. Anthony On Sat, Apr 28, 2012 at 3:43 PM, broletto <te...@br...> wrote: > Hello list, > > please i found someone can help me to resolve a problem between python > and cx_Oracle > i must insert some data inside my Oracle Express, i use python to do this. > > try: > self.c.execute('''INSERT INTO MODELLO (title, > descrizione, url, prezzo, sconto) > VALUES(:1, :2, :3, :4, :5 )''', > > (item['title'], > > item['descrizione'], > > item['url'], > > item['prezzo'], > > item['sconto'] > )) > > self.db.commit() > > except cx_Oracle.DatabaseError, exception: > error, = exception > print "Oracle error: ", error.message > > ** item are list of data > when run this code i received an output error: > Oracle error: ORA-01484: arrays can only be bound to PL/SQL statements > > thanks > marco > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > cx-oracle-users mailing list > cx-...@li... > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users |
From: broletto <te...@br...> - 2012-04-29 08:02:27
|
On 29/04/2012 06:12, Anthony Tuininga wrote: > Hi, > > You'll have to tell us what the actual values are that you are > passing. Looks like one of them is a list or tuple which cx_Oracle > automatically binds to an array. > > Anthony > > On Sat, Apr 28, 2012 at 3:43 PM, broletto<te...@br...> wrote: >> Hello list, >> >> please i found someone can help me to resolve a problem between python >> and cx_Oracle >> i must insert some data inside my Oracle Express, i use python to do this. >> >> try: >> self.c.execute('''INSERT INTO MODELLO (title, >> descrizione, url, prezzo, sconto) >> VALUES(:1, :2, :3, :4, :5 )''', >> >> (item['title'], >> >> item['descrizione'], >> >> item['url'], >> >> item['prezzo'], >> >> item['sconto'] >> )) >> >> self.db.commit() >> >> except cx_Oracle.DatabaseError, exception: >> error, = exception >> print "Oracle error: ", error.message >> >> ** item are list of data >> when run this code i received an output error: >> Oracle error: ORA-01484: arrays can only be bound to PL/SQL statements >> >> thanks >> marco >> >> ------------------------------------------------------------------------------ >> Live Security Virtual Conference >> Exclusive live event will cover all the ways today's security and >> threat landscape has changed and how IT managers can respond. Discussions >> will include endpoint security, mobile security and the latest in malware >> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ >> _______________________________________________ >> cx-oracle-users mailing list >> cx-...@li... >> https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > cx-oracle-users mailing list > cx-...@li... > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > hello, thanks anthony if you want here http://pastebin.com/Yknan8dk you seen a simple example of items details i try to pass at oracle. thanks marco |
From: James C. M. <Jam...@or...> - 2012-04-29 11:40:09
|
Hi Marco, On 29/04/12 06:02 PM, broletto wrote: > On 29/04/2012 06:12, Anthony Tuininga wrote: >> Hi, >> >> You'll have to tell us what the actual values are that you are >> passing. Looks like one of them is a list or tuple which cx_Oracle >> automatically binds to an array. ... >> On Sat, Apr 28, 2012 at 3:43 PM, broletto<te...@br...> wrote: >>> Hello list, >>> >>> please i found someone can help me to resolve a problem between python >>> and cx_Oracle >>> i must insert some data inside my Oracle Express, i use python to do this. >>> -reformatted- try: self.c.execute('''INSERT INTO MODELLO (title, descrizione, url, prezzo, sconto) VALUES(:1, :2, :3, :4, :5 )''', (item['title'], item['descrizione'], item['url'], item['prezzo'], item['sconto'])) self.db.commit() except cx_Oracle.DatabaseError, exception: error, = exception print "Oracle error: ", error.message ** item are list of data >>> when run this code i received an output error: >>> Oracle error: ORA-01484: arrays can only be bound to PL/SQL statements ... > if you want here http://pastebin.com/Yknan8dk you seen a simple example > of items details i try to pass at oracle. Anthony's suggestion is correct. The example you give from the pastebin is a dict: [{"prezzo": ["\n\t\t\t\t$519.00\n\t\t\t\t\n\t\t\t", "\n\t\t\t\t$849.00\n\t\t\t\t\n\t\t\t", "\n\t\t\t\t$849.00\n\t\t\t\t\n\t\t\t", "\n\t\t\t\t$899.00\n\t\t\t\t\n\t\t\t", "\n\t\t\t\t$929.00\n\t\t\t\t\n\t\t\t", ... ... from which you're trying to pass an entire key's values. Which would normally be ok, but your keys have lists attached to them, rather than plain elements. You need to pass the element from within the dict key, eg item['prezzo'][0] While I'm thinking of it, a few comments on your dict contents: #1 Why have you embedded newline and tab characters in the elements instead of using an output format function at the point where you actually report the data and storing a number in the field? #2 I think you should store bare numbers rather than text with a dollar sign prepended. That would give you more flexibility if, for instance, you want to provide a converted price in another currency. #3 Your sconto field might be better presented as a percentage, so when the price of the item changes, your application's presentation layer can handle calculating the discount's value to the customer. Best regards, James C. McPherson (a Solaris kernel and tools engineer, NOT a DBA :>) -- Oracle http://www.jmcp.homeunix.com/blog |