Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7913357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:49:26+00:00 2026-06-03T13:49:26+00:00

I have a problem with the query I have a table newtable and have

  • 0

I have a problem with the query I have a table newtable and have inserted values:

create table newtable(
col1 varchar2(3),
col2 varchar2(3),
col3 varchar2(3),
col4 varchar2(3),
col5 varchar2(3)
)

insert into newtable values(5,'m','q',4,3);

I want to add together the values in the columns which have only digits. In this case, I want the result to be 12 (5+4+3).

In Excel, I would do something similar with the countif function. How do I do this in Oracle?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T13:49:29+00:00Added an answer on June 3, 2026 at 1:49 pm

    You could create a function that either converts the string to a number or returns a 0 and use that function on each column

    SQL> ed
    Wrote file afiedt.buf
    
      1  create or replace function my_to_number( p_str in varchar2 )
      2    return number
      3  is
      4    l_num number;
      5  begin
      6    l_num := to_number( p_str );
      7    return l_num;
      8  exception
      9    when others then
     10      return 0;
     11* end;
    SQL> /
    
    Function created.
    
    SQL> select my_to_number(col1) +
      2         my_to_number(col2) +
      3         my_to_number(col3) +
      4         my_to_number(col4) +
      5         my_to_number(col5)
      6    from newtable;
    
    MY_TO_NUMBER(COL1)+MY_TO_NUMBER(COL2)+MY_TO_NUMBER(COL3)+MY_TO_NUMBER(COL4)+MY_T
    --------------------------------------------------------------------------------
                                                                                  12
    

    In a relational database, however, it is almost certainly a mistake to design a data model where you are storing numeric data in a varchar2 column when you want to subsequently treat that data as a number to do things like add the numbers together. It is almost certainly a mistake to design a data model where a particular column will sometimes store a numeric value and sometimes store a string. So I would be exceptionally concerned that the design of newtable needs to be rethought.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some problem whith such mysql_query INSERT INTO table VALUES ('', CURDATE()-1) why
I have a performance problem on a query. First table is a Customer table
Got a problem with a query I'm trying to write. I have a table
I have a problem with mysql query .. I have a table in the
I having this problem with query these two table do not have any link
I have a problem with a query: I have a table with sections and
HI, I have a problem with this query SELECT * FROM table WHERE `name`
I have a query problem. I have a table of agents that do things.
I have started learning django and have a problem with INSERT-query using ORM (DB
I have a problem with an SQL query. SELECT SUM(table_colum) AS value, SUM(value *

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.