sql - PL SQL Oracle PLS-00103 : Encountered the symbol “CREATE”

标签 sql oracle syntax compiler-errors pls-00103

此代码接受邮政编码,城市和州的输入,然后将其插入到创建的地址表中。在插入数据之前,它将检查邮政编码是否已在表中,如果是,则调用procedure(error)以显示错误代码。

我收到错误代码pls-00103:尝试执行该代码时遇到符号“CREATE”。到目前为止,这是我的代码。感谢您的任何提前帮助。

drop table address;

create table address(zipcode NUMBER, city varchar2(30), state varchar2(20));

create or replace procedure error as
begin
  dbms_output.put_line('Error Zip Code already found in table');
end error;

declare
 zzip number;
 ccity varchar2(30);
 sstate varchar2(30);

create or replace procedure location(p_zipcode NUMBER,
                                     p_city varchar2,
                                     p_state varchar2) is
zip address.zipcode%type;
cit address.city%type;
st address.state%type;

begin
  select count(*) from address into zip where zipcode = zip;
  if any_rows_found then 
    error;
  else
  Insert into address values(zip, cit, st);
  end if;
end location;

begin
  select &zipcode into zzip from dual;
  select &city into ccity from dual;
  select &state into sstate from dual;
  procedure location(zzip, ccity, sstate);
end;
/

最佳答案

我不确定您要做什么,但是以下内容可能更接近您的想法:

drop table address;

create table address(zipcode NUMBER, city varchar2(30), state varchar2(20));

declare
 zzip number;
 ccity varchar2(30);
 sstate varchar2(30);

 procedure error is
 begin
  dbms_output.put_line('Error Zip Code already found in table');
 end error;

 procedure location(p_zipcode NUMBER, p_city varchar2, p_state varchar2) is
  zip_count   NUMBER;
 begin
  select count(*)
    into zip_count
    from address
    where zipcode = p_zipcode;

  if zip_count > 0 then 
    error;
  else
   Insert into address
     (zipcode, city, state)
   values
     (p_zipcode, p_city, p_state);
  end if;
 end location;

begin
 select &zipcode into zzip from dual;
 select &city into ccity from dual;
 select &state into sstate from dual;

 location(zzip, ccity, sstate);
end;
/

祝你好运。

关于sql - PL SQL Oracle PLS-00103 : Encountered the symbol “CREATE” ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33622074/

相关文章:

java - 您可以从 Oracle 数据库中提取 pl/java 类文件吗?

sql - 更新插入到 oracle

c++ - 如何将指针数组分配给数组

mysql - 合并sql数据库和不合并sql数据库是否有意义?

mysql - 否定 SQL 查询

sql - MYSQL - 一起使用 AVG() 和 DISTINCT

scala - 我可以在Scala 2.8中命名一个元组(定义结构吗?)吗?

sql - Sparx EA : detect what database type currently using

sql - 日期字段文字与格式字符串不匹配

c++ - 模板化类然后重载运算符 (C++)