ORA 00907 Missing Right Parenthesis - oracle

I am getting this Error of "Missing Right Parenthesis" on the Query below. Can someone rectify the mistake please?
SELECT
DESCRIPTION,
TOTAL_ADMISSION,
EMERGENCY,
NORMAL
FROM TABLE (ORDERENTRY.PKG_S04REP00031.ADMISSION_SUMMARY(P_START_DATE = to_date('31/08/2021', 'dd/mm/yyyy')
P_END_DATE = to_date('01/09/2021', 'dd/mm/yyyy')
P_ADMISSION_TYPE = 'NORMAL'
/*P_ORDER_LOCATION_ID => :P_ORDER_LOCATION_ID, */
P_LOCATION_ID = 'K01'));

This should work
SELECT
DESCRIPTION,
TOTAL_ADMISSION,
EMERGENCY,
NORMAL
FROM TABLE (ORDERENTRY.PKG_S04REP00031.ADMISSION_SUMMARY(P_START_DATE => to_date('31/08/2021', 'dd/mm/yyyy') ,
P_END_DATE => to_date('01/09/2021', 'dd/mm/yyyy') ,
P_ADMISSION_TYPE => 'NORMAL' ,
--P_ORDER_LOCATION_ID => :P_ORDER_LOCATION_ID,
P_LOCATION_ID => 'K01')
);
You are using select from table(package.function, therefore
Parameters values in functions or packages follow the sign => not =
Parameters are separated by comma
I replaced /* */ just for --, just for cosmetic purposes, as both represent comments, but the later is more common when you want to comment just one line

Related

Data exists within database but doesnt show up on webi report

Hi I am building a v simple report as below; when I include the customer reference number and filter for another column (resolved time) being NULL then the number of incidents are reduced. (I know they exist within the database with the same filters)
(only INC1988464 is showing when more incidents should be showing)
Is there a way to test issues such as this in webi? Or a way to resolve this? Thanks in advance
Here is the sql used to make the report:
SELECT
'INC'||TRIM(to_char(ead_incident.incident,'0000000')),
ead_incident_credit.circuit_ref,
ead_incident_credit.customer_ref,
ead_incident_credit.data_rate,
ead_incident_credit.connection_type,
ead_incident_credit.completed_date,
ead_incident_credit.wholesaler_name,
ead_incident_credit.opened_datetime,
ead_incident_credit.resolved_datetime,
ead_incident_credit.resolution_details,
ead_incident_credit.resolution_duration_seconds,
ead_incident_credit.access_circuit_core_network,
ead_incident_credit.charge_amount,
ead_incident_credit.or_cost,
ead_incident_credit.sky_cost,
ead_incident_credit.service_credit_applicable,
ead_incident_credit.service_credit_due,
CASE WHEN COALESCE(COALESCE(ead_incident.actual_end_datetime,ead_incident.impact_end_datetime),ead_incident.resolved_datetime) IS NOT NULL THEN CASE WHEN ead_incident.impact_type = 'Full Outage' AND COALESCE(ead_incident.cause_classification,'') <> 'Resolved - No fault found' AND COALESCE(odwh_data.ead_within_sla('TTR',ead_incident.opened_datetime, COALESCE(COALESCE(ead_incident.actual_end_datetime,ead_incident.impact_end_datetime),ead_incident.resolved_datetime)),'f') = 'f' THEN 'Y' ELSE 'N' END ELSE NULL END,
CASE WHEN ead_incident.correlation = 't' THEN 'Y' ELSE 'N' END,
odwh_system.kpi_nextweek_startdate(),
odwh_system.kpi_currentweek_startdate()
FROM
odwh_data.ead_incident ead_incident INNER JOIN odwh_data.ead_incident_credit ead_incident_credit ON (ead_incident_credit.incident=ead_incident.incident)
WHERE
(
CASE WHEN COALESCE(COALESCE(ead_incident.actual_end_datetime,ead_incident.impact_end_datetime),ead_incident.resolved_datetime) IS NOT NULL THEN CASE WHEN ead_incident.impact_type = 'Full Outage' AND COALESCE(ead_incident.cause_classification,'') <> 'Resolved - No fault found' AND COALESCE(odwh_data.ead_within_sla('TTR',ead_incident.opened_datetime, COALESCE(COALESCE(ead_incident.actual_end_datetime,ead_incident.impact_end_datetime),ead_incident.resolved_datetime)),'f') = 'f' THEN 'Y' ELSE 'N' END ELSE NULL END = 'Y'
AND
(
CASE WHEN ead_incident.deleted = 't' THEN 'Y' ELSE 'N' END = 'N'
AND
(
CASE WHEN ead_incident.wholesaler = 't' THEN 'Y' WHEN ead_incident.wholesaler = 'f' THEN 'N' END = 'Y'
OR
CASE WHEN ead_incident.wholesaler = 't' THEN 'Y' WHEN ead_incident.wholesaler = 'f' THEN 'N' END Is Null
)
)
)
If you can create a free-hand SQL query which exhibits your issue like this...
SELECT
'INC1988464' AS [Incident Number]
, 'SKY-COLT-003' AS [Customer Reference]
, CONVERT (DATETIME, '2022-05-08 11:17:49') AS [Resovled Time]
UNION
SELECT
'INC1988464' AS [Incident Number]
, 'SKY-COLT-005' AS [Custome rReference]
, CONVERT (DATETIME, '2022-05-09 9:03:21') AS [Resovled Time]
UNION
SELECT
'INC1988464' AS [Incident Number]
, 'SKY-COLT-007' AS [Customer Reference]
, NULL AS [Resovled Time]
UNION
SELECT
'INC1988464' AS [Incident Number]
, 'SKY-COLT-009' AS [Customer Reference]
, CONVERT (DATETIME, '2022-05-09 10:17:02') AS [Resovled Time];
Then we can take that query, put it into a WebI report, replicate the issue, and possibly resolve it.
First and easiest thing to check. Do you have any filters already on your report page or are you starting on a brand new page? The filters may be against the page or the individual report block.
If you have, then remove them and see if the issue is resolved. Note that there may also be a ranking in there, returning the top 1 incidents.
If not, then there will be something in the report logic preventing the records from being returned. Comment out the where clauses and make sure to add the columns from the where clauses into your result set. From here you have two things to check:
1/ All rows are being returned
2/ You can see which rows are going to be filtered by your where clause based on what you see on your report based on your logic. You have nested case expressions which may not be doing what you expected for example.

Implementing the GROUP BY oracle query causing: not a GROUP BY expression in Ruby

My RUBY code executes a oracle query in the following way, but I seem to be getting the error:
Java::JavaSql::SQLSyntaxErrorException: ORA-00979: not a GROUP BY expression
SELECT
"REQUESTS".*
FROM
"REQUESTS"
WHERE
(
customer_id = 1
AND request_method != 'OPTIONS'
AND request_time BETWEEN TO_TIMESTAMP('2021-10-29 00:00:00', 'YYYY-MM-DD HH24:MI:SS')
AND TO_TIMESTAMP(
'2021-11-05 23:59:59.000999',
'YYYY-MM-DD HH24:MI:SS.FF'
)
)
GROUP BY
"REQUESTS"."REQUEST_TIME"
Initially the code which is translated into the above mentioned select query is:
requests = Request.where("customer_id = ? AND request_method != ? AND request_time BETWEEN TO_TIMESTAMP(?,'YYYY-MM-DD HH24:MI:SS') AND TO_TIMESTAMP(?,'YYYY-MM-DD HH24:MI:SS.FF')", customer.id, 'OPTIONS', start_time, end_time).group('date(request_time'))
The
.group('date(request_time') is translated in oracle to: GROUP BY date(request_time)
but it didn't seem to work either which was the original query, and the reason is because Oracle doesn't have this functionality , so I changed it and have been trying in differnt ways but can't seem to figure out why the group by expression wont work.
select * means "select all columns".
Group by clause says group by request_time, which is only one column, and that just won't work.
You'll have to apply group by to ALL columns (specified one-by-one), or - simpler - use select distinct.
Basically, we use group by when there's an aggregation in select column list. If there's none, you don't group by.
What you'll really do depends on what you want to do, i.e. which result you expect.

