Home » RDBMS Server » Server Administration » quotation mark in pl/sql
quotation mark in pl/sql [message #55823] Tue, 18 February 2003 10:42 Go to next message
Tony
Messages: 190
Registered: June 2001
Senior Member
Hello,
I have the following dynamic SQL:
DECLARE
cursor c1 is SELECT bill_fname,bill_lname,bill_phone,email,ship_addr,ship_city,ship_state,ship_zip,bill_addr,b
ill_city,bill_state,bill_zip FROM CUSTOMER_MERGE_V;
str varchar2(1000);
begin
for mag in c1 loop
exit when c1%notfound;
str:='UPDATE CUSTOMER_T SET TELEPHONE='||mag.bill_phone||',ship_address='||mag.ship_addr||',ship_city='||mag.ship_city||',ship_state='||mag.ship_state||',ship_zip='||mag.ship_zip||',bill_address='||mag.bill_addr||',bill_city='||mag.bill_city||',bill_state='||mag.bill_state||' where first_name= '||mag.bill_fname||' and last_name= '||mag.bill_lname||' and email='||mag.email;
execute immediate str;
end loop;
end;
/

when i look at my trace files, i can see that the sql being generated is like set last_name=JOHN instead of set last_name='JOHN'. How can I embed the quotation marks in my statement here?thanks a bunch
Re: quotation mark in pl/sql [message #55824 is a reply to message #55823] Tue, 18 February 2003 11:43 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
mag@itloaner1_local > ed
Wrote file afiedt.buf

  1  declare
  2  cursor c1 is select * from dept;
  3  begin
  4  for mag in c1 loop
  5     exit when c1%notfound;
  6          dbms_output.put_line('select * from emp where loc='||''''||mag.loc||'''');
  7  end loop;
  8* end;
mag@itloaner1_local > /
select * from emp where loc='NEW YORK'
select * from emp where loc='DALLAS'
select * from emp where loc='CHICAGO'
select * from emp where loc='BOSTON'

PL/SQL procedure successfully completed.

Re: quotation mark in pl/sql [message #55826 is a reply to message #55823] Tue, 18 February 2003 13:45 Go to previous messageGo to next message
Tony
Messages: 190
Registered: June 2001
Senior Member
thanks for the reply, I have tried the following:
declare
cursor c1 is SELECT bill_fname,bill_lname,bill_phone,email,ship_addr,ship_city,ship_state,ship_zip,bill_addr,bill_city,bill_state,bill_zip FROM CUSTOMER_MERGE_V;
begin
for mag in c1 loop
exit when c1%notfound;
dbms_output.put_line('UPDATE CUSTOMER_T SET TELEPHONE='||''''||mag.bill_phone||'''',ship_address='||''''||mag.ship_addr||'''',ship_city='||''''||mag.ship_city||'''',ship_state='||''''||mag.ship_state||'''',ship_zip='||''''||mag.ship_zip||'''',bill_address='||''''||mag.bill_addr||'''',bill_city='||''''||mag.bill_city||'''',bill_state='||''''||mag.bill_state||'''' where first_name= '||''''||mag.bill_fname||'''' and last_name= '||''''||mag.bill_lname||'''' and email='||''''||mag.email||'''');
end loop;
end;
/

I m getting "identifier 'SHIP_ADDRESS' must be declared" error, I think it doesn t like the comma, the same update works in sql plus with values entered manually.. thanks
Re: quotation mark in pl/sql [message #55837 is a reply to message #55823] Wed, 19 February 2003 06:55 Go to previous message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
the chr(10) is added for more readablity...remove them...

mag@itloaner1_local > ED
Wrote file afiedt.buf

  1  CREATE TABLE MERGE_V
  2  (
  3  bill_fname VARCHAR2(10),
  4  bill_lname VARCHAR2(10),
  5  bill_phone NUMBER,
  6  email  VARCHAR2(10),
  7  ship_addr VARCHAR2(10),
  8  ship_city VARCHAR2(10),
  9  ship_state VARCHAR2(10),
 10  ship_zip VARCHAR2(10),
 11  bill_addr VARCHAR2(10),
 12  bill_city VARCHAR2(10),
 13  bill_state VARCHAR2(10),
 14* bill_zip  VARCHAR2(10))
mag@itloaner1_local > /
Table created.
mag@itloaner1_local > ed
Wrote file afiedt.buf

  1  INSERT INTO MERGE_V
  2  VALUES
  3* ('first','last',123,'sm@sam.com','boston','bs','ma','92','33','salem','ma','33')
mag@itloaner1_local > /

1 row created.

-- based on above example...
mag@itloaner1_local > ed
Wrote file afiedt.buf

  1  declare
  2   cursor c1 is SELECT
  3      Bill_fname,bill_lname,bill_phone,email,ship_addr,ship_city,
  4      ship_state,ship_zip,bill_addr,bill_city,bill_state,bill_zip
  5   FROM MERGE_V;
  6   begin
  7   for mag in c1 loop
  8   exit when c1%notfound;
  9   dbms_output.put_line('UPDATE CUSTOMER_T SET '||chr(10)||
 10      ' TELEPHONE='     ||mag.bill_phone||','||chr(10)||
 11      ' ship_address=''' ||mag.ship_addr ||''','||chr(10)||
 12      ' ship_city='''    ||Mag.ship_city ||''','||chr(10)||
 13      ' ship_state='''   ||Mag.ship_state||''','||chr(10)||
 14      ' ship_zip='''     ||mag.ship_zip  ||''','||chr(10)||
 15      ' bill_address=''' ||mag.bill_addr ||''','||chr(10)||
 16      ' bill_city='''    ||mag.bill_city ||''','||chr(10)||
 17      ' bill_state='''   ||mag.bill_state||''''||chr(10)||
 18      ' where  first_name='''||mag.bill_fname ||''''||chr(10)||
 19      ' and last_name= '''||mag.bill_lname ||''''||chr(10)||
 20      ' and email='''||mag.email||''''||';');
 21   end loop;
 22*  end;
mag@itloaner1_local > /
UPDATE CUSTOMER_T SET 
 TELEPHONE=123,
 ship_address='boston',
 ship_city='bs',
 ship_state='ma',
 ship_zip='92',

bill_address='33',
 bill_city='salem',
 bill_state='ma'
 where  first_name='first'
 and last_name= 'last'
 and email='sm@sam.com';

PL/SQL procedure successfully completed.

Previous Topic: How to know the oracle database size
Next Topic: Can we mailtain log file of all the queries to a DB
Goto Forum:
  


Current Time: Fri Sep 20 03:27:40 CDT 2024