如何编写具有 x 个输入参数和 x 个参数的输入/输出组合的 PL/SQL 过程 [英] How to write a PL/SQL procedure with x input parameters and input/ouput of x parameters combined

查看:74
本文介绍了如何编写具有 x 个输入参数和 x 个参数的输入/输出组合的 PL/SQL 过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须制定一个程序来自动创建一个STUDENT_ID,输入参数为姓名、姓氏、性别、日期_出生、州.

I have to make a procedure that will create me autonomously a STUDENT_ID with the input parameters as Name, Surname, Gender, Date_Birth, State.

示例:

  • 姓名:约翰
  • 姓氏:史密斯
  • 性别:男
  • 出生日期:17/05/1996
  • 州:加利福尼亚

输出:

STUDENT_ID is : JHN-STH-M-17596-CLFN

我把-"为了使它在问题中看得更清楚,但在输出中它应该是 JHNSTHM17596CLFN

我制作了 5 个单独的程序来计算姓名、姓氏等.我想编写一个程序来计算 STUDENT_ID 使用我制作的程序(按顺序),并且还有一个输入"参数和输入/输出学生"将打印"STUDENT_ID

I have made 5 separate procedures that will calculate name, surname ecc.. I want to write a procedure that will calculate the STUDENT_ID using the procedures I made (in order) , and also have an "input" parameter and input/output "student" that will "print" the STUDENT_ID

procedure  student_id     (surname in varchar2,
                           name in varchar2,
                           gender in varchar2,
                           date_birth in varchar2,
                           state in varchar2) is
begin

....


dbms_output.put_line ('Student_ID is :');

此代码是假定的"作为输入参数,不知道写对了没

推荐答案

对我来说,好像

  • 你应该转换"过程STUDENT_ID的每一部分计算成函数
    • 为什么?因为 - 就像现在一样 - 过程必须有一个 OUT 参数,以便它们可以返回它们的计算结果.那不过是一个函数

    像这样:

    function f_name (par_name in varchar2) return varchar2 is
      retval varchar2(20);
    begin
      retval := whatever code you have to find it
      return retval;
    end;
    
    function f_surname (par_surname in varchar2) return varchar2 is
      retval varchar2(20);
    begin
      retval := whatever code you have to find it
      return retval;
    end;
    
    etc.
    
    procedure student_id (par_surname in varchar2, par_name in varchar2, ...)
    is
      l_student_id varchar2(30);
    begin
      l_student_id := f_name   (par_name)    ||'-'||
                      f_surname(par_surname) ||'-'||
                      f_gender (par_gender)  ||'-'||
                      ...
                      f_state  (par_state);
                      
      dbms_output.put_line('Student_ID is: ' || l_student_id);
    end;  
    

    最后,由于所有这些函数和过程都处理相同的问题,最好将它们全部放入一个.

    Finally, as all those functions and procedure deal with the same problem, it would be nice to put them all into a package.

    这篇关于如何编写具有 x 个输入参数和 x 个参数的输入/输出组合的 PL/SQL 过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