how to populate sysdate in apex_item.date_popup

i have created apex_item.datepopup() function to provide entry for user to select date from calendar, it should populate sysdate bydefault..
APEX_ITEM.DATE_POPUP (2,ROWNUM,ISSUED_DATE,'dd-mon-yyyy')
Try this:
APEX_ITEM.DATE_POPUP (2,ROWNUM, nvl(ISSUED_DATE, sysdate),'dd-mon-yyyy')
Directly copied from my code where I have it
APEX_ITEM.DATE_POPUP (p_idx => 2 , p_value => (CASE WHEN UPPER(cur_parameter.default) = 'SYSDATE' THEN SYSDATE WHEN UPPER(cur_parameter.default) != 'SYSDATE' AND cur_parameter.default IS NOT NULL THEN TO_DATE(cur_parameter.default) ELSE NULL END) , p_item_id => cur_parameter.name, p_date_format => cur_parameter.format , p_item_label => cur_parameter.name)
The CASE is because I keep the defaults stored in a table, and most of the time, the default date is sysdate, however, its viewed as a string and not SYSDATE. The cur_parameter is a row in a cursor.
If a call has more than one or two parameters, its always best to use named notation, avoids confusion and helps prevent mix ups.
APEX_ITEM.DATE_POPUP (p_idx =>2 , p_value => SYSDATE , p_item_id => ISSUED_DATE, p_date_format => 'DD-MON-YYYY') IssuedDate,

