?
Solved

sql query

Posted on 2016-11-09
5
Medium Priority
?
90 Views
Last Modified: 2016-11-10
how to write a pl sql which will count the number of not null rows in a column and update another table with the sum?
0
Comment
Question by:sam shah
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 49

Expert Comment

by:PortletPaul
ID: 41881717
PL/SQL is Oracle, so I  added that topic.
Is ms sql server not relevant?

Could you elaborate on your question with a small example. Include the real tables names and column name you want updated.
0
 
LVL 11

Expert Comment

by:HuaMinChen
ID: 41881786
Try
Update Tab1
set col1=(select count(1) from Tab2 where nvl(col2,'')<>'');

Open in new window

0
 
LVL 35

Expert Comment

by:ste5an
ID: 41881808
There is no such think like a null row. What is your concrete problem?
0
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 2000 total points
ID: 41882073
HuaMinChen,

That won't work.  Oracle treats an empty string as a null.



sam,

To update a COLUMN with the count of not null COLUMNS:
update some_table set some_column=(select count(*) from another_table where some_column is not null);

I suspect the real answer is a little more complex than that.  As Paul and ste5an suggested, can you explain more about the actual requirements?
0
 
LVL 32

Expert Comment

by:awking00
ID: 41882116
Sample data with table names and structures, column names and their data types, plus the expected results is ALWAYS helpful.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the dā€¦
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to recover a database from a user managed backup
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question