Connecting Tech Pros Worldwide Forums | Help | Site Map

help with "execute immediate" in oracle

Newbie
 
Join Date: Nov 2008
Posts: 10
#1: Nov 27 '08
hi
i need to insert values in a temporary teble which i dynamically create the columns like tbl_01, tbl_02....
for eg.,
execute immediate 'INSERT INTO TBL_MONTH_LEAVE_DETAIL(TBL_ADM_NO,TBL_MONTH,'TBL_' ||TO_CHAR(SYSDATE,'DD'))'
||'VALUES (TRSTBD_ADM_NO,TO_CHAR(SYSDATE,'MMYY'),1)';

HERE THE COLUMNS ARE TBL_ADM_NO,TBL_MONTH,TBL_01,.....TBL_30
ACCORDING TO THE DAY THE COLUMN WILL BE SELECTED AND A VALUE 1 WILL BE INSERTED.

amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#2: Nov 27 '08

re: help with "execute immediate" in oracle


So what is the error that your dynamic insert statement is displaying?
amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#3: Nov 27 '08

re: help with "execute immediate" in oracle


Try this statement:

Expand|Select|Wrap|Line Numbers
  1.  
  2. execute immediate 'INSERT INTO TBL_MONTH_LEAVE_DETAIL(TBL_ADM_NO,TBL_MONTH,TBL_'||TO_CHAR(SYSDATE,'DD'))||'VALUES (TRSTBD_ADM_NO,TO_CHAR(SYSDATE,''MMYY''),1)';
  3.  
  4.  
Newbie
 
Join Date: Nov 2008
Posts: 10
#4: Nov 28 '08

re: help with "execute immediate" in oracle


the error says column not allowed here
Newbie
 
Join Date: Nov 2008
Posts: 10
#5: Nov 28 '08

re: help with "execute immediate" in oracle


can we concatenate the column names in the execute immedite statement?
Member
 
Join Date: Oct 2008
Location: Home
Posts: 127
#6: Nov 28 '08

re: help with "execute immediate" in oracle


Hi,

Check you parenthesis and quotes, i think you are making a mistake with that.

Pilgrim.
debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,508
#7: Nov 28 '08

re: help with "execute immediate" in oracle


Quote:

Originally Posted by cmuraz View Post

can we concatenate the column names in the execute immedite statement?

why you need to concatenate the column names in insert statement ?
Newbie
 
Join Date: Nov 2008
Posts: 10
#8: Dec 1 '08

re: help with "execute immediate" in oracle


thank u guys n sorry for the trouble..
ive done a mistake in the paranthesis and quotation mark.
i ve misplaced them in a wrong place...
i got it working now..
thanks a lot
Member
 
Join Date: Oct 2008
Location: Home
Posts: 127
#9: Dec 1 '08

re: help with "execute immediate" in oracle


Quote:

Originally Posted by cmuraz View Post

thank u guys n sorry for the trouble..
ive done a mistake in the paranthesis and quotation mark.
i ve misplaced them in a wrong place...
i got it working now..
thanks a lot

Hi,

Good to see that your problem is solved.

Pilgrim.
Reply