简体   繁体   English

Oracle 开始预计得到创建

[英]Oracle begin expected got create

I'm writing a PL/SQL program, I've created a procedure and the syntax is correct.我正在编写一个 PL/SQL 程序,我已经创建了一个过程并且语法是正确的。 Running this on DataGrip.在 DataGrip 上运行它。 ` `

declare
create or replace procedure salutation(x OUT number) is begin
    x:= x*10;
end salutation;
begin
    SYS.DBMS_OUTPUT.PUT_LINE('hello');
end;

` I get error messages when I execute the code: BEGIN expected, got 'create'. ` 我在执行代码时收到错误消息:BEGIN expected, got 'create'。 [2022-12-04 23:58:09] [65000][6550] [2022-12-04 23:58:09] ORA-06550: line 1, column 7: [2022-12-04 23:58:09] PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: [2022-12-04 23:58:09] begin function pragma procedure subtype type [2022-12-04 23:58:09] current cursor delete [2022-12-04 23:58:09] exists prior [2022-12-04 23:58:09] [65000][6550] [2022-12-04 23:58:09] ORA-06550:第 1 行,第 7 列:[2022-12-04 23:58: 09] PLS-00103:期望以下之一时遇到符号“文件结束”:[2022-12-04 23:58:09] begin function pragma procedure subtype type [2022-12-04 23:58 :09] 当前 cursor 删除 [2022-12-04 23:58:09] 之前存在

I don't think there's a problem with the syntax.我不认为语法有问题。 Also why does the DataGrip not allow DBMS_OUTPUT.PUT_LINE without the SYS.还有为什么 DataGrip 不允许没有 SYS 的 DBMS_OUTPUT.PUT_LINE。 ? even though I've enabled the DBMSOUTPUT.即使我启用了 DBMSOUTPUT。

You can't have static DDL statements (like create procedure ) within PL/SQL (you'd need to use dynamic SQL, but it's very rarely necessary anyway).你不能在 PL/SQL 中有 static DDL 语句(比如create procedure )(你需要使用动态 SQL,但它很少有必要)。

But if you're trying to declare a local procedure within your anonymous block - not create a permanent, stored procedure, then you don't need the create part:但是如果你试图在你的匿名块中声明一个本地过程 - 而不是创建一个永久的存储过程,那么你不需要create部分:

declare
  y number := 42;

  procedure salutation(x IN OUT number) is begin
    x:= x*10;
  end salutation;
begin
    SYS.DBMS_OUTPUT.PUT_LINE('hello');
    -- call salutation here if you want...
    salutation(y);
    dbms_output.put_line(to_char(y));
end;
/
1 rows affected

dbms_output:
hello
420

fiddle小提琴

Note that I changed the argument to IN OUT - otherwise it would always be reset to null.请注意,我将参数更改为IN OUT - 否则它将始终重置为 null。

If you want to create a permanent stored procedure then do that separately, before you try to run your anonymous block:如果你想创建一个永久存储过程,那么在你尝试运行你的匿名块之前单独做:

create or replace procedure salutation(x IN OUT number) is begin
  x:= x*10;
end salutation;
/
declare
  y number := 42;
begin
    SYS.DBMS_OUTPUT.PUT_LINE('hello');
    -- call salutation here if you want...
    salutation(y);
    dbms_output.put_line(to_char(y));
end;
/
1 rows affected

dbms_output:
hello
420

fiddle小提琴

Also why does the DataGrip not allow DBMS_OUTPUT.PUT_LINE without the SYS.还有为什么 DataGrip 不允许没有 SYS 的 DBMS_OUTPUT.PUT_LINE。 ?

That suggests your database is missing a public synonym for the package;这表明您的数据库缺少 package 的公共同义词; not a DataGrip thing, you'd see the same behaviour using any client.不是 DataGrip 的东西,你会看到使用任何客户端的相同行为。 You'd need to ask your DBA why it's missing and whether it can be reinstated.您需要询问您的 DBA 为什么它丢失以及它是否可以恢复。 (I haven't included the schema prefix in the extra calls I added, but if those don't work for you then you'll need to add it.) (我没有在我添加的额外调用中包含模式前缀,但如果这些不适合你,那么你需要添加它。)

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

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