Issue while running a query within a procedure

I have a procedure that expects a SELECT statement as a parameter.
If I run the SELECT Statement out of the procedure, it runs fine, but when I run it within the procedure i get the error:
The procedure :
data_dump(query_in => 'select * from reservation where type not in ('H','PURGE','E') ',
file_in => 'export_'||months_from||''||months_to||'.csv',
directory_in => 'C:\Users\Administrator\Desktop\test',
delimiter_in => '|' );
The query itself gives me the expected result.
select * from reservation where type not in ('H','PURGE','E', '|| other ||')
The error is: encountered the symbol 'H'.
Can it be because of the single quotes around the IN condition?
getting error missing right parenthesis:
(trunc(a.update_date) between (select add_months(TRUNC(SYSDATE), -(]'|| months_from ||q'[') ) from dual) and (select add_months(TRUNC(SYSDATE), -(]'|| months_to ||q'[') from dual))]'
You're passing quoted arguments within a string. You need to either escape those internal quotes:
data_dump(query_in => 'select * from reservation where type not in (''H'',''PURGE'',''E'') ',
file_in => 'export_'||months_from||''||months_to||'.csv',
directory_in => 'C:\Users\Administrator\Desktop\test',
delimiter_in => '|' );
Or use the alternative quoting mechanism:
data_dump(query_in => q'[select * from reservation where type not in ('H','PURGE','E') ]',
...
With your 'other' value you need to still include that in its own escape quotes:
data_dump(query_in => 'select * from reservation where type not in (''H'',''PURGE'',''E'','''|| other ||''')',
...
or (getting less readable now, perhaps):
data_dump(query_in => q'[select * from reservation where type not in ('H','PURGE','E',']' || other || q'[')]',
...
You can use dbms_output to debug this sort of thing, printing the generated argument and seeing if that matches what you've been running manually.
With your third partial code you've put closing single quotes after the (presumably numeric) variables:
(trunc(a.update_date) between (select add_months(TRUNC(SYSDATE), -(]'|| months_from ||q'[') ) from dual) and (select add_months(TRUNC(SYSDATE), -(]'|| months_to ||q'[') from dual))]'
^ ^
and you are, as the message says, missing a closing parenthesis in the second add_month call; so it should be (where ... is the rest of the statement that you haven't shown):
q'[ ... (trunc(a.update_date) between (select add_months(TRUNC(SYSDATE), -(]'
|| months_from ||q'[) ) from dual) and (select add_months(TRUNC(SYSDATE), -(]'
|| months_to ||q'[) ) from dual))]'
Again, this is basic debugging you can do by printing the generated statement and inspecting it or trying to run it manually.
Also you don't need the inner select from dual stuff or all the parentheses; you can just do:
q'[ ... trunc(a.update_date) between add_months(TRUNC(SYSDATE), -]'
|| months_from ||q'[) and add_months(TRUNC(SYSDATE), -]'|| months_to ||q'[)]'

Split owner and object name in Oracle

Given an object identified by the form owner.tablename; how do I split the owner and table name up?
Both my ideas of either string tokenization or select owner, object_name from all_objects where owner || '.' || object_name = 'SCHEMA.TABLENAME' seem like hacks.
You can use DBMS_UTILITY.name_tokenize for this purpose.
This procedure calls the parser to parse the given name as "a [. b [.
c ]][# dblink ]". It strips double quotes, or converts to uppercase if
there are no quotes. It ignores comments of all sorts, and does no
semantic analysis. Missing values are left as NULL.
e.g.
DBMS_UTILITY.NAME_TOKENIZE
( name => 'SCHEMA.TABLENAME'
, a => v_schema
, b => v_object_name
, c => v_subobject -- ignore
, dblink => v_dblink
, nextpos => v_nextpos -- ignore
);
http://docs.oracle.com/cd/E11882_01/appdev.112/e40758/d_util.htm#BJEFIFBJ
SELECT SUBSTR('SCHEMA.TABLENAME', 0, INSTR('SCHEMA.TABLENAME', '.') - 1) OWNER,
SUBSTR('SCHEMA.TABLENAME', INSTR('SCHEMA.TABLENAME', '.') + 1) TABLE_NAME
FROM DUAL

Resources