代码之家  ›  专栏  ›  技术社区  ›  Hamish Grubijan

如何使用Oracle SQL developer运行存储过程?

  •  19
  • Hamish Grubijan  · 技术社区  · 15 年前

    *编辑6:*

    var ret1 number
    var tran_cnt number
    var msg_cnt number
    var rc refcursor
    exec :tran_cnt := 0
    exec :msg_cnt := 123
    exec get_account(Vret_val => :ret1, Vtran_count => :tran_cnt, Vmessage_count => :msg_cnt, Vaccount_id => 1, rc1 => :rc)
    print :tran_cnt
    print :msg_cnt
    print :rc
    

    SQL开发人员使这变得非常困难/不可能?。我不在乎实用程序是否基于命令行;我只想能够快速地运行和查看它。如果它也能捕捉到错误就好了。如果能够逐渐地(以交互方式)登录,并同时指定所有内容(类似于典型的基于ftp/sftpcmd的客户端的工作方式),那就太好了。

    我的平台是windowsserver2008+Cygwin。

    编辑: 也许您知道如何使用Python编写脚本?

    在MSFT SQL server中,我可以简单地键入以下内容:

    get_user 1;
    

    login   name    
    NULL    Somename
    

    打印到输出窗口。oraclesql开发人员对此毫无帮助。我不确定如何传入1,也不确定如何查看返回的实际行/记录。

    当我打字的时候 var rc refcursor;

    An error was encountered performing the requested operation:
    
    ORA-00900: invalid SQL statement
    00900.00000 - "invalid SQL statement"
    * Cause:
    * Action:
    Vendor code 900Error at Line: 2
    

    编辑4:

    create or replace procedure get_account
    (
        Vret_val out number,
        Vtran_count in out number,
        Vmessage_count in out number,
        Vaccount_id     IN NUMBER
        , rc1 in out sys_refcursor
    )as
    begin
    ...
    

    我得到一个错误:

    Error starting at line 2 in command:
    exec :rc := get_account(1) 
    Error report:
    ORA-06550: line 1, column 24:
    PLS-00306: wrong number or types of arguments in call to 'GET_ACCOUNT'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    06550. 00000 -  "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    *Action:
    rc
    ------
    

    我是如此接近。。。请帮忙。

    我正在运行的脚本(功能相同),错误总是相同的:

    var ret1 number
    var tran_cnt number
    var msg_cnt number
    var rc refcursor
    exec :tran_cnt := 0
    exec :msg_cnt := 123
    exec get_account(Vret_val => :ret1, Vtran_count => :tran_cnt, Vmessage_count => :msg_cnt, Vaccount_id => 1, rc1 => rc)
    

    Error report:
    ORA-06550: line 1, column 134:
    PLS-00201: identifier 'RC' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    06550. 00000 -  "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    *Action:
    anonymous block completed
    anonymous block completed
    
    Error starting at line 7 in command:
    exec get_account(Vret_val => :ret1, Vtran_count => :tran_cnt, Vmessage_count => :msg_cnt, Vaccount_id => 1, rc1 => rc)
    Error report:
    ORA-06550: line 1, column 134:
    PLS-00201: identifier 'RC' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    06550. 00000 -  "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    *Action:
    anonymous block completed
    anonymous block completed
    
    Error starting at line 7 in command:
    exec get_account(Vret_val => :ret1, Vtran_count => :tran_cnt, Vmessage_count => :msg_cnt, Vaccount_id => 1, rc1 => rc)
    Error report:
    ORA-06550: line 1, column 134:
    PLS-00201: identifier 'RC' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    06550. 00000 -  "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    *Action:
    

    为什么写着第1行第134列?没有线延伸那么远。。。

    5 回复  |  直到 14 年前
        1
  •  36
  •   ruffin    13 年前

    不仅有办法做到这一点,还有不止一种方法(我承认这不是很Pythonic,但是SQL*Developer是用Java编写的)。

    我有一个签名的程序: get_maxsal_by_dept( dno number, maxsal out number) .

    . (我可以用 ctrl键 + )这将生成一个带有测试线束的弹出窗口( 注: 包含程序名称的包下面的图标;然后,当测试线束出现时,您将从包的“目标”列表中选择存储过程。)在本例中,测试线束将显示以下内容:

    DECLARE
      DNO NUMBER;
      MAXSAL NUMBER;
    BEGIN
      DNO := NULL;
    
      GET_MAXSAL_BY_DEPT(
        DNO => DNO,
        MAXSAL => MAXSAL
      );
      DBMS_OUTPUT.PUT_LINE('MAXSAL = ' || MAXSAL);
    END;
    

    我将变量DNO设置为50,然后按ok。在 运行-日志

    Connecting to the database apc.
    MAXSAL = 4500
    Process exited.
    Disconnecting from the database apc. 
    

    公平地说,对于返回Ref游标的函数,运行程序不太友好,例如: get_emps_by_dept (dno number) return sys_refcursor .

    DECLARE
      DNO NUMBER;
      v_Return sys_refcursor;
    BEGIN
      DNO := 50;
    
      v_Return := GET_EMPS_BY_DEPT(
        DNO => DNO
      );
      -- Modify the code to output the variable
      -- DBMS_OUTPUT.PUT_LINE('v_Return = ' || v_Return);
    END;
    

    DECLARE
      DNO NUMBER;
      v_Return sys_refcursor;
      v_rec emp%rowtype;
    BEGIN
      DNO := 50;
    
      v_Return := GET_EMPS_BY_DEPT(
        DNO => DNO
      );
    
      loop
        fetch v_Return into v_rec;
        exit when v_Return%notfound;
        DBMS_OUTPUT.PUT_LINE('name = ' || v_rec.ename);
      end loop;
    END;
    

    Connecting to the database apc.
    name = TRICHLER
    name = VERREYNNE
    name = FEUERSTEIN
    name = PODER
    Process exited.
    Disconnecting from the database apc. 
    

    或者我们可以使用旧的SQL SQL中的PLus命令 开发人员工作表:

    var rc refcursor 
    exec :rc := get_emps_by_dept(30) 
    print rc
    

    在这种情况下,输出出现在 脚本输出 结果 选项卡)。

    the matrix in the online documentation 更多信息。


    var rc refcursor; 选择并运行它,我得到这个 错误(GUI):“

    工作表解释SQL的方式中有一个特性或错误 Plus命令是脚本的一部分。如果我们输入一行SQL*Plus var rc refcursor 然后单击 Execute Statement (或 F9层 )工作表上有ORA-900 i、 它不是SQL。我们需要做的是点击 Run Script (或 F5级


    你的计划是 程序 有五个强制参数的签名。出现错误是因为您将其作为函数调用,并且只使用一个参数:

    exec :rc := get_account(1)
    

    var ret1 number
    var tran_cnt number
    var msg_cnt number
    var rc refcursor
    
    exec :tran_cnt := 0
    exec :msg_cnt := 123
    
    exec get_account (Vret_val => :ret1, 
                      Vtran_count => :tran_cnt, 
                      Vmessage_count => :msg_cnt, 
                      Vaccount_id   => 1,
                      rc1 => :rc )
    
    print tran_count 
    print rc
    

    也就是说,每个OUT或IN-OUT参数都需要一个变量。IN参数可以作为文本传递。前两个EXEC语句为两个IN-OUT参数赋值。第三个EXEC调用这个过程。过程不返回值(与函数不同),因此我们不使用赋值语法。最后,这个脚本显示映射到OUT参数的几个变量的值。

        2
  •  4
  •   Gary Myers    15 年前

    我不知道怎么看实际情况 返回的行/记录。

    存储过程不返回记录。它们可能有一个游标作为输出参数,它是指向select语句的指针。但它需要额外的操作才能真正从该游标带回行。

    在sqldeveloper中,可以执行返回ref游标的过程,如下所示

    var rc refcursor
    exec proc_name(:rc)
    

    print rc
    
        3
  •  3
  •   Sujee    15 年前

    我的建议是 TORA

        5
  •  0
  •   Matthew Farwell    15 年前