DBAsupport.com Forums - Powered by vBulletin
Results 1 to 7 of 7

Thread: query running at sql but not in plsql

  1. #1
    Join Date
    Jul 2000
    Location
    India
    Posts
    60

    Angry

    hi,

    assuming i have 2 tables temp1 and temp2 both having fields
    t1 & t2

    if i write a query at the sql prompt

    update temp1 a set t2 = t1*( select t2 from temp2 b where b.t1 = a.t1);

    it works properly but when i put it in a procedure

    create or replace procedure test as
    begin
    update temp1 a set t2 = t1*( select t2 from temp2 b where b.t1 = a.t1);
    end;

    it gives the foll error.
    LINE/COL ERROR
    -------- -----------------------------------------------------------------
    3/30 PLS-00103: Encountered the symbol "SELECT" when expecting one of
    the following:
    ( - + mod not null others
    avg
    count current exists max min prior sql stddev sum variance
    execute forall time timestamp interval date




    can anyone please suggest a solution

    satish

  2. #2
    Join Date
    Aug 2000
    Location
    Ny
    Posts
    105
    You can not write DML statment using sql in pl/sql, you have to use dynamic sql.

    See Oracle doc (execute immediate, dmbs_sql)

    Good luck.

  3. #3
    Join Date
    Aug 2000
    Location
    Ny
    Posts
    105
    Sorry I missled you by mistake, try this

    create or replace procedure test as
    begin
    update temp1 a set t2 = ( select t2 from temp2 b where b.t1 = a.t1);
    end;


    This will update temp1.t2 with temp2.t2 where t1 = t2.

  4. #4
    Join Date
    May 2000
    Location
    ATLANTA, GA, USA
    Posts
    3,135
    Your procedure should be
    create or replace procedure test as
    begin
    update temp1 a set a.t2 = ( select a.t1*b.t2
    from temp2 b
    where b.t1 = a.t1)
    where a.t1 in ( Select c.t1 from temp2 c ) ;
    commit;
    end;
    /

    Note: If you don't add WHERE clause for the updating table, all the rows will be updated. In ANSI SQL, the column being updated is set to NULL before the value is written on to that column. Hence, restricting the rows is must.

    [Edited by tamilselvan on 08-13-2001 at 01:38 PM]

  5. #5
    Join Date
    Jul 2000
    Location
    India
    Posts
    60
    hi,

    it worked. thanks a lot. i have another query.

    can i use olap functions in procedures. when i create a cursor

    create cursor cr_sch_dt (tdate date) is
    select cmast.sch_code, brok_code, cmast.isc_code, cust_type, count(1) no_cust from
    (Select cust_code, sch_code, brok_code, isc_code, trxn_date,
    rank() over(partition by cust_code, sch_code order by trxn_date desc) prank
    from test.eis_trans where trxn_type = 'P' and trxn_date <= tdate) rdet,
    eis_cust_mast cmast
    where prank = 1 and rdet.cust_code = cmast.cust_code
    group by cmast.sch_code, brok_code, cmast.isc_code, cust_type;

    it gives me the foll error
    LINE/COL ERROR
    -------- -----------------------------------------------------------------
    182/15 PLS-00103: Encountered the symbol "(" when expecting one of the
    following:
    , from

    which points out to the "(" of "Over". how can i write this statement ?

    satish

  6. #6
    Join Date
    Dec 2000
    Location
    Ljubljana, Slovenia
    Posts
    4,439
    No, AFAIK you can't use analytical functions in PL/SQL in 8i. I guess you can use them in 9i, but I've not try it yet...
    Jurij Modic
    ASCII a stupid question, get a stupid ANSI
    24 hours in a day .... 24 beer in a case .... coincidence?

  7. #7
    Join Date
    Nov 2000
    Location
    Baltimore, MD USA
    Posts
    1,339
    You have to use dynamic SQL to utilize Analytical functions (or CASE statements) in PL/SQL in 8i. Thank you, Oracle

    - Chris

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width