Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database 函数,如果Oracle中的行值为空,则打印输入_Database_Oracle_Plsql - Fatal编程技术网

Database 函数,如果Oracle中的行值为空,则打印输入

Database 函数,如果Oracle中的行值为空,则打印输入,database,oracle,plsql,Database,Oracle,Plsql,我有一个名为CustomerDetails的表: 删除键|替换键 CID0001 | CUSTID01 CID0002 | CUSTID02 CID0003 |空 当给函数的输入为CID0001、CID0003时 输出应该是CUSTID01,CID0003 由于CID001替换为CUSTID01,且CID0003为空,因此它应返回输入值 如何在plsql中编写具有多个输入值的函数。删除并替换输入的客户ID时,应返回替换的客户ID。 如果未替换,则ReplacedKey为NULL,则应打印输入值

我有一个名为CustomerDetails的表:

删除键|替换键

CID0001 | CUSTID01

CID0002 | CUSTID02

CID0003 |空

当给函数的输入为CID0001、CID0003时

输出应该是CUSTID01,CID0003

由于CID001替换为CUSTID01,且CID0003为空,因此它应返回输入值

如何在plsql中编写具有多个输入值的函数。删除并替换输入的客户ID时,应返回替换的客户ID。 如果未替换,则ReplacedKey为NULL,则应打印输入值

我的代码:没有输入。我应该如何为其添加输入值

create or replace function ChangeList
as
cursor c1
select replaced ReplacedKey.CustomerDetails%type
deleted DeletKey.CustomerDetails%type
from CustomerDetails;
begin
  open c1;
   loop ``
     if ReplacedKey is null
     then
     dbms_output.put_line('DeletedKey' ||deleted);
     else
     dbms_output.put_line('ReplacedKey'||replaced);
     end if;
   end loop;
 close c1:
end;
prg的输入-无

prg的输出-DelettedKey CID0003 替换密钥CUSTID01

我应该给出的输入:CID0001 CID0003

我需要的输出:CUSTID01
CID0003

您只需要一个nvl功能

select NVL(ReplacedKey,DELETKEY) from table

带参数的函数:

create or replace function ChangeList(p_cid varchar2) return varchar2
as
  ret varchar2;
begin 
  select nvl(ReplacedKey, p_cid) 
  into ret
  from CustomerDetails
  where DeletKey = p_cid;

  return ret;
exception when no_data_found then return 'no data found';
end;

你有什么特别的问题?@eviletech实际上我写了一个带有光标的函数,但它不起作用。我的另一个问题是没有一个输入。因为我给出了输入的数量。我不知道如何给函数输入!对不起,如果这个问题很傻的话。我是PLSql的初学者,查找COALESCE、NVL、NVL2函数,它们应该有助于解决您的任务。创建或替换函数更改列表x varchar2