By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,826 Members | 2,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,826 IT Pros & Developers. It's quick & easy.

USE OF VARIABLES IN postgreSQL

P: 1
I HAVE A PROBLEM REGARDING DECLARATION/ INITIALISATION OF VARIABLES IN POSTGRESQL FUNCTIONS AND PROCEDURES. MY CODE PRESENTLY LOOKS LIKE
Expand|Select|Wrap|Line Numbers
  1. CREATE FUNCTION ins_into_std_values() RETURNS void AS
  2. $BODY$
  3. myflag CHAR(1) :='y';
  4. dbms_output.put_line('enter the values sequentially');
  5.     loop
  6.             if myflag='n' then 
  7.             exit;
  8.             end if;
  9.         insert into std_values
  10.         values('&tree_species_name','&location',&p,&c1,&c2,&q,&c3,&a,&b,&sp_gravity,&exp_factor);
  11.         commit;
  12.         dbms_output.put_line('records inserted sucessfully');
  13.         dbms_output.put_line('enter n to exit or y to continue entering values');
  14.         myflag:= '&y or n';
  15.     end loop;
  16. commit;
  17. $BODY$
  18. LANGUAGE 'sql' VOLATILE;
  19.  
BUT IT SHOWS ERROR AT INITIALISATION OF MYFLAG... CAN ANYONE TELL ME HOW TO DECLARE VARIABLES IN POSTGRESQL..
Jun 22 '07 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 534
saumya, please read the Posting Guidelines at the top of the forum and use the CODE tags in your future postings.
Jun 22 '07 #2

Expert 100+
P: 534
Your code has to with Oracle more than with Postgresql.
There's no dbms_output.put_line in Postgresql, and you probably want to use plpgsql, not sql for this function.

Please start with the PostgreSQL manual:
CREATE FUNCTION
Writing SQL Functions
Procedural languages
plpgsql procedural language
Declarations
Jun 22 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.