Skip to Main Content
  • Questions
  • diff between AS and IS in Subprogram syntax

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Santhosh.

Asked: August 18, 2016 - 5:18 am UTC

Last updated: November 08, 2016 - 10:35 am UTC

Version: 11g

Viewed 1000+ times

You Asked

IN The Syntax of Create procedure and function we have two keywords IS,AS what is the difference betwwen them how to use them.Belo I given A link

https://livesql.oracle.com/apex/livesql/s/dqk6ejx3lpdaslymswdqfk347

By using is and as i can create sub programs.

and Chris said...

For most purposes there is no difference. There are a few cases where it does matter though.

In the "must be is corner", we have:

Explicit cursors

declare
  cursor c as select * from dual;
begin
  null;
end;
/ 

PLS-00103: Encountered the symbol "AS" when expecting one of the following:


PL/SQL array types

SQL> declare
  2    type typ as table of pls_integer;
  3  begin
  4    null;
  5  end;
  6  /
  type typ as table of pls_integer;
              *
ERROR at line 2:
ORA-06550: line 2, column 15:
PLS-00103: Encountered the symbol "TABLE" when expecting one of the following:
object opaque


Though this only applies in PL/SQL. SQL nested tables can use either:

SQL> create or replace type typ as object (x int);
  2  /

Type created.

SQL> create or replace type typ_arr as table of typ;
  2  /

Type created.

SQL> create or replace type typ_arr2 is table of typ;
  2  /

Type created.


-----

And in the "must be as" corner we have:

Create table as select

It's implied in the name - you can't "create table is select"!

SQL> create table t is
  2    select rownum x from dual;
create table t is
               *
ERROR at line 1:
ORA-00922: missing or invalid option


Materialized Views

SQL> create materialized view mv is
  2    select 1 n from dual;
create materialized view mv is
                            *
ERROR at line 1:
ORA-00905: missing keyword


Standard Views

SQL> create or replace view v is
  2    select 1 n from dual;
create or replace view v is
                         *
ERROR at line 1:
ORA-00905: missing keyword


Directories

SQL> create or replace directory dir is '/tmp';
create or replace directory dir is '/tmp'
                                *
ERROR at line 1:
ORA-00905: missing keyword


PS - thanks for using LiveSQL!

Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

santhosh, November 07, 2016 - 5:00 am UTC

So Should we use only as keyword when CREATE or REPLACE Text not present?
Connor McDonald
November 07, 2016 - 11:27 am UTC

If it does not return an error, use it.

If it does return an error, change it.

:-)

Norm

A reader, November 07, 2016 - 6:10 pm UTC

So when we CREATE it's AS all the way
when we DECLARE it's IS

(Even though create is works, but not declare as.)
Hence rule above is good? ????
Chris Saxon
November 08, 2016 - 10:35 am UTC

Yep, you can use "create ... is" for PL/SQL objects. I'm not aware of somewhere you can use "as" in a declare.

AS vs. IS

Praveen Ray, November 08, 2016 - 9:52 am UTC

Technically speaking, there is no difference unless it's been restricted by the syntax. If the syntax supports both then you can use them interchangeably.
Chris Saxon
November 08, 2016 - 10:28 am UTC

Yes, that's what we said!

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library