DB: SELECT query on a SQL View returns 0 results Follow
Issue: DB service runs a query that uses a view, returnings 0 array items.
The same service works fine returning 1+ results on a different machine (using same DB, same input).
Cause: the view might be depend on enviornment-specific variables.
Bellow is an example with a cause and solution, but the cause may be a different environment variable.
Investigating an example query
Example: Query bellow uses a view from EBS.
It returns 0 rows in ServiceManager, 2483 rows in SqlDeveloper and other machines:
SELECT organization_id, name FROM HR_ORGANIZATION_UNITS
Investigation:
- Run the following in SQL Developer to fetch the definition of the view:
SELECT TEXT FROM ALL_VIEWS WHERE VIEW_NAME = 'HR_ORGANIZATION_UNITS';
2. Inspect the definition: in this case we see that the WHERE clause uses USERENV('LANG')
:
It is an immediate suspect since this is an environment-specific value.
WHERE DECODE(HR_SECURITY.VIEW_ALL, 'Y', 'TRUE', HR_SECURITY.SHOW_RECORD('HR_ALL_ORGANIZATION_UNITS', HAOTL.ORGANIZATION_ID))='TRUE' AND decode(hr_general.get_xbg_profile, 'Y', hao.business_group_id, hr_general.get_business_group_id) = hao.business_group_id AND HAO.ORGANIZATION_ID = HAOTL.ORGANIZATION_ID AND HAOTL.LANGUAGE = USERENV('LANG')
3. Use the following queries in SQL&Java accordingly to find out whether your different machines use different USERENV('LANG')
values:
SELECT USERENV('LANG') AS lang, SYS_CONTEXT('USERENV','LANGUAGE') AS full_lang FROM DUAL;
SLogger.info("DISPLAY locale: " + Locale.getDefault(Locale.Category.DISPLAY)); SLogger.info("FORMAT locale: " + Locale.getDefault(Locale.Category.FORMAT));
4. If the above queries return incosistant languages (some 'US', some 'FR'), please check your OS language settings (Control Panel -> Time & language > Language & region):
In the screenshot bellow, change the regional format to "English (United States)" to fix the issue.
5. Restart your Tomcat / Weblogic server (the server, not just the ServiceManager.)
Comments
0 comments
Please sign in to leave a comment.