Update Oracle column using function

I have a table that has a scan file name.
I have a fuction that takes the scan file name as a parameter and finds the file path.
I need to update a column in the table with this function output.
So, for every scan file name, I'll have an associated column value with the file path.

This sounds simple but I'm struggling.  Can I update the column value with a function?
Any direction appreciated.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
Sure you can use a function to update a column.

Maybe something like:
update some_table set some_column=FILE_LOC('file_name');

To be more specific we would need more information.  Some sample data and expected results would help.
diannagibbsAuthor Commented:
Pretty basic:
Table has two columns
scan_file which is the file name
file_path which is null until updated
function is file_loc and you give it a variable input of scan_file

I want to update file_path with the output of function file_loc
slightwv (䄆 Netminder) Commented:
The update statement I posted above should be the correct syntax.

Below is a simplified test case based on what I think you have.  Of course my function is pretty simple and has a hard-coded path but as long as your function returns a varchar2, it should be representative.

drop table tab1 purge;

create table tab1(
scan_file varchar2(20),
file_path varchar2(200)

insert into tab1(scan_file) values('file1');
insert into tab1(scan_file) values('file2');

create or replace function file_loc(p_file in varchar2) return varchar2
	return '\S-\ts\t-\18\70\' || p_file;

show errors

update tab1 set file_path=file_loc(scan_file);

select * from tab1;

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

diannagibbsAuthor Commented:
Thanks.  Let me play with this and see.
diannagibbsAuthor Commented:
Got it to work - thanks for your suggestions.  Actually, I just updated the field with current function.  Thought it would be much harder than that.
Steve WalesSenior Database AdministratorCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.