database - SQL script to get information to add to the DB -
i trying create swl script prompt user information added database. prompting user date , store name. after user enters store name want run query return code associated store name , assign variable. when run script, after user enters store name, happens:
enter date of expense:01-01-13 enter store name expense against:meted 12
i not sure doing wrong new writing sql scripts. below script file appreciate help/tips. thank you. p.s., amusing sql plus / oracle.
accept edate prompt 'enter date of expense:'; accept storename prompt 'enter store name expense against:'; declare v_storecode varchar; begin select code v_storecode store storename = '&storename'; end; insert expmast (expnum, edate, storecode) values(seq_expmast.nextval, to_date('&edate','mm-dd-yy'), 'v_storecode');
the 12
line number, because you're being prompted input. sql*plus expects /
on new line execute anonymous block. script hasn't got that. hence prompt.
you have other problems. presume want insert retrieved value of code right you're inserting string 'v_storecode'
. need remove single quotes.
accept edate prompt 'enter date of expense:'; accept storename prompt 'enter store name expense against:'; declare v_storecode varchar; begin select code v_storecode store storename = '&storename'; end; / insert expmast (expnum, edate, storecode) values(seq_expmast.nextval, to_date('&edate','mm-dd-yy'), v_storecode);
in addition tidy code using insert ... select construct:
accept edate prompt 'enter date of expense:'; accept storename prompt 'enter store name expense against:'; insert expmast (expnum, edate, storecode) select seq_expmast.nextval, to_date('&edate','mm-dd-yy'), code store storename = '&storename';
Comments
Post a Comment