简体   繁体   English

Oracle Apex:成功但编译错误

[英]Oracle Apex: Success With compilation error

I'm trying to create a procedure named "Greetings" in the oracle apex.我正在尝试在 oracle 顶点中创建一个名为“Greetings”的过程。 The Procedure Greetings runs with some error throwing up called "Success with compilation error".程序问候运行时抛出一些错误,称为“编译错误成功”。 Is there anything wrong with my below code.我下面的代码有什么问题吗?

Code:代码:

create table tb_Animals (
    txt_Name varchar(20) Primary Key,
    int_Weight number
);

insert into tb_Animals values ('Dog',30);
insert into tb_Animals values ('Cat',15);

CREATE OR REPLACE PROCEDURE greetings 
AS 
BEGIN 
   select * from tb_Animals;
END;

In PL/SQL, you have to insert those values into something, usually a variable, However, if you're selecting the whole table contents, then it has to be something else;在 PL/SQL 中,您必须将这些值插入到某个东西中,通常是一个变量,但是,如果您要选择整个表格内容,那么它必须是其他东西; one option might be a refcursor.一个选项可能是一个参考。 For example:例如:

SQL> CREATE OR REPLACE PROCEDURE greetings
  2  AS
  3    rc sys_refcursor;
  4  BEGIN
  5    open rc for
  6     select * from tb_Animals;
  7  END;
  8  /

Procedure created.

SQL>

It is now correct as far as compilation is concerned, but - actual "solution" depends on what you really want to do.编译而言,它现在是正确的,但是 - 实际的“解决方案”取决于您真正想要做什么。

Two problems I see here:我在这里看到两个问题:

  1. The code you provided is a SQL script that will create the procedure, not run the procedure.您提供的代码是 SQL 脚本,它将创建程序,而不是运行程序。 The error is telling you that the procedure has been created, but that it has an error.该错误告诉您该过程已创建,但它有一个错误。 You can see the precise error by entering "SHOW ERRORS" at the sqlplus prompt after the create command completes.创建命令完成后,您可以通过在 sqlplus 提示符下输入“SHOW ERRORS”来查看确切的错误。
  2. The problem with the procedure itself is that you have to do something with the data you've selected.该过程本身的问题是您必须对您选择的数据一些事情。 It needs to be processed into variables, or used in a for/next loop for some purpose.它需要被处理成变量,或者出于某种目的在 for/next 循环中使用。 Simply selecting data into nothing won't work - PL/SQL is a programming language, not a scripting language.简单地选择数据是行不通的——PL/SQL 是一种编程语言,而不是脚本语言。 See here for a beginner's guide: https://oracle-base.com/articles/misc/introduction-to-plsql .请参阅此处获取初学者指南: https://oracle-base.com/articles/misc/introduction-to-plsql I can't offer any more specific guidance than that since you've not provided any info on what your procedure is actually trying to do.我无法提供比这更具体的指导,因为您没有提供任何有关您的程序实际尝试做什么的信息。

If you just want your script to return the data you just inserted into the table as a confirmation, just run the select statement without the procedural stuff, like this (and don't forget to commit your changes:):如果您只是希望您的脚本返回您刚刚插入表中的数据作为确认,只需运行 select 语句而不使用程序内容,就像这样(并且不要忘记提交您的更改:):

create table tb_Animals (
    txt_Name varchar(20) Primary Key,
    int_Weight number
);

insert into tb_Animals values ('Dog',30);
insert into tb_Animals values ('Cat',15);
commit;

select * from tb_Animals;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM