Jython zxJDBC / Python cx_oracle 调用 oracle 存储过程时参数数量或类型错误

发布于 2024-12-21 21:40:46 字数 2599 浏览 1 评论 0原文

尝试制作一个 django 测试应用程序,它将使用存储的 Oracle 过程来插入/获取数据。

将 jython 与 zxJDBC 一起使用,但同样的错误也适用于 python 和 cx_oracle。

这里是一些代码片段:

models.py

from django.db import models
from django.db import connection

class ALEX_TEST_PKG():
    def get_data(self, inparam1):
        cursor = connection.cursor()
        ret = cursor.callproc("ALEX_TEST_PKG.test0", inparam1)
        cursor.close
        return ret

views.py

class TestForm(forms.Form):
    inparam1 = forms.CharField(max_length=500)


def message(request):
    if request.method == 'POST':
        form = TestForm(request.POST)
    else:
        form = TestForm()
    if form.is_valid():
        my_util = ALEX_TEST_PKG()
        ret = my_util.get_data(request.POST['inparam1'])
        return HttpResponse(ret)
    return render_to_response('form.html', {'form':form}, context_instance=RequestContext(request))

oracle 的程序:

CREATE OR REPLACE PACKAGE BODY ALEX.alex_test_pkg
IS
   PROCEDURE test0 (inparam1 IN integer)
   IS
   BEGIN
      insert into alex_debug(col1) values(inparam1); 
   END test0;
END alex_test_pkg;
/

Django 错误日志:

Environment:


Request Method: POST
Request URL: http://localhost:8000/form/

Django Version: 1.3.1
Python Version: 2.7.0
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'dbtest']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "C:\Python27\lib\site-packages\django-1.3.1-py2.7.egg\django\core\handlers\base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "E:\WatchTower\workspace3\erwtwe\erwtwe\dbtest\views.py" in message
  19.         ret = my_util.get_data(request.POST['inparam1'])
File "E:\WatchTower\workspace3\erwtwe\erwtwe\dbtest\models.py" in get_data
  7.         ret = cursor.callproc("ALEX_TEST_PKG.test0", inparam1)

Exception Type: DatabaseError at /form/
Exception Value: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'TEST0'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

任何帮助都会被采纳。我已经为此伤透了三天了。

Trying to make a django test application which will use stored oracle's procedures to insert/get data.

Using jython with zxJDBC but same error applies with python and cx_oracle too.

here is some code snipets:

models.py

from django.db import models
from django.db import connection

class ALEX_TEST_PKG():
    def get_data(self, inparam1):
        cursor = connection.cursor()
        ret = cursor.callproc("ALEX_TEST_PKG.test0", inparam1)
        cursor.close
        return ret

views.py

class TestForm(forms.Form):
    inparam1 = forms.CharField(max_length=500)


def message(request):
    if request.method == 'POST':
        form = TestForm(request.POST)
    else:
        form = TestForm()
    if form.is_valid():
        my_util = ALEX_TEST_PKG()
        ret = my_util.get_data(request.POST['inparam1'])
        return HttpResponse(ret)
    return render_to_response('form.html', {'form':form}, context_instance=RequestContext(request))

oracle's procedures:

CREATE OR REPLACE PACKAGE BODY ALEX.alex_test_pkg
IS
   PROCEDURE test0 (inparam1 IN integer)
   IS
   BEGIN
      insert into alex_debug(col1) values(inparam1); 
   END test0;
END alex_test_pkg;
/

Django error log:

Environment:


Request Method: POST
Request URL: http://localhost:8000/form/

Django Version: 1.3.1
Python Version: 2.7.0
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'dbtest']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "C:\Python27\lib\site-packages\django-1.3.1-py2.7.egg\django\core\handlers\base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "E:\WatchTower\workspace3\erwtwe\erwtwe\dbtest\views.py" in message
  19.         ret = my_util.get_data(request.POST['inparam1'])
File "E:\WatchTower\workspace3\erwtwe\erwtwe\dbtest\models.py" in get_data
  7.         ret = cursor.callproc("ALEX_TEST_PKG.test0", inparam1)

Exception Type: DatabaseError at /form/
Exception Value: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'TEST0'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

Any help is appriciated. breaking my head with this for 3 days already.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

失与倦" 2024-12-28 21:40:47

您正在从 request.POST 传递值,该值始终是一个字符串,但您的存储过程需要一个整数。

请改用 form.cleaned_data['inparam1'] - 表单会将其转换为正确的类型,即整数。

You're passing the value from request.POST, where it's always a string, but your stored procedure is expecting an integer.

Use form.cleaned_data['inparam1'] instead - the form will have converted it to the proper type, ie an integer.

混浊又暗下来 2024-12-28 21:40:47

callproc 的参数预计通过列表传入。您似乎正在传递一个字符串。我的即兴猜测是 Django 或 cx_Oracle 正在将该字符串解释为序列并将一整串 1 字符字符串传递给 Oracle。

[inparam1] 而不是仅将 inparam1 传递给cursor.callproc。

The parameters to callproc are expected to be passed in via a list. You appear to be passing in a string. My off-hand guess is that Django or cx_Oracle is interpreting that string as a sequence and passing a whole series of 1-character strings to Oracle.

Pass [inparam1] instead of just inparam1 to cursor.callproc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文