473,748 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with function

137 New Member
hi all,
i have written one function, but it is showing some error, the code is as follows:

Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE FUNCTION fn_name(int8, int8, int8, "varchar", date, date)
  2. RETURNS "varchar" AS
  3. '
  4. declare
  5. dt numeric;
  6. a varchar(20);
  7. start_dt alias for $5;
  8. end_dt alias for $6;
  9. et alias for $4;
  10. begin
  11. if et = \'D\' then
  12. while not start_dt = end_dt loop 
  13. insert into tbl1(event_cd, party_cd, project_cd, event_type,event_dt) values ($1,$2,$3,$4,start_dt)
  14. start_dt:=to_date(start_dt,\'yyyy-mm-dd\') + interval \'1 day\';
  15. end loop;
  16. end if;
  17. return \'a\';
  18. end'
  19.   LANGUAGE 'plpgsql' VOLATILE;
  20.  
  21.  
i want to insert the whole data with only the date incremented by 1 day till it equals to the end date. but it shows the error:
parser:parse error at or near "$6" at character 112

can anyone help me?

TIA
Jul 15 '07 #1
4 1291
michaelb
534 Recognized Expert Contributor
It often helps to provide information such as what version of database you are using, do you get a compile time or run time error, and, if this is the run time error what are the arguments you pass to the function.

I suppose that you are getting a compile time error, can you post the version of Postgresql?
Jul 15 '07 #2
michaelb
534 Recognized Expert Contributor
I took a closer look at your code and I think you probably have a run time error;
I can spot at least two problems in your function:

1) On line 13 the INSERT statement is not terminated with semi-colon, this is likely the cause of the error message you got.

2) On line 14 you are changing the value of $5.
The function arguments are considered to be constants, and so their aliases.
If you get another error after terminating INSERT with ";" you may have to change your code like this:

Expand|Select|Wrap|Line Numbers
  1.    declare
  2.         ... ... ...
  3.         start_dt date ;
  4.  
  5.    begin
  6.         start_dt := $5;
  7.          ... ... ... ...
  8.  
This should allow incrementing value of start_dt
Jul 15 '07 #3
coolminded
137 New Member
I took a closer look at your code and I think you probably have a run time error;
I can spot at least two problems in your function:

1) On line 13 the INSERT statement is not terminated with semi-colon, this is likely the cause of the error message you got.

2) On line 14 you are changing the value of $5.
The function arguments are considered to be constants, and so their aliases.
If you get another error after terminating INSERT with ";" you may have to change your code like this:

Expand|Select|Wrap|Line Numbers
  1.    declare
  2.         ... ... ...
  3.         start_dt date ;
  4.  
  5.    begin
  6.         start_dt := $5;
  7.          ... ... ... ...
  8.  
This should allow incrementing value of start_dt

thanx for your suggestion michaelb,
it really helped me a lot.
thanx once again
Jul 16 '07 #4
michaelb
534 Recognized Expert Contributor
coolminded, you are very welcome!
Jul 16 '07 #5

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

Similar topics

1
20698
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function init() {
7
2439
by: Emanuel Ziegler | last post by:
Hello, I want to do some mathematics with functions. In my case the function classes are very complex, but this simple example has the same problems. To allow calculations that begin with a double, I have to define a global operator+ (or -*/) and special function classes. --- source begins here ---
117
7239
by: Peter Olcott | last post by:
www.halting-problem.com
1
3646
by: Mohamed Fysal | last post by:
I have written a Regular DLL with many Export Functions and one CALLBACK fun ction . The callback function declared in the .cpp file of the Regular DLL is as fol lows: typedef BOOL (CALLBACK* ExProcessMessage)(UINT msg, LPVOID lpParam); // ExProcessMessage MyProcMsg;
4
6031
by: Andy_Khosravi | last post by:
Hello, I'm having a problem with the MID function within Access 97. I have been trying to build a function to check to make sure that a field on a form does not have any spaces or dashes. This should be easy enough to do using the MID function in a For...Next statement. However, I've had more than a few problems. My first problem was that I had a data type mismatch. Access simply refused to evaluate anything I put in there no matter...
0
1598
by: Lucas, Todd | last post by:
Hello everyone! I'm having a problem with a WebControl that I'm designing for a Menu. I've been at it for about 3 weeks now, and can't seem to get around this problem. So I'm hoping that someone can help me ... My environment: VS 2003 v7.1.3088, Win2K v5.0.2195 SP3, IE6 v6.0.2800.1106 browser. I have a class (C3Menu) derived from WebControl, with a property (MenuItems) that is a collection of menu items. The collection property is...
78
4964
by: Josiah Manson | last post by:
I found that I was repeating the same couple of lines over and over in a function and decided to split those lines into a nested function after copying one too many minor changes all over. The only problem is that my little helper function doesn't work! It claims that a variable doesn't exist. If I move the variable declaration, it finds the variable, but can't change it. Declaring the variable global in the nested function doesn't work...
5
14816
by: jbenner | last post by:
I have opened a PMR for this with IBM, and am not asking for advice from the DB2 DBA community. I am posting this as an FYI that DB2 Health Monitor, even at the latest version of DB2, still can cause huge problems with slow connect times and heavy resource locking in high concurrency / high transaction volume environments. I have an OLTP with 30-90 transactions per second activity, and start of Health Monitor every 2 hours was crashing our...
2
7411
by: Ravikiranreddy | last post by:
Hi every one, Am pasting the error code returned in log please help me in fixing it--- ERROR:An error occurred during the execution of the command "/opt/IBM/db2/V8.1/instance/dascrt -u dasusr1 -d". The DB2 Administration Server may not function properly. The return value is "1". ERROR:## call function cleanup_reg_list das crt dasusr1 ## call function create_das
6
4547
by: pauldepstein | last post by:
Let double NR( double x, double(*)(const double&) f ) be the signature of a Newton-Raphson function NR. Here, f is a function which returns a double and accepts a const double&. The aim of the game is to find a zero of this function f (the point at which f crosses the x-axis). This zero-of-f which solves our problem is the double which NR returns. It remains to explain what the "double x" represents. This is the...
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.