Question

PL/SQL insert problem

Asked by: bwetmore

Here is my script I am trying to run....
declare
begin

Insert into t3
select t1.r1,
       t1.r2,
       t1.r3,
       (Select r4 from t2 where t2.r1 = t1.r1
                          and   t2.r2 = t1.r2)
from   t1;
commit;
end;

My problem is that this runs fine in straight SQL, but does not work in PL/SQL.
I get this error...
ORA-06550: line 28, column 11: PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:     ( - + mod not null others <an identifier>    <a double-quoted delimited-identifie.....

Any ideas what I am missing, this is just a small part in a larger PL/SQL procedure.

Thanks,
Brad

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2001-09-18 at 07:55:47ID20184342
Tags

insert

,

column

,

from

,

sql

Topic

Oracle Database

Participating Experts
7
Points
200
Comments
16

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. java.sql.SQLException: ORA-06550
    Hi, I have a stored procedure in Oracle that compiles and executes correctly. When I call the same from java (jdbc thin driver) I get the following error message: java.sql.SQLException: ORA-06550: line 1, column 47: PLS-00103: Encountered the symbol "end-of-file&quo...
  2. SQL Execution Error, ORA-06550:
    Getting the following execution error SQL execution error, ORA-06550: line 1, column 7: PLS-00103: Encounter the symbol "." when expecting one of the following: begin declare exit for goto if loop mod null pragma raise return select update while <an identifier...
  3. Commit Frequency in PL/SQL
    Hello, I have a PL/SQL procedure that will open up a cursor and process records one at a time to load them into another table. I will be processing ~4,000 - 5,000 records per run. I don't want to commit each record, but I also don't want to wait until the end to commit. H...
  4. ORA-06550 in executing a pl/sql in shell
    I am executiing this shell script #!/usr/bin/ksh /usr/bin/mv C:/Inetpub/ftproot/*.*.ldssfile.* E:/errorfile /usr/bin/cp E:/errorfile/*.*.ldssfile.* E:/errorfile/errct.dat #set -x export ORACLE_SID=LDSS2 sqlplus -s ldss/bum021 2>DEVNULL <<EOF truncate table erro...
  5. ORA-06550: compilation error on a second run of a P…
    I have a DB script that builds DB schema of our product. The script should be re-runnable, so we could upgrade our schema from version to version. I have the following tables : CREATE TABLE productname.DOCUMENTS ( Id varchar2(48) NOT NULL, doc_type_id v...
  6. DAAB error System.Data.OracleClient.OracleException…
    [WebMethod(Description = "Compare PriceList")] public DataSet ComparePriceListDelete( string OldPriceList, string NewPriceList, ref string Status) { string procedureName = "init_price.PRICE_LIST_RE...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: BasharPosted on 2001-09-18 at 08:47:55ID: 6490972

I guess you should enclose the select statement used to insert data in table t3 with parantheses:

Insert into t3
 (select t1.r1,
      t1.r2,
      t1.r3,
      (Select r4 from t2 where t2.r1 = t1.r1
                         and   t2.r2 = t1.r2)
 from   t1);
commit;
end;


What release of Oracle you are using??

Regards,
Bashar.

 

by: WadhwaPosted on 2001-09-18 at 08:56:19ID: 6491003

I guess you are missing smething in your code
Here is a pl/sql which show its working
ora816 SamSQL :> @t2
ora816 SamSQL :> declare
  2  sqlstr varchar2(2000);
  3  begin
  4  sqlstr := 'insert into t1
  5      select empno,ename,(Select dname from deptdup where deptdup.deptno=empdup.deptno) newcol from empdup';
  6  execute immediate sqlstr;
  7  end;
  8  /

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.80
ora816 SamSQL :> select * from t1;

     EMPNO ENAME      NEWCOL
---------- ---------- --------------
      7369 SMITH      ACCOUNTING
      7499 ALLEN      ACCOUNTING
      7521 WARD       MANAGER
      7566 JONES      ACCOUNTING
      7654 MARTIN     ACCOUNTING
      7698 BLAKE      COMPUTER
      7782 CLARK      ACCOUNTING
      7788 SCOTT      ASSISTANT
      7839 KING       ACCOUNTING
      7844 TURNER     CLERK
      7876 ADAMS      ACCOUNTING
      7900 JAMES      CLERK
      7902 FORD       ACCOUNTING
      7934 MILLER     ACCOUNTING

14 rows selected.

 

by: bwetmorePosted on 2001-09-18 at 09:00:00ID: 6491017

I am using 8.0.5 for Win NT
The brackets did not help, I still got the same error message.

Brad

 

by: ser6398Posted on 2001-09-18 at 09:05:18ID: 6491045

Couldn't you just change your Insert statement to:

Insert into t3
select t1.r1,
      t1.r2,
      t1.r3,
      t2.r4
from   t1, t2
where t2.r1 = t1.r1
  and t2.r2 = t1.r2;

 

by: bwetmorePosted on 2001-09-18 at 09:08:00ID: 6491061

I am using 8.0.5 for Win NT
The brackets did not help, I still got the same error message.

Brad

 

by: kretzschmarPosted on 2001-09-18 at 10:13:22ID: 6491303

maybe the failure is more above in your pl/sql code

 

by: robvcPosted on 2001-09-18 at 12:33:54ID: 6491664

Brad,
PL/SQL and SQL are different.  PL/SQL is a procedural language.  Things that work in SQL don't always work in PL/SQL.  The best way I found to handle this type of problem is to create a PL/SQL Procedure and use cursors.

PROCEDURE xxx AS
CURSOR c1 IS
  select t1.r1,
      t1.r2,
      t1.r3,
      (Select r4 from t2 where t2.r1 = t1.r1
                         and   t2.r2 = t1.r2)
  from t1;
this c1%ROWTYPE
BEGIN
  OPEN c1;
  LOOP
    FETCH c1 INTO this;
      EXIT WHEN c1%NOTFOUND;  -- end of records, exit loop
     INSERT INTO t3
          VALUES (r1 = this.r1,
                  r2 = this.r2,...);
        COMMIT;
  END LOOP;
  CLOSE c1;
END;
END xxx;

Or something like this.  You can add exception handling and other checks along the way.  You can also put it in a package.  Hope it helps.
Rob

 

by: WadhwaPosted on 2001-09-18 at 13:11:18ID: 6491744

I guess that this is not a feture of oracle 8.0.5 .if you
run the below sql from sql*plus

Insert into t3
select t1.r1,
      t1.r2,
      t1.r3,
      (Select r4 from t2 where t2.r1 = t1.r1
                         and   t2.r2 = t1.r2)
from   t1;

You will get a "ORA-00936: missing expression" error . and if make a plsql and run it as a plsql program you will get a error something like this
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
( - + mod not null others <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev sum variance
cast <a string literal with character set specification>
<a number> <a single-quoted SQL string>
ORA-06550: line 4, column 62:
PLS-00103: Encountered the symbol "FROM" when expecting one of the following:
) intersect minus union

Hope this helps
Sam


 

by: markgeerPosted on 2001-09-18 at 19:09:29ID: 6492230

I think Oracle8.0.5 does not support that syntax, Oracle8i (8.1.5 or higher) does.

 

by: robvcPosted on 2001-09-18 at 19:37:00ID: 6492261

A SELECT statement cannot be used directly in a PL/SQL procedure because there is nowhere for the results to go.  It is a procedural language that requires a memory structure to store the results (i.e., SELECT INTO or CURSOR).

 

by: kretzschmarPosted on 2001-09-18 at 21:05:42ID: 6492402

its not a select its an insert and this should also work in pl/sql

meikl ;-)

 

by: robvcPosted on 2001-09-19 at 08:29:04ID: 6493902

meikl, you're right.  I forgot about the insert.  I was thinking a straight SELECT statement.  Thanks for the correction.

My preference is to always open an explicit cursor in these situations so I can adequately control the execution of the procedure.  I try to avoid the implicit cursor in formal PL/SQL code.

 

by: WadhwaPosted on 2001-09-19 at 11:03:22ID: 6494462

Hi bwetmore,

As i already commented previously  , this is not a feature of 8.0.5. you can not implement this in PL/sql with this syntax. Although you can implement  by changing the insert statment as ser6398 suggested you before.


Sam

 

by: mozartnyPosted on 2001-09-20 at 23:21:40ID: 6498962

Try the following:
declare
begin

Insert into t3
select t1.r1,
      t1.r2,
      t1.r3,
      t2.r4
      from t1, t2
      where t2.r1 = t1.r1
        and t2.r2 = t1.r2;
commit;
end;
/

 

by: ser6398Posted on 2001-09-21 at 06:54:14ID: 6499941

Hey mozartny,

I made that suggestion 3 days ago.  I suggest you read the EE guidelines on comments vs. answers: http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp

 

by: kretzschmarPosted on 2001-09-21 at 06:56:52ID: 6499947

ser6398 already commented this, mozartny

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...