System. Data. oracleclient. oracleexception: ORA-00979: Not a group by expression

Source: Internet
Author: User
Tags oracleconnection

Today, we have been entangled in this issue for a long time. In fact, this is not the first time we have made such a mistake. We have recorded it today to prevent another mistake.

In general, it is because of the errors generated by the oracleclient type conversion. The same correct SQL statement does not produce errors today, and may cause errors tomorrow. Combined with my personal error experience, the error mainly comes from the clustering function, which demonstrates how the error is generated:

First, the function for obtaining the data source is provided.

Public datatable orselect (string Str)
{
Datatable dt = new datatable ();
Oracleconnection conn = new oracleconnection ();
Conn. connectionstring = connectionstring;
Oracledataadapter adapter = new oracledataadapter (STR, Conn );
Try
{
Conn. open ();
Adapter. Fill (DT );
}
Catch (oracleexception ee)
{
Errorstring = ee. tostring ();
}
Finally
{
Conn. Close (); // close the connection
}
Return DT;
}

Then, you can call the function statement:

String selectsql = "select clusterid, AVG (AGE) from v_physics_storeaction group by clusterid ";

Datatable dt = conn. orselect (selectsql );

Why ?? Yes, but the results are unexpected. Three records can be obtained in PL/SQL, but there is only one statement in the preceding DT. Is this a bug ??

If you change selectsql to "select 1/3 from dual", is that right ?? However, it still reports an error. Now you may know where it is wrong! How can this problem be solved ??

In fact, it is very simple. You only need to change "select 1/3 from dual" to "select to_char (1/3) from dual". The problem is very simple, but if you are not familiar with oracleclient, it may be difficult for you to identify this error.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.