Search particular column using WITHIN operator in rewrite query template in Oracle Text - oracle-sqldeveloper

I have one query regarding usage of query template in oracle text.I am using below query but not able to figure out how to restrict it to particular column search , I tried using WITHIN operator but it is not considering it. Any help will be appreciated. Thanks.<query><textquery lang="ENGLISH" grammar="CONTEXT" >' || p_search ||'<progression><seq><rewrite>transform((TOKENS, "{", "}" within contact_name, " ")) </rewrite></seq><seq><rewrite>transform((TOKENS , "{", "}" within contact_name, " NEAR ")) </rewrite></seq><seq><rewrite>transform((TOKENS , "{", "}" within contact_name, "OR")) </rewrite></seq><seq><rewrite>transform((TOKENS , "fuzzy(", ", 50)" within contact_name, " ")) </rewrite></seq></progression></textquery><score datatype="FLOAT" algorithm="COUNT"/></query>
I am trying to use the above query template in Contains operator to fetch the results but I see it is scanning whole document instead of single node.(contact_name in my case) .
I have stored the data in JSON format in my master table.
Thanks.
select * from (select /*+ FIRST_ROWS(20) */ ccc.name
,ccc.value
,ccc.job_title
,ccc.customer_id
,ccc.contact_id
,score(0) score
,score(0) score0
from customer_contacts ccc
right join customers ccu
on ccu.customer_id = ccc.customer_id
where (contains(ccu.search_col_js, '<query>
<textquery lang="ENGLISH" grammar="CONTEXT" >' || :p_search ||'
<progression>
<seq><rewrite>transform((TOKENS, "{", "}" within contact_name, " ")) </rewrite></seq>
<seq><rewrite>transform((TOKENS , "{", "}" within contact_name, " NEAR ")) </rewrite></seq>
<seq><rewrite>transform((TOKENS , "{", "}" within contact_name, "OR")) </rewrite></seq>
<seq><rewrite>transform((TOKENS , "fuzzy(", ", 50)" within contact_name, " ")) </rewrite></seq>
</progression>
</textquery>
<score datatype="FLOAT" algorithm="COUNT"/>
</query>' ,0) > 1)
and :P1_SEARCH_CUSTOMER is not null
order by score desc
);

Related

aggregate function as tuple argument postgres

I want to pass aggregate function like min, max etc as query parameter using Tuple.
Below is my query:
"select $5(CAST (vol AS FLOAT)) AS agg_v, "
+ "time_bucket_gapfill" + "(($1::text || ' minutes')::interval, t) AS time_function_minute, "
+ "tag_id from rtdata "
+ "where tag_id = any($2) and t > $3 and t < $4 "
+ "GROUP BY (tag_id, time_function_minute) ORDER BY time_function_minute"
But I'm getting following exception:
io.vertx.pgclient.PgException: syntax error at or near
"("
at io.vertx.pgclient.impl.codec.ErrorResponse.toException(ErrorResponse.java:29)
at io.vertx.pgclient.impl.codec.PrepareStatementCommandCodec.handleErrorResponse(PrepareStatementCommandCodec.java:62)
at io.vertx.pgclient.impl.codec.PgDecoder.decodeError(PgDecoder.java:233)
at io.vertx.pgclient.impl.codec.PgDecoder.decodeMessage(PgDecoder.java:122)
at io.vertx.pgclient.impl.codec.PgDecoder.channelRead(PgDecoder.java:102)
at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1422)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:931)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:700)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:635)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:552)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:514)
at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1044)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:745)
But If I replace $5 with hardcode aggregate function it works. How can I pass aggregate function dynamically in this scenario?
RxJava code Snippet:
return txBegin()
.flatMapObservable(tx ->
tx.rxPrepare(abovesql)
.flatMapObservable(pq -> {
return pq.createStream(50,
Tuple.of(
evalBucketInterval(req),
req.getTags().toArray(new Integer[0]),
parse(req.getStartDate()),
parse(req.getEndDate()),
parse(req.getAggFunc())))
.toObservable();
})
.doAfterTerminate(tx::commit))
.map(this::toFuncJson);
PostgreSQL allows to use parameters only as values and doesn't understand when you try to use parameters for function names, table names, etc. So you cannot pass aggregate name as a parameter.
I suggest to work around it in your application by concatenating the string value containing the aggregate function name. I guess it can be something like, but I am not sure about the exact syntax and what limitations of your environment are:
"select "+ my_agg_func_name +"(CAST (vol AS FLOAT)) AS agg_v, "
+ "time_bucket_gapfill" + "(($1::text || ' minutes')::interval, t) AS time_function_minute, "
+ "tag_id from rtdata "
+ "where tag_id = any($2) and t > $3 and t < $4 "
+ "GROUP BY (tag_id, time_function_minute) ORDER BY time_function_minute"

