1

I am trying to take a picture from URL and insert it on a table. My code as follows:

    pic = Image.open(urllib.request.urlopen( picurl ))
    stream = io.BytesIO()
    pic.save(stream, format="PNG")
    pichex = stream.getvalue()
    cursor.execute( "INSERT INTO GENELOC( GENE_CODE, CYT_LOC , CYT_POS , CHRM_CODE , CHRM_ARM_CODE , BP_START , BP_END , GENE_PICT ) VALUES( :1 , :2 , :3 , :4 , :5 , :6 , :7 , utl_raw.cast_to_raw(:8) )",(genecode, cytloc, cytpos, chrmcode, chrmarmcode, bpst, bpend, pichex ))
    con.commit()

and when I try this I get this error message:

cx_Oracle.DatabaseError: ORA-01461: can bind a LONG value only for insert into a LONG column

GENE_PICT column is a BLOB column. Thanks for any help.

5
  • what about the other columns and their types? What is the structure of your table - what are the values of your variables? You should provide an minimal verifiable example .. stackoverflow.com/help/mcve Commented Oct 18, 2018 at 17:34
  • @Plirkee There is no problem about other columns. I tried inserting "abc" instead of pichex, and it works. The problem is only about GENE_PICT column. Commented Oct 18, 2018 at 17:52
  • 1
    Have you tried just not using UTL_RAW.CAST_TO_RAW? See e.g. stackoverflow.com/questions/50679128/… Commented Oct 18, 2018 at 18:27
  • I think the error is CAST_TO_RAW complaining that its argument is a BLOB, not a VARCHAR2. Commented Oct 18, 2018 at 18:29
  • @kfinity Yes it worked finally. Thanks. Commented Oct 18, 2018 at 18:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.