• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • Last Modified:

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.

  • 3
  • 2
1 Solution
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now