How to eliminate explicit "null" values
Hello,
I am having a problem in eliminating the explicit "null" values while retrieving them from the database.
Here is my problem as follows,
For the optional fields in a form i am explicitly entering "null" as value or else it is throwing null pointer exception in linux. While i am trying to display the values existing in a table it is displaying fine when i use this condition
if(varialble.equals("null") ||varialble.equals("") || variable.equals(null))
varialble = "";
else
out.println(variable)
But when i use the same for the values i retrieve from the view it is displaying "Null" for the explicit "null" values and null from implicit null values.
Please help me out how to remove the explicit null values. It would be great help if somebody replies me at the earliest.
Thanks in advance
daya
the following is the code which i am using to retrieve values.
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.*;
import StrChk.*;
public class DataSearch extends HttpServlet
Connection con=null;
Statement st=null;
ResultSet rs=null;
ResultSetMetaData rsmd=null;
PrintWriter out=null;
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException,ServletException
String key;
String sql;
res.setContentType("text/html");
out = res.getWriter();
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:daya","daya","daya");
st = con.createStatement();
catch(Exception e)
System.out.println("Error Accessing DataBase:"+e);
key = req.getParameter("key");
// Search(str1.retString(key));
Search(key);
public void Search(String key)
int res=0;
boolean flag=true,found=false;
StringTokenizer strt = new StringTokenizer(key, " ");
String sql;
String str1,str2;
int i=0;
int count = strt.countTokens();
String keywords[] = new String[count+1];
keywords=key;
i++;
if(count > 1)
count++;
while(strt.hasMoreTokens())
keywords[i] = strt.nextToken();
i++;
out.println("<html><title>DataSearch</title>");
out.println("<script>");
out.println("function myclose(){ self.close(); } ");
out.println("</script><body>");
for(i=0; i<count && flag==true; i++)
try
/* sql = "select ";
sql += " nvl(\"Topic Title\",' '), ";
sql += " nvl(\"Name\",' '), ";
sql += " nvl(\"Title\",' '), ";
sql += " nvl(\"Affiliation\",' '), ";
sql += " nvl(\"Street Name\",' '), ";
sql += " nvl(\"City\",' '), ";
sql += " nvl(\"State\",' '), ";
sql += " nvl(\"Country\",' '), ";
sql += " nvl(\"Zip Code\",' '), ";
sql += " nvl(\"Phone\",' '), ";
sql += " nvl(\"Fax\",' '), ";
sql += " nvl(\"eMail\",' '), ";
sql += " nvl(\"Web Site\",' ') ";
sql += " from SEARCHVWUSERDET where ";
sql += " lower(\"Name\") like " + "lower('%" + keywords[i] + "%') or ";
sql += " lower(\"Title\") like " + "lower('%" + keywords[i] + "%') or ";
sql += " lower(\"Affiliation\") like " + "lower('%" + keywords[i] + "%') or ";
sql += " lower(\"Street Name\") like " + "lower('%" + keywords[i] + "%') or ";
sql += " lower(\"City\") like " + "lower('%" + keywords[i] + "%') or ";
sql += " lower(\"State\") like " + "lower('%" + keywords[i] + "%') or ";
sql += " lower(\"Country\") like " + "lower('%" + keywords[i] + "%') or ";
sql += " lower(\"eMail\") like " + "lower('%" + keywords[i] + "%') or ";
sql += " lower(\"Web Site\") like " + "lower('%" + keywords[i] + "%')";*/
sql = "select ";
sql += " nvl(\"Name\",' '), ";
sql += " nvl(\"Title\",' '), ";
sql += " nvl(\"Affiliation\",' '), ";
sql += " nvl(\"Street Name\",' '), ";
sql += " nvl(\"City\",' '), ";
sql += " nvl(\"State\",' '), ";
sql += " nvl(\"Country\",' '), ";
sql += " nvl(\"Zip Code\",' '), ";
sql += " nvl(\"Phone\",' '), ";
sql += " nvl(\"Fax\",' '), ";
sql += " nvl(\"eMail\",' '), ";
sql += " nvl(\"Web Site\",' '), ";
sql += " nvl(\"Key Words\",' ') ";
sql += " from searchcombi where ";
sql += " lower(\"Name\") like " + "lower('%" + keywords[i] + "%') or ";
sql += " lower(\"Title\") like " + "lower('%" + keywords[i] + "%') or ";
sql += " lower(\"Affiliation\") like " + "lower('%" + keywords[i] + "%') or ";
sql += " lower(\"Street Name\") like " + "lower('%" + keywords[i] + "%') or ";
sql += " lower(\"City\") like " + "lower('%" + keywords[i] + "%') or ";
sql += " lower(\"State\") like " + "lower('%" + keywords[i] + "%') or ";
sql += " lower(\"Country\") like " + "lower('%" + keywords[i] + "%') or ";
sql += " lower(\"eMail\") like " + "lower('%" + keywords[i] + "%') or ";
sql += " lower(\"Web Site\") like " + "lower('%" + keywords[i] + "%') or";
sql += " lower(\"Key Words\") like " + "lower('%" + keywords[i] + "%')";
sql += " order by \"Name\" ";
rs = st.executeQuery(sql);
//out.println(sql);
if(rs.next())
if(i == 0)
flag=false;
found=true;
res=0;
do
res++;
}while(rs.next());
out.println(res++);
out.println("<center><font color=#ff9999 face=\"verdana, geneva, arial, sans-serif\" size=2><b>Searched for \""+ keywords[i]+"\", ");
out.println("Total Matches found : "+res+"</center><br>");
rs = st.executeQuery(sql);
while(rs.next())
res++;
out.println("<table width=600 align=center>");
str1 = disp(rs.getString(1),keywords[i]);
out.println(str1);
//if(str1.equals("null") || str1.equals(" ") || str1.equals(null))
if(str1 == "null" || str1 == "")
str1 = "";
else
out.println("<tr><td width=150><font color = green face=\"verdana, geneva, arial, sans-serif\" size=2><b>Name </td><td><font face=\"verdana, geneva, arial, sans-serif\" size=2>"+str1+"</td></tr>");
//System.out.println(str1);
//out.println(str1);
str2="";
str1 = disp(rs.getString(2),keywords[i]);
if(!str1.equals("") || !str1.equals(""))
str2 = str1;
str1 = disp(rs.getString(3),keywords[i]);
if(!str1.equals(" ") || !str1.equals(""))
if(str2.length() > 0 || !str2.endsWith(", "))
str2+= ", ";
str2 += str1;
if(!str2.equals(""))
out.println("<tr><td width=150><font color = green face=\"verdana, geneva, arial, sans-serif\" size=2><b>Title, Affiliation</td><td><font face=\"verdana, geneva, arial, sans-serif\" size=2>");
out.println(str2);
out.println("</td></tr>");
str2="";
str1 = disp(rs.getString(4),keywords[i]);
if(!str1.equals(" ") || !str1.equals(""))
str2 = str1;
str1 = disp(rs.getString(5),keywords[i]);
if(!str1.equals(" ") || !str1.equals(""))
if(str2.length() > 0 || !str2.endsWith(", "))
str2+= ", ";
str2 += str1;
str1 = disp(rs.getString(6),keywords[i]);
if(!str1.equals(" ") || !str1.equals(""))
if(str2.length() > 0 || !str2.endsWith(", "))
str2+= ", ";
str2 += str1;
str1 = disp(rs.getString(7),keywords[i]);
if(!str1.equals(" ") || !str1.equals(""))
if(str2.length() > 0 || !str2.endsWith(", "))
str2+= ", ";
str2 += str1;
str1 = disp(rs.getString(8),keywords[i]);
if(!str1.equals(" ") || !str1.equals(""))
if(str2.length() > 0 || !str2.endsWith(", "))
str2+= ", ";
str2 += str1;
if(!str2.equals(""))
out.println("<tr><td valign=top width=150><font color = green face=\"verdana, geneva, arial, sans-serif\" size=2><b>Address </td>");
out.println("<td><font face=\"verdana, geneva, arial, sans-serif\" size=2>");
out.println(str2);
out.println("</td></tr>");
str1 = disp(rs.getString(9),keywords[i]);
if(!str1.equals(" ") || !str1.equals(""))
out.println("<tr><td width=150><font color = green face=\"verdana, geneva, arial, sans-serif\" size=2><b>Phone</td><td><font face=\"verdana, geneva, arial, sans-serif\" size=2>"+str1+"</td></tr>");
str1 = disp(rs.getString(10),keywords[i]);
if(!str1.equals(" ") || !str1.equals(""))
out.println("<tr><td width=150><font color = green face=\"verdana, geneva, arial, sans-serif\" size=2><b>Fax</td><td><font face=\"verdana, geneva, arial, sans-serif\" size=2>"+str1+"</td></tr>");
str1 = disp(rs.getString(11),keywords[i]).toLowerCase();
if(!str1.equals(" ") || !str1.equals(""))
out.println("<tr><td width=150><font color = green face=\"verdana, geneva, arial, sans-serif\" size=2><b>eMail</td><td><font face=\"verdana, geneva, arial, sans-serif\" size=2>"+str1+"</td></tr>");
str1 = disp(rs.getString(12),keywords[i]).toLowerCase();
if(str1.equals("null") || str1.equals(" ") || str1.equals(null))
str1="";
else
out.println("<tr><td width=150><font color = green face=\"verdana, geneva, arial, sans-serif\" size=2><b>Web Site</td><td><font face=\"verdana, geneva, arial, sans-serif\" size=2>"+str1+"</td></tr>");
str1 = disp((rs.getString(13)).replace(',',' '),keywords[i]);
if(str1 == "null" || str1 == null || str1 == "")
//if(!rs.wasNull())
out.println("nothing");
else
out.println("<tr><td width=150><font color = green face=\"verdana, geneva, arial, sans-serif\" size=2><b>Key Words</td><td><font face=\"verdana, geneva, arial, sans-serif\" size=2>"+str1+"</td></tr>");
out.println("<tr><td width=150><hr></td><td><hr></td></tr>");
out.println("</table><br>");
} // end while
} // end if
catch(Exception e)
System.out.println("Exception while executing query: "+ e);
} // end for
if(!found)
out.println("<center><font color=#ff9999 face=\"verdana, geneva, arial, sans-serif\" size=2><b>Searched for \""+ key+"\", ");
out.println("Total Matches found : 0</center><br>");
out.println("<center><a href=\"javascript:myclose()\"><font color=red face=\"verdana, geneva, arial, sans-serif\" size=2>Close</a></center>");
out.println("</body></html>");
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException,ServletException
doPost(req,res);
public String disp(String str1, String str2)
int i,j,k;
boolean found=false;
String s1,s2,s3;
String t1,t2;
t1 = initCap(str1);
s1 = t1.toLowerCase();
s2 = str2.toLowerCase();
for(i=0;i<s1.length() && !found ;i++)
k=i;
for(j=0;j<s2.length() && k < s1.length() && s1.charAt(k) == s2.charAt(j) ;j++,k++);
if(j==s2.length())
found=true;
if(found)
i--;
s3 = t1.substring(0,i);
s3 += "<font color=blue face=\"verdana, geneva, arial, sans-serif\" size=2><b>";
s3 += t1.substring(i,i+str2.length());
s3 += "</font></b>";
s3 += t1.substring(i+str2.length(),t1.length());
else
s3 = t1;
return s3;
public String initCap(String str)
StringTokenizer st = new StringTokenizer(str," ");
String s1="";
String s2="";
String s3="";
String s4="";
while(st.hasMoreElements())
s1 = (String)st.nextElement();
if(s1.length() > 0)
s2 = s1.substring(0,1);
s2 = s2.toUpperCase();
if(s1.length() > 1)
s3 = s1.substring(1,s1.length());
s2 += s3;
s4 +=" "+s2;
return s4;
Similar Messages
-
How do I restrict null values??????
Hi,
Created BW report Purchase Orders Awaiting Goods Receipting. Having difficulty in restricting the report to those orders that have not been goods receipted. How do I restrict null values.
thanks in advance
S VRHi,
I believe you are using Standard Business Content.
You can use the following reports for overcome your requirement:
Query Name: 0PUR_C01_Q0017 - Quantities Purchase Order Delivery - Invoice
Link: http://help.sap.com/saphelp_nw04/helpdata/en/99/670539b15b186ce10000000a114084/content.htm
Try to use it. And let me know still you are having some doubts.
Regards,
Vivek V -
How to check for null values in pl sql?
Hello,
I have an sql statement where I read the db column into a number of variables, some of the columns contain NULL values or empty varchars. How can I check if my variable contains any data?
Thanks,
Jto check if your variable contain null or not use like this
if v_variable is null if you use
if v_variable=NULL this is right according to syntax but it will not give you desired result
SQL> declare
2 v_empname varchar2(20);
3 v_comm number;
4 begin
5 select ename,comm into v_empname,v_comm from emp
6 where empno=7839 and comm is NULL;
7 dbms_output.put_line(v_empname);
8 if v_comm is NULL then
9 dbms_output.put_line(v_empname);
10 end if;
11 end;
12 /
KING
KING
PL/SQL procedure successfully completed.but if you will use = null then you will not get result
SQL> declare
2 v_empname varchar2(20);
3 v_comm number;
4 begin
5 select ename,comm into v_empname,v_comm from emp
6 where empno=7839 and comm is NULL;
7 dbms_output.put_line(v_empname);
8 if v_comm = NULL then
9 dbms_output.put_line(v_empname);
10 end if;
11 end;
12 /
KING -------------king will get printed only once.
PL/SQL procedure successfully completed. -
How can I get null values for the later weeks
Hi All,
When I execute this code I get the records till current week.
How can I display the output so that I get null values for the later weeks. (with the help of v_numOfWeeks variable in the code)
Thanks,
Vikram
DECLARE
v_query VARCHAR2(4000);
TYPE ref_cursor IS REF CURSOR;
v_refcur ref_cursor;
v_sum NUMBER;
v_id NUMBER;
v_name VARCHAR2(1000);
v_weeknum NUMBER;
v_pernum NUMBER;
v_numOfWeeks NUMBER := 5;
BEGIN
v_query := ' SELECT SUM(product_bkg), postn_id, postn_tbl.postn_name, b.week_num, b.period_num
FROM ops_cv_extract b, (SELECT row_id, desc_text postn_name
FROM s_postn) postn_tbl
WHERE lvl_6_id = 5767
AND fiscal_year = 2008
AND b.week_num < 4
AND b.period_num = 3
AND b.postn_id = TO_NUMBER(postn_tbl.row_id)
GROUP BY postn_id, postn_tbl.postn_name, b.week_num, b.period_num
ORDER BY postn_tbl.postn_name, b.week_num';
OPEN v_refcur FOR v_query;
LOOP
FETCH v_refcur INTO v_sum, v_id, v_name, v_weeknum, v_pernum;
EXIT WHEN v_refcur%notfound;
dbms_output.put_line('P'|| v_pernum||'W'|| v_weeknum||' '||v_name||' '||v_sum);
END LOOP;
END;
This is the output when I execute this code.
P3W1 COMM CNTRL ISAM 213 26961.61
P3W2 COMM CNTRL ISAM 213 12870.4
P3W3 COMM CNTRL ISAM 213 245.88
P3W1 COMM CNTRL ISAM 273 72831.2
P3W2 COMM CNTRL ISAM 273 8739.38
P3W3 COMM CNTRL ISAM 273 3764.92
P3W1 COMM CNTRL TAM 213 49844
P3W2 COMM CNTRL TAM 213 20515.17
P3W3 COMM CNTRL TAM 213 16167.46
P3W2 COMM CNTRL TAM 216 12561.4
P3W3 COMM CNTRL TAM 216 2027.1
P3W1 COMM CNTRL TAM 273 -3336.71
P3W2 COMM CNTRL TAM 273 -1376.68
P3W3 COMM CNTRL TAM 273 19707.42
P3W1 Damon Walters -609.07
P3W2 Damon Walters 30030.24
P3W3 Damon Walters 37475.1
This is the output I'd like to get
P3W1 COMM CNTRL ISAM 213 26961.61
P3W2 COMM CNTRL ISAM 213 12870.4
P3W3 COMM CNTRL ISAM 213 245.88
P3W4 COMM CNTRL ISAM 213
P3W5 COMM CNTRL ISAM 213
P3W1 COMM CNTRL ISAM 273 72831.2
P3W2 COMM CNTRL ISAM 273 8739.38
P3W3 COMM CNTRL ISAM 273 3764.92
P3W4 COMM CNTRL ISAM 273
P3W5 COMM CNTRL ISAM 273
P3W1 COMM CNTRL TAM 213 49844
P3W2 COMM CNTRL TAM 213 20515.17
P3W3 COMM CNTRL TAM 213 16167.46
P3W4 COMM CNTRL TAM 213
P3W5 COMM CNTRL TAM 213
P3W1 COMM CNTRL TAM 273 -3336.71
P3W2 COMM CNTRL TAM 273 -1376.68
P3W3 COMM CNTRL TAM 273 19707.42
P3W4 COMM CNTRL TAM 273
P3W5 COMM CNTRL TAM 273
P3W1 Damon Walters -609.07
P3W2 Damon Walters 30030.24
P3W3 Damon Walters 37475.1
P3W4 Damon Walters
P3W5 Damon Walters Edited by: polasa on Oct 28, 2008 6:42 PMSure, in a Single SQL ->
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
Elapsed: 00:00:00.01
satyaki>
satyaki>
satyaki>-- Start Of Test Data --
satyaki>with week_tab
2 as
3 (
4 select 1 period_num, 1 week_num, 10 bkg1 from dual
5 union all
6 select 1, 2, 40 from dual
7 union all
8 select 1, 3, 30 from dual
9 union all
10 select 1, 2, 20 from dual
11 union all
12 select 1, 1, 10 from dual
13 union all
14 select 1, 1, 20 from dual
15 union all
16 select 1, 3, 10 from dual
17 union all
18 select 2, 1, 15 from dual
19 union all
20 select 2, 2, 20 from dual
21 union all
22 select 2, 3, 10 from dual
23 union all
24 select 2, 1, 15 from dual
25 union all
26 select 2, 2, 30 from dual
27 union all
28 select 2, 3, 20 from dual
29 )
30 -- End Of Test Data --
31 select period_num,
32 week_num,
33 (
34 select sum(week_tab.bkg1)
35 from week_tab
36 where period_num = m.period_num
37 and week_num = m.week_num
38 group by week_num, period_num
39 ) sum_bkg1
40 from (
41 select dum.week_num,
42 wk.period_num
43 from (
44 select 1 week_num from dual
45 union all
46 select 2 from dual
47 union all
48 select 3 from dual
49 union all
50 select 4 from dual
51 union all
52 select 5 from dual
53 ) dum ,
54 (
55 select distinct period_num
56 from week_tab
57 ) wk
58 ) m;
PERIOD_NUM WEEK_NUM SUM_BKG1
1 1 40
1 2 60
1 3 40
1 4
1 5
2 1 30
2 2 50
2 3 30
2 4
2 5
10 rows selected.
Elapsed: 00:00:00.48
satyaki>Regards.
Satyaki De. -
How can I skip Null values from being part of sorting
Hi,
I am using ADF sorting for table, where i dont want to consider null values of that column when i do sorting . Now when I do ascending sort null values for that column are coming first and then the not null values are coming in ascending order.User,
Always mention your JDev version.
Now when I do ascending sort null values for that column are coming first and then the not null values are coming in ascending order.
.. which is expected. How would you want it to be? You may probably want to have a custom sortListener for the table and try out. Ex : Custom sort function in ADF table
-Arun -
How to avoid the null values from xml publisher.
I am creating a report which have the claim numbers with the values CLA001,CLA111,null, null . when i preview my report it is showing some spaces for null values also. How can i avoid the spaces from the report.
I am giving for loop for the claim numbers in the template.
<?for-each:ROW?> <?sort:CLAIMNUMBER;'ascending';data-type='text'?>
<?CLAIMNUMBER?>
<?end for-each?>
Please help me out to solve this problem.
Thanks,
vasanth.Hi Sheshu,
According to your description, you are experiencing the null values and infinity values when browser the calculated measure, right?
Based on my research, the issue is caused by that dividing a non-zero or non-null value by zero or null. In this cases, we need to check for division by zero to avoid this situation. Here is the sample query for you reference.
IIF(
Measures.[Measure B]=0,null,
Measures.[Measure A] / Measures.[Measure B]
If you have any questions, please feel free to ask.
Regards,
Charlie Liao
TechNet Community Support -
How can I delete null values from List Item?
Hi Friends,
I used List item for field job_Type, I entered values in List item at design time through property pallet. When I run form I will see null values in this List Item.
How can I remove these null values from the List?
Best regards,
ShahzadDear Shahzad,
It can be removed by adding the following code in the When-new-Form-Instance.
Set_item_property('List name', required, property_true);
:block_name.list_name := <put your default value here>; (If you didn't oput the default value, then you will get some problem and the cursor may not navigate away from the list).
Senthil Alagu .P. -
How to restrict the Null Values for Key Figules in the Bex Query
Hi Friends,
I want to restrict the Null values of a perticular key figure in the Bex Query Output.
I will explain in details. i have 3 key figures in my query.. let us assume.. key1 key2key3
key1 key2 key3
4 4 100.00
5 0 200.00
1 0 19.00
0 1 10.00
i don't want to see the the records for which key 2 is 0.
we have a setting in the Bex Query for restricting the Zero values in the query properties. If we enable that setting it will show
4 4 100.00
but i want the report to display..
4 4 100.00
0 1 10.00
can any body guide me. <b>i want to display the values if key2 <> 0.</b>
Regards,
Nagesh.Hi AVR,
nice to see reply.
can you eloborate your view...how can i put the condition.
<b>i want to put the condition key2 <> 0.</b>
Regards,
Nagesh. -
How can i pass NULL value in Store Procedure?
Hi guys,
I am calling one store procedure from MS SQL Server 200, i had create the follow layout:
But i need pass to MSQL SEVER the CPF = NULL, when i execute the procedre the CPF send empty value (not null).
I already changed Communication Channel parammeter "Interpretation of Empty String Values" to "Null Value" value.
But the interface always send empty string instead of null.
How can anybody help me, please?
Edited by: João Noberto dos Santos Junior on Jun 24, 2009 5:00 PMHi,
To achieve this through "Interpretation of Empty String Value" in the cc, you will have to implement a patch which is sent to you by SAP when an OSS is raised. By default its not available, i mean you can configure it but it will actually not work.
As a temporary solution you can map your element with a constant/mapwithdefault field with value mentioned as NULL.
Regards,
Anshul -
How to check for null values in bpel?? Please Help! very urgent!!!
Hello Guys,
I have a problem. I have an external webservice to which I have to post my request. My task is to create an Webservice and Service Assembly to which others would post request and get response. I have to create SA to deploy onto the bus.
The problem is that there are optional elements in the request and response xsd's. In the Response sometimes certain feilds may come or they may not. for Example:- my response could contain a tag like this <firstName></firstName>
I have to copy these feilds in my bpel process from one variable to another.(like in the mapper).
My Question is , Is there any way in BPEL process or BPEL mapper where I could Check for null values in the request or response???
Your inputs would be very helpful.
Thanks
RajeshThanks for replying man :)
Ok I will be more clear.
Here is a snippet of one of the xsd's that I am using.
<xs:element name="returnUrl" nillable="false" minOccurs="0">
<xs:annotation>
<xs:documentation>Partner specifies the return URL to which responses need to be sent to, in case of
Async message model.
</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:anyURI">
<xs:maxLength value="300"/>
<xs:whiteSpace value="collapse"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
This means that the return URL field can be there or it may not be there. But if it is there it cant be null because nillable=false. But the whole <returnURL> </returnURL> can be there or it may not be there because minOccurs=0.
My requirement is , if returnURL is there in the response with a value, then in my BPEL mapper I should map it else I should not map it.
Thats the issue.
and Yes kiran, the node be non-existant.
So can you please help me with this.
Thanks
Rajesh -
How to remove gaps/null values from set of columns in a row
Im trying to implement a solution for removing null value columns from a row.
Basically in below example i have five codes and corresponding id's for that codes.What im trying to achive here is if
i have a null code then i have to move next not null code and id into its new location.
Example:
'A1'cd1,'A2'cd2,null cd3,'A4'cd4,null cd5,'i1'id1,'i2'id2,null id3,'i4' id4,null id5 So here cd4 and id4 should take positions of cd3 and id3.
Output should look like this
cd1 cd2 cd3 cd4 cd5 id1 id2 id3 id4 id5
A1 A2 A4 i1 i2 i4Any help would be highly appreciated for below example:
with temp_table as
(select 'A1'cd1,'A2'cd2,null cd3,'A4'cd4,null cd5,'i1'id1,'i2'id2,null id3,'i4' id4,null id5 from dual union all
select 'A11',null,null,'A44','A55','id11',null,null, 'id44','id55' from dual union all
select null,'A111',null,null,'A555',null,'id111',null, null,'id555' from dual union all
select 'A',null,null,'A1111','E55','id11',null,null, 'id111','id1111' from dual )
select * from temp_table;Edited by: GVR on Dec 1, 2010 8:27 AMI like case expression B-)
The same question of my homepage http://www.geocities.jp/oraclesqlpuzzle/7-81.html
with temp_table(cd1,cd2,cd3,cd4,cd5,id1,id2,id3,id4,id5) as(
select 'A1' ,'A2' ,null,'A4' ,null ,'i1' ,'i2' ,null,'i4' ,null from dual union all
select 'A11',null ,null,'A44' ,'A55' ,'id11',null ,null,'id44' ,'id55' from dual union all
select null,'A111',null,null ,'A555',null ,'id111',null,null ,'id555' from dual union all
select 'A' ,null ,null,'A1111','E55' ,'id11',null ,null,'id111','id1111' from dual)
select
case when SumCD1 = 1 then CD1
when SumCD1+SumCD2 = 1 then CD2
when SumCD1+SumCD2+SumCD3 = 1 then CD3
when SumCD1+SumCD2+SumCD3+SumCD4 = 1 then CD4
when SumCD1+SumCD2+SumCD3+SumCD4+SumCD5 = 1 then CD5 end as CD1,
case when SumCD1+SumCD2 = 2 then CD2
when SumCD1+SumCD2+SumCD3 = 2 then CD3
when SumCD1+SumCD2+SumCD3+SumCD4 = 2 then CD4
when SumCD1+SumCD2+SumCD3+SumCD4+SumCD5 = 2 then CD5 end as CD2,
case when SumCD1+SumCD2+SumCD3 = 3 then CD3
when SumCD1+SumCD2+SumCD3+SumCD4 = 3 then CD4
when SumCD1+SumCD2+SumCD3+SumCD4+SumCD5 = 3 then CD5 end as CD3,
case when SumCD1+SumCD2+SumCD3+SumCD4 = 4 then CD4
when SumCD1+SumCD2+SumCD3+SumCD4+SumCD5 = 4 then CD5 end as CD4,
case when SumCD1+SumCD2+SumCD3+SumCD4+SumCD5 = 5 then CD5 end as CD5,
case when SumID1 = 1 then ID1
when SumID1+SumID2 = 1 then ID2
when SumID1+SumID2+SumID3 = 1 then ID3
when SumID1+SumID2+SumID3+SumID4 = 1 then ID4
when SumID1+SumID2+SumID3+SumID4+SumID5 = 1 then ID5 end as ID1,
case when SumID1+SumID2 = 2 then ID2
when SumID1+SumID2+SumID3 = 2 then ID3
when SumID1+SumID2+SumID3+SumID4 = 2 then ID4
when SumID1+SumID2+SumID3+SumID4+SumID5 = 2 then ID5 end as ID2,
case when SumID1+SumID2+SumID3 = 3 then ID3
when SumID1+SumID2+SumID3+SumID4 = 3 then ID4
when SumID1+SumID2+SumID3+SumID4+SumID5 = 3 then ID5 end as ID3,
case when SumID1+SumID2+SumID3+SumID4 = 4 then ID4
when SumID1+SumID2+SumID3+SumID4+SumID5 = 4 then ID5 end as ID4,
case when SumID1+SumID2+SumID3+SumID4+SumID5 = 5 then ID5 end as ID5
from (select cd1,cd2,cd3,cd4,cd5,id1,id2,id3,id4,id5,
nvl2(cd1,1,0) as SumCD1,
nvl2(cd2,1,0) as SumCD2,
nvl2(cd3,1,0) as SumCD3,
nvl2(cd4,1,0) as SumCD4,
nvl2(cd5,1,0) as SumCD5,
nvl2(id1,1,0) as SumID1,
nvl2(id2,1,0) as SumID2,
nvl2(id3,1,0) as SumID3,
nvl2(id4,1,0) as SumID4,
nvl2(id5,1,0) as SumID5
from temp_table)
order by cd1,cd2,cd3,cd4,cd5;
CD1 CD2 CD3 CD4 CD5 ID1 ID2 ID3 ID4 ID5
A A1111 E55 null null id11 id111 id1111 null null
A1 A2 A4 null null i1 i2 i4 null null
A11 A44 A55 null null id11 id44 id55 null null
A111 A555 null null null id111 id555 null null nullMy SQL articles of OTN-Japan
http://www.oracle.com/technology/global/jp/pub/jp/ace/sql_image/1/otnj-sql-image1.html
http://www.oracle.com/technology/global/jp/pub/jp/ace/sql_image/2/otnj-sql-image2.html -
How to give not null value in a rule for a field
hi,
i want to create a rule through rule designer where i want a field say "country" should not be left blank. when i go to the rule designer and select country through attribute value i get 2 conditions "=" and "!=" what shoud i give the value as so that the country field is not null.
TIAI don't think you can have null value in the rule designer , rather you can created one more UDF and populate this UDF with something based on the nulllness/not-null of the country field and use this new UDF in the rule .
Hope this helps .
Thanks
Suren -
How to update the null values to some number on the NUMBER type of column
Hello All,
I have one NUMBER type of column in DB table. It has some (null) values. I want to update with value 1. I tried to run the Update statement , It gives 0 rows updated.
SELECT objectid,attr20 FROM table;
object id attr20
====== ====
fff70b67-8d54-4ad7-bc57-7b40a0d8b219 (null)
cac5264a-b363-487b-bfe6-6b84d60064e9 (null)
2fc2a626-51d8-401c-9495-18aacd4c35c8 (null)
1b60bfa4-ff68-4488-adf6-2a83528c0e20 (null)
1c662829-24c1-4b3c-9289-0128e170c043 5
74f11331-545b-435f-bf4b-f57c7a6b4500 2
c941c1ac-a18e-47ec-843c-dbe2a5b51001 0
d7eba203-93c0-48ea-a109-9b06015ef387 0
eba72fa3-21d8-4489-bb93-917ebbd67de2 0
I ran following query but no success.
UPDATE eb_tcsservfnadoc SET attr20 = 1 WHERE attr20 = NULL
0 rows updated
UPDATE eb_tcsservfnadoc SET attr20 = 1 WHERE attr20 = null
0 rows updated
UPDATE eb_tcsservfnadoc SET attr20 = 1 WHERE attr20 = ''
0 rows updated
UPDATE eb_tcsservfnadoc SET attr20 = 1 WHERE attr20 =' '
Error starting at line 1 in command:
UPDATE eb_tcsservfnadoc SET attr20 = 1 WHERE attr20 =' '
Error report:
SQL Error: ORA-01722: invalid number
01722. 00000 - "invalid number"
*Cause:
*Action:
can some one help me out to update such values ????Hi,
"=" will not work for NULL values. Please remeber two NULL values are NOT same. Try IS operator.
UPDATE eb_tcsservfnadoc SET attr20 = 1 WHERE attr20 IS NULLRegards,
Avinash -
How to put the null value at the last of a select list
Hello,
I have a select list with a null value, I want the null value to be the last value in the list. It always appears in the top of the list, Desc and Asc order is not working.
Thank you in advance!
Edited by: Najla on Apr 1, 2013 10:37 PMHi,
Edited by: Howard (... in Training) on Apr 2, 2013 1:xx PM
The statement - I don't think it is possible to arrange the order of the null option in a select list.- is close. You can't control the order of the Null value if you add the Null value through the GUI. However, it can be added and controlled as part of a SELECT ...
One way is to add NULL to the "SELECT". Here the Yes/No are hard-coded but they could have been selected from a table:
select d, r from
select 'YES' d, 'Y' r from dual
union all
select 'No' d, 'N' r from dual
union all
select Null d, '<Null>' r from dual
) order by 1 desc NULLS lastHoward -
How to check for null value/field?
Hi!
I have created a form that is designed to calculate the rows using the FormCalc function.
My problem is that if I have no value in the some of the rows, a 0 is automatically display as the calculated output field. If a row has no data, how can I get a null or blank field in the result (calculated field) field?
Let's say, I have 5 rows and each row should have a calculated value in one of the fields; when I fill out only two of the rows, the remaining three rows come out with 0s in the calculated output field. I need a blank output field for the remaining calculated values instead of 0s. I am a newbie so please excuse me if I am not explaining well.
Thanks
Jofar1This is the value that I have on my calculate event: "Rate*Units_of_ServiceRow2".
How should/can I incorporate the two codes?
Maybe you are looking for
-
Java Browser Window (JDIC)
well im trying to make a browser, but when i run the project i get following error: Exception in thread "EventThread" java.lang.NullPointerException at org.jdesktop.jdic.browser.internal.MsgClient.<init>(Unknown Source) at org.jdeskto
-
IP mobility solution for a Data Centers
Hello guys Please give me an advice. Now I try to work out a networking solution for a two geo separated data centers (DCs). Both the data centers will contain a virtualised server infrastructure (VMware). Now the main design problem is to choose goo
-
Emoji Catastrophy (iPod 4th Gen iOs 6.1.3)
Emojis are pretty cool...except when it is the reason why nearly all my games and apps are crashing. I've never had this problem until the end of August. At first, it wasn't a big deal as emojis slowed down my iPod a little bit. I've realized that em
-
What you need to know before buying an antenna
Isn't it time you upgraded to an antenna? Wait- what? Upgrade to an antenna? Whether or not you're a cord cutter (meaning you've cancelled your monthly television service) you might find that adding an antenna to your entertainment viewing space can
-
Do AATC's get a free copy of Apple Remote Desktop?
I work at an AATC and I wanted to use Apple Remote Desktop in the classroom. They use to have a copy on ASW for download but I can't find it anymore. Does anyone have any information on how I can get it?