CREATE OR REPLACE PROCEDURE SYSTEM.tiii IS
v_full_name VARCHAR2(500);
sal varchar(200);
jobid varchar(100);
cpct varchar(50);
mgid varchar(25);
did varchar(20);
cid varchar(20);
rid varchar(20);
lid varchar(20);
BEGIN
select HR.EMPLOYEES.FIRST_NAME||' '||HR.EMPLOYEES.LAST_NAME AS
Full_Name,HR.EMPLOYEES.SALARY as sal,HR.EMPLOYEES.JOB_ID as ji,
HR.EMPLOYEES.COMMISSION_PCT as cmpct,HR.EMPLOYEES.MANAGER_ID as
mgid,HR.EMPLOYEES.DEPARTMENT_ID as dep,HR.COUNTRIES_EXTERNAL.COUNTRY_ID as
country,HR.DW_REGION.R_ID as region,
HR.LOCATIONS.LOCATION_ID as loc
into v_full_name,sal,jobid,cpct,mgid,did,cid,rid,lid
from HR.EMPLOYEES
join HR.DEPARTMENTS ON
HR.EMPLOYEES.DEPARTMENT_ID=HR.DEPARTMENTS.DEPARTMENT_ID
join HR.LOCATIONS ON HR.DEPARTMENTS.LOCATION_ID=HR.LOCATIONS.LOCATION_ID
join HR.COUNTRIES_EXTERNAL ON HR.LOCATIONS.COUNTRY_ID=HR.COUNTRIES_EXTERNAL.COUNTRY_ID
join HR.DW_REGION ON HR.COUNTRIES_EXTERNAL.REGION_ID=HR.DW_REGION.R_ID
where HR.COUNTRIES_EXTERNAL.COUNTRY_ID='US'
AND trunc(HR.EMPLOYEES.HIRE_DATE) BETWEEN TO_DATE('16/08/2002','DD/MM/YYYY') AND
TO_DATE('07/12/2007','DD/MM/YYYY');
END tiii;
/
正如在注释中已经提到的,不要将包添加到系统或SYS模式中!
此外,只有从查询中只收到一行,才能导入变量。因此,您可以保证查询永远不会返回多行,或者需要更改获取数据的方式。例如,使用一条记录,然后将其大容量收集到该记录的表中:
CREATE OR REPLACE PROCEDURE <<YOUR_SCHEMA>>.tiii IS
TYPE MyResultsRec IS RECORD(
v_full_name VARCHAR2(500),
sal varchar(200),
jobid varchar(100),
cpct varchar(50),
mgid varchar(25),
did varchar(20),
cid varchar(20),
rid varchar(20),
lid varchar(20)
);
TYPE MyResultsTab IS TABLE OF MyResultsRec;
t_my_results MyResultsTab;
BEGIN
SELECT HR.EMPLOYEES.FIRST_NAME||' '||HR.EMPLOYEES.LAST_NAME AS Full_Name,
HR.EMPLOYEES.SALARY as sal,
HR.EMPLOYEES.JOB_ID as ji,
HR.EMPLOYEES.COMMISSION_PCT as cmpct,
HR.EMPLOYEES.MANAGER_ID as mgid,
HR.EMPLOYEES.DEPARTMENT_ID as dep,
HR.COUNTRIES_EXTERNAL.COUNTRY_ID as country,
HR.DW_REGION.R_ID as region,
HR.LOCATIONS.LOCATION_ID as loc
BULK COLLECT INTO t_my_results
FROM HR.EMPLOYEES
INNER JOIN HR.DEPARTMENTS ON HR.EMPLOYEES.DEPARTMENT_ID=HR.DEPARTMENTS.DEPARTMENT_ID
INNER JOIN HR.LOCATIONS ON HR.DEPARTMENTS.LOCATION_ID=HR.LOCATIONS.LOCATION_ID
INNER JOIN HR.COUNTRIES_EXTERNAL ON HR.LOCATIONS.COUNTRY_ID=HR.COUNTRIES_EXTERNAL.COUNTRY_ID
INNER JOIN HR.DW_REGION ON HR.COUNTRIES_EXTERNAL.REGION_ID=HR.DW_REGION.R_ID
WHERE HR.COUNTRIES_EXTERNAL.COUNTRY_ID='US'
AND trunc(HR.EMPLOYEES.HIRE_DATE) BETWEEN TO_DATE('16/08/2002','DD/MM/YYYY')
AND TO_DATE('07/12/2007','DD/MM/YYYY');
END tiii;
/
另一种方法是创建一个游标,然后在结果上循环:
CREATE OR REPLACE PROCEDURE <<YOUR_SCHEMA>>.tiii IS
BEGIN
FOR r_results IN (
SELECT HR.EMPLOYEES.FIRST_NAME||' '||HR.EMPLOYEES.LAST_NAME AS Full_Name,
HR.EMPLOYEES.SALARY as sal,
HR.EMPLOYEES.JOB_ID as ji,
HR.EMPLOYEES.COMMISSION_PCT as cmpct,
HR.EMPLOYEES.MANAGER_ID as mgid,
HR.EMPLOYEES.DEPARTMENT_ID as dep,
HR.COUNTRIES_EXTERNAL.COUNTRY_ID as country,
HR.DW_REGION.R_ID as region,
HR.LOCATIONS.LOCATION_ID as loc
FROM HR.EMPLOYEES
INNER JOIN HR.DEPARTMENTS ON HR.EMPLOYEES.DEPARTMENT_ID=HR.DEPARTMENTS.DEPARTMENT_ID
INNER JOIN HR.LOCATIONS ON HR.DEPARTMENTS.LOCATION_ID=HR.LOCATIONS.LOCATION_ID
INNER JOIN HR.COUNTRIES_EXTERNAL ON HR.LOCATIONS.COUNTRY_ID=HR.COUNTRIES_EXTERNAL.COUNTRY_ID
INNER JOIN HR.DW_REGION ON HR.COUNTRIES_EXTERNAL.REGION_ID=HR.DW_REGION.R_ID
WHERE HR.COUNTRIES_EXTERNAL.COUNTRY_ID='US'
AND trunc(HR.EMPLOYEES.HIRE_DATE) BETWEEN TO_DATE('16/08/2002','DD/MM/YYYY')
AND TO_DATE('07/12/2007','DD/MM/YYYY')
LOOP
-- do something here
-- access your results like r_results.full_name
END LOOP;
END tiii;
/
ORA-06512:在“sys.dbms_sql”处,第1721行 我确信这个函数的结果只有一行,我不想使用。
在第1行声明 * 错误: ORA-01422:精确提取返回的行数超过请求的行数 ORA-06512:在第11行 这是我的代码。
剧本: 新的SQL和PL/SQL,所以我将感谢任何帮助。
Select语句在Resault中返回多行。是否可以用此函数获得resault中的所有行? ORA-01422:精确提取返回的行数多于请求的行数
问题内容: 我有个问题。我已经在过去的3个小时中一直试图弄清楚这一点,但是我不知道为什么这没有按照我的预期工作。请知道我还是Java语言的新手,因此,如果有任何明显的内容,我深表歉意。 但是,通过此代码,我试图从Twitter获取承载令牌,并返回2个完全不同的东西。 当我获得预期的输出时: 但是,如果I ,我将以JSON形式获取http请求。我在下面粘贴了我的代码,希望有人能够提供帮助。 问题答案