ADO.NET working with SQL and database

I'm getting an exception error saying missing operators can anyone help
string sql = "Select SalesPerson.Name, Item.Description, Orders.Quantity, Orders.OrderDate"
+ "From([Orders]"
+ "Inner Join[SalesPerson] On Orders.SalesPersonID=SalesPerson.SalesPersonID)"
+ "Inner Join[Item] On Orders.ItemNumber=Item.ItemNumber"
+ "Where Orders.CustomerID=#customer Order by Orders.OrderDate DESC";
You need to add some spaces at the end of each of your lines of SQL!
string sql = "SELECT SalesPerson.Name, Item.Description, Orders.Quantity, Orders.OrderDate "
+ "FROM [Orders] "
+ "INNER JOIN [SalesPerson] ON Orders.SalesPersonID = SalesPerson.SalesPersonID "
+ "INNER JOIN [Item] ON Orders.ItemNumber = Item.ItemNumber "
+ "WHERE Orders.CustomerID = #customer "
+ "ORDER BY Orders.OrderDate DESC";
Otherwise, your SQL ends up being
Select ..... Orders.OrderDateFROM([Orders]Inner Join[SalesPerson] .....
and so on - and that's just not valid SQL.
I also removed some unnecessary parenthesis around the JOIN operators - those are only needed for MS Access, but since you're saying you're using ADO.NET, I assume this is not for MS Access and therefore, those parenthesis are not needed

how to replace comma in List of string in Jasper report

I have create one report with list of the string. The string got value parameter TO.REFOS_STATUS_CODE in ('10','ZZ','11','12','13'). i want to replace "," with ".". i have try the solution with my expression but it does'nt work.
The parameter expression is $P{refos_status}.equalsIgnoreCase("0") ?" ": " TO.REFOS_STATUS_CODE IN ( " +$P{refos_status}.replace( ',', '.' )+ ")".
Anyone know how to do that?
This is my query:
SELECT
TO.REFOS_STATUS_DESC_RPT ,
SUM(US.ENFUS_TOTAL_OFF_ACT) TOTAL
FROM TENF_RPT_UNSETTLE_SUMMACT US
INNER JOIN TREF_BRANCH B ON B.REFBR_BRANCH_ID = US.ENFUS_BRANCH
INNER JOIN TREF_STATE ST ON B.REFBR_STATE_CODE = ST.REFST_STATE_CODE
INNER JOIN TREF_OFFENCE_STATUS TO ON US.ENFUS_OFF_ACT =TO.REFOS_STATUS_CODE
WHERE
$P!{refos_status_1}
GROUP BY
TO.REFOS_STATUS_CODE,
TO.REFOS_STATUS_DESC_RPT
ORDER BY
TO.REFOS_STATUS_CODE,
TO.REFOS_STATUS_DESC_RPT

Insert hours and date in MS access via excel vba

I'm trying to insert this datas to MS Access via vba excel but I keep getting an error
dates = Cells(4, "E").Value ' contains 9/11/2013 '
hours= "7:30"
connDB.Execute "INSERT INTO DeptOrder (IDDept, DateIntervention, HourIntervention, bilaterale) VALUES (4, "& #dates# &" , "&hours&" , true)"
This the latest version of my query. The error message is "data type mismatch in criteria expression".
INSERT INTO DeptCommande
(IDDept, IDIntervention, DateIntervention, HeureIntervention, bilatérale, IDChirurgien, NumSalle)
VALUES ('5' , '574', #09-10-2013#, '0.322916666666667', 'True', '1', '4')
Thanks HansUp!!! I did remove all unecessay quotes and it's finally working. Sorry for the long query I wanted to post a short question by adding a few variables only.
VALUES (" & ledept & " , " & lintervention & ", #" & ladate & "#, " & heurevoulue & ", " & bilat & ", " & nomchiru & ", " & numeroSalle & ")"
Debug.Print strInsert
VALUES (5 , 574, #10-11-2014#, 0.322916666666667, True, 1, 4)

JPQL "DISTINCT" returns only one result

I am confused by DISTINCT in JPQL. I have two JPQL queries identical except for "DISTINCT" in one of them:
String getObjectsForFlow =
"SELECT " +
" se.componentID " +
"FROM " +
" StatisticsEvent se " +
"WHERE " +
" se.serverID IS NOT NULL " +
" AND se.flowID = :uuid " +
" AND se.componentID IS NOT NULL " +
"ORDER BY " +
" se.timeStamp desc ";
String getObjectsForFlowDistinct =
"SELECT DISTINCT " +
" se.componentID " +
"FROM " +
" StatisticsEvent se " +
"WHERE " +
" se.serverID IS NOT NULL " +
" AND se.flowID = :uuid " +
" AND se.componentID IS NOT NULL " +
"ORDER BY " +
" se.timeStamp desc ";
I run a little code to get the results from each query and dump them to stdout, and I get many rows with some duplicates for non-distinct, but for distinct I get only one row which is part of the non-distinct list.
NOT DISTINCT
::: 01e2e915-35c1-6cf0-9d0e-14109fdb7235
::: 01e2e915-35c1-6cf0-9d0e-14109fdb7235
::: 01e2e915-35d9-afe0-9d0e-14109fdb7235
::: 01e2e915-35d9-afe0-9d0e-14109fdb7235
::: 01e2e915-35bd-c370-9d0e-14109fdb7235
::: 01e2e915-35bd-c370-9d0e-14109fdb7235
::: 01e2e915-35aa-1460-9d0e-14109fdb7235
::: 01e2e915-35d1-2460-9d0e-14109fdb7235
::: 01e2e915-35e1-7810-9d0e-14109fdb7235
::: 01e2e915-35e1-7810-9d0e-14109fdb7235
::: 01e2e915-35d0-12f0-9d0e-14109fdb7235
::: 01e2e915-35b0-cb20-9d0e-14109fdb7235
::: 01e2e915-35a8-66b0-9d0e-14109fdb7235
::: 01e2e915-35a8-66b0-9d0e-14109fdb7235
::: 01e2e915-35e2-6270-9d0e-14109fdb7235
::: 01e2e915-357f-33d0-9d0e-14109fdb7235
DISTINCT
::: 01e2e915-35e2-6270-9d0e-14109fdb7235
Where are the other entries? I would expect a DISTINCT list containing eleven (I think) entries.
Double check equals() method on your StatisticsEvent entity class. Maybe those semantically different values returns same when equals() is called hence producing this behavior
The problem was the "ORDER BY se.timeStamp" clause. To fulfill the request, JPQL added the ORDER BY field to the SELECT DISTINCT clause.
This is like a border case in the interplay between JPQL and SQL. The JPQL syntax clearly applies the DISTINCT modifier only to se.componentID, but when translated into SQL the ORDER BY field gets inserted.
I am surprised that the ORDER BY field had to be selected at all. Some databases can return a data set ORDERed by a field not in the SELECTion. Oracle can do so. My underlying database is Derby -- could this be a limitation in Derby?
Oracle does not support SELECT DISTINCT with an order by unless the order by columns are in the SELECT. Not sure if any databases do. It will work in Oracle if the DISTINCT is not required (does not run because rows are unique), but if it needs to run you will get an error.
You will get, "ORA-01791: not a SELECTed expression"
If you are using EclipseLink this functionality is controlled by the DatabasPlatform method,
shouldSelectDistinctIncludeOrderBy()
You can extend your platform to return false if your database does not require this.
Still, I don't see how adding the TIMESTAMP will change the query results?
Both queries are incorrect JPQL queries, because ORDER BY clause refers to the item that is not on select list. JPA 2.0 specification contains example that matches to this case:
The following two queries are not legal because the orderby_item is
not reflected in the SELECT clause of the query.
SELECT p.product_name
FROM Order o JOIN o.lineItems l JOIN l.product p JOIN o.customer c
WHERE c.lastname = ‘Smith’ AND c.firstname = ‘John’
ORDER BY p.price
SELECT p.product_name
FROM Order o, IN(o.lineItems) l JOIN o.customer c
WHERE c.lastname = ‘Smith’ AND c.firstname = ‘John’
ORDER BY
o.quantity
Of course it would be nicer if if implementation could give clear error message instead of trying to guess what is expected result of incorrect query.