Home » Other » Training & Certification » Insert values into a table using function
Insert values into a table using function [message #264015] Fri, 31 August 2007 09:12 Go to next message
nagaraj42
Messages: 8
Registered: August 2007
Location: chennai
Junior Member
Can anyone please help in writing a function which will insert the values into table when we give the input values.
And it has to display the result as "PASS" if the inserted value is a number and it is "Fail" if inserted value is not number

I have written the function like this... Can you please help me in goin further

I am inserting upto 100 values at present....



CREATE OR REPLACE FUNCTION FN_INSERT ( I NUMBER )
RETURN VARCHAR2 ;
BEGIN
LOOP
INSERT INTO T1 VALUES(I,I);
I := I+1;

EXIT WHEN I>100;

END LOOP;

RETURN ('PASS');

EXCEPTION WHEN OTHERS THEN
RETURN ('FAIL');

END;
Re: Insert values into a table using function [message #264025 is a reply to message #264015] Fri, 31 August 2007 09:33 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
Where do you define J?
bummer, need glasses... Thought it said values (I, J)

ok,
what happens if you execute this?

[Updated on: Fri, 31 August 2007 09:33]

Report message to a moderator

Re: Insert values into a table using function [message #264032 is a reply to message #264025] Fri, 31 August 2007 09:44 Go to previous messageGo to next message
Littlefoot
Messages: 20899
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Many bad things, one after another.
Re: Insert values into a table using function [message #264062 is a reply to message #264015] Fri, 31 August 2007 10:37 Go to previous messageGo to next message
Michel Cadot
Messages: 64131
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
First line: if your parameter is of type number then it can't not be a number (I'm not sure this is correct english).

Regards
Michel

[Updated on: Fri, 31 August 2007 10:38]

Report message to a moderator

Re: Insert values into a table using function [message #264096 is a reply to message #264015] Fri, 31 August 2007 14:45 Go to previous messageGo to next message
Barbara Boehmer
Messages: 8635
Registered: November 2002
Location: California, USA
Senior Member
Also, you have a semicolon after varchar2 that should not be there and you are missing AS before begin. You should use SHOW ERRORS to display the errors after you try to compile your function, then work through correcting the errors, one at a time.
Re: Insert values into a table using function [message #264174 is a reply to message #264062] Sat, 01 September 2007 07:23 Go to previous messageGo to next message
nagaraj42
Messages: 8
Registered: August 2007
Location: chennai
Junior Member
Can you please correct that function ?? Is the parameter of data type number is wrong??
Please suggest me where I am going wrong.

The concept is this " writing a function which will insert the values into table when we give the input values.
And it has to display the result as "PASS" if the inserted value is a number and it is "Fail" if inserted value is not number " T1 is any table which is created to insert values into table.

Regards,

Raju

[Updated on: Sat, 01 September 2007 07:24]

Report message to a moderator

Re: Insert values into a table using function [message #264182 is a reply to message #264015] Sat, 01 September 2007 09:05 Go to previous messageGo to next message
BlackSwan
Messages: 25046
Registered: January 2009
Location: SoCal
Senior Member
Do you REALLY want others to do your homework assignment for you?
If you can't/won't do this assignment, perhaps you should drop this class & try something better suited for your capabilities.

Please use CUT & PASTE & show us a function that contains ZERO compilation errors.
Re: Insert values into a table using function [message #264188 is a reply to message #264182] Sat, 01 September 2007 09:35 Go to previous messageGo to next message
Michel Cadot
Messages: 64131
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Ana, you missed the revolution in skills.
Now, having skills is to be able to find the forum that will do the job for you.

./fa/1686/0/
Regards
Michel
Re: Insert values into a table using function [message #264192 is a reply to message #264174] Sat, 01 September 2007 14:07 Go to previous messageGo to next message
Barbara Boehmer
Messages: 8635
Registered: November 2002
Location: California, USA
Senior Member
If you want to test for a valid number within the function, then you need to accept a varchar2 parameter and use to_number within the function to test for a valid number. Any of us could easily correct your function, but then you would not learn anything, so we are trying to just point you in the right direction, so that you can learn how to test and fix your own code, instead of relying on others to do it for you.
Re: Insert values into a table using function [message #264322 is a reply to message #264192] Mon, 03 September 2007 00:42 Go to previous message
nagaraj42
Messages: 8
Registered: August 2007
Location: chennai
Junior Member
Thanks for your suggestion Barbara Boehmer.
Previous Topic: problem with new database
Next Topic: changing zero into hi?
Goto Forum:
  


Current Time: Wed Dec 07 12:55:21 CST 2016

Total time taken to generate the page: 0.07492 seconds