SQL Query converted to PL/SQL?
I am trying to get my sql query here (which works) converted over to a pl/sql function so I can use an IF / THEN statement to determine whether my 2nd search field has been submitted with something in it.
My current query:
select
comm_Devices.ID,
comm_Devices.PhonePager,
comm_Devices.FirstName,
comm_Devices.LastName,
comm_Devices.Vendor,
comm_DeviceType.Device,
comm_Devices.PhoneNo,
comm_Devices.Location,
comm_Vendors.VendorName
from comm_Devices
Inner Join comm_DeviceType
on comm_Devices.DeviceTypeID = comm_DeviceType.ID
Inner Join comm_Vendors
on comm_Vendors.vendorId = comm_Devices.vendor
where
comm_Devices.LastName LIKE '%' || upper(:P1_SEARCH_LAST_NAME) || '%'
and comm_Vendors.VendorName LIKE '%' || upper(:P1_SEARCH_VENDOR) || '%'
What I am wanting to do is convert it to pl/sql so I can do this:
if :P1_SEARCH_VENDOR != '' then
q:=q||'and comm_Vendors.VendorName LIKE '%' || upper(:P1_SEARCH_VENDOR) || '%';
end if;
Any help would be greatly appreciated!
You are fairly close to figuring this out. Basically you want to create a Quesry Region of type :SQL Query (Pl/SQL Function Body Returning Sql Query).
Then as most of the Dynamic query examples shouw you would do something like
declare
q varchar2(32767); -- query
w varchar2(4000); -- where clause
we varchar2(1) :='N'; -- identifies if where clause exists
begin
q := 'select "comm_Devices"."ID", ' ||
' "comm_Devices"."PhonePager", ' ||
' "comm_Devices"."FirstName",' ||
' "comm_Devices"."LastName", ' ||
' from "comm_Devices" ' ||
' Inner Join "comm_DeviceType" on "comm_Devices"."DeviceTypeID" = "comm_DeviceType"."ID" ' ||
' Inner Join "comm_Vendors" on "comm_Vendors"."vendorId" = "comm_Devices". "vendor" ';
if :P1_SEARCH_VENDOR != '' then
w := "where statement";
we := 'Y';
END IF;
IF we = 'Y' THEN
q := q || w;
END IF;
return q;
end;
This should get you started.
James
Message was edited by:
[email protected]
Similar Messages
-
I'm attempting to dynamically generate a rather large SQL query via the "PL/SQL function body returning SQL query" report region option. The SQL query generated will possibly be over 32K. When I execute my page, I sometimes receive the "ORA-06502: PL/SQL: numeric or value error" which points to a larger than 32K query that was generated. I've seen other posts in the forum related to this dynamic SQL size limitation issue, but they are older (pre-2010) and point to the 32K limit of the DNS (EXECUTE IMMEDIATE) and DBMS_SQL. I found this post (dynamic sql enhancements in 11g) which discusses 11g no longer having the 32K size limitation for generating dynamic SQL. Our environment is on 11gR2 and using ApEx 4.2.1. I do not know which dynamic SQL method -- DNS or DBMS_SQL -- ApEx 4.2.1 is using. Can someone clarify for me which dynamic SQL method ApEx uses to implement the "PL/SQL function body returning SQL query" option?
As a test, I created a page on apex.oracle.com with a report region with the following source:
declare
l_stub varchar2(25) := 'select * from sys.dual ';
l_sql clob := l_stub || 'union all ';
br number(3) := 33;
begin
while length ( l_sql ) < 34000 loop
l_sql := l_sql || l_stub || 'union all ';
end loop;
l_sql := l_sql || l_stub;
for i in 1 .. ceil ( length ( l_sql ) / br ) loop
dbms_output.put_line ( dbms_lob.substr ( l_sql, br, ( ( i - 1 ) * br ) + 1 ) );
end loop;
return l_sql;
end;
The dbms_output section is there to be able to run this code in SQL*Plus and confirm the size of the SQL is indeed larger than 32K. When running this in SQL*Plus, the procedure is successful and produces a proper SQL statement which can be executed. When I put this into the report region on apex.oracle.com, I get the ORA-06502 error.
I can certainly implement a work-around for my issue by creating a 'Before Header' process on the page which populates an ApEx collection with the data I am returning and then the report can simply select from the collection, but according to documentation, the above 32K limitation should be resolved in 11g. Thoughts?
Shane.What setting do you use in your report properties - especially in Type and in Region Source?
If you have Type="SQL Query", then you should have a SELECT statement in the Region Source. Something like: SELECT .... FROM ... WHERE
According to the ERR-1101 error message, you have probably set Type to "SQL Query (PL/SQL function body returning SQL query)". In this situation APEX expects you to write a body of a PL/SQL function, that will generate the text of a SQL query that APEX should run. So it can be something like:
declare
mycond varchar2(4000);
begin
if :P1_REPORT_SEARCH is not null THEN
mycond:='WHERE LAST_NAME like :P1_REPORT_SEARCH ||''%''';
end if;
return 'select EMPLOYEE_ID, FIRST_NAME, LAST_NAME from EMPLOYEES ' ||mycond;
end;
And for escaping - are you interested in escaping the LIKE wildcards, or the quotes?
For escaping the wildcards in LIKE function so that when the user enters % you will find a record with % and not all functions, look into the SQL Reference:
http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/conditions007.htm
(You would than need to change the code of your function accordingly).
If you are interested in escaping the quotes, try to avoid concatenating the values entered by the user into the SQL. If you can, use bind variables instead - as I have in my example above. If you start concatenating the values into the text of SQL, you are open to SQLInjection - user can enter anything, even things that will break your SQL. If you really need to allow users to choose the operator, I would probably give them a separate combo for operators and a textfield for values, than you could check if the operator is one of the allowed ones and create the condition accordingly - and than still use bind variable for inserting the filtering value into the query. -
SQL Query Works in MS SQL Server 2008 but not when using Database Toolkit
I have this SQL query:
DECLARE @DataTypeTable TABLE (
Name varchar(128),
TypeID INT)
--Add comma delimeted data type names to temp table
INSERT INTO @DataTypeTable (Name)
SELECT * FROM WhatWeShouldDoRead.func_Split(@DataTypeTrimmed,',')
SELECT Name FROM @DataTypeTable
Which takes a comma delimited string and returns the string as a table. It works correctly in Microsoft SQL Server Management Studio. When I run this as a stored procedure I get back nothing. There are no errors, SQL or otherwise. I've verified that I am connected to the correct database and that the stored procedure is loaded by changing the no error string that is reported from this stored procedure (that code is not shown in the above example). Has anyone seen this problem before, or have any experiance with SQL/Labview interfaces to tell me what I'm doing wrong?
Thanks in advance.
Solved!
Go to Solution.After doing some more research it appears that the database toolkit cannot interface with any table results from any type of temp table. It may have to do with the fact that MS SQL 2008 stores temp tables in a seperate database (tempdb) and not the database you are currently connected to. See this link for a good artical on temp tables:
http://databases.aspfaq.com/database/should-i-use-a-temp-table-or-a-table-variable.html
If possible, I'd like a someone to prove me wrong, but for now will have to settle for exporting the contents of a temp table through a string. -
SQL query generating data in SQL management studio but not in CUIC interface
Hello,
I'm working on a UCCE 9.0 system
I created SQL query for a report.
Whenever I run the query inside the SQL management studio, it works and generates data, but when I run it in the CUIC interface it works but generates nothing. As you can see in the below snapshot, it contains 209 records that are not being displayed.
Any help would be greatly apprciatedIs it a custom report ? Can you right click on your Custom Report and click on Edit Views. You need to check whether you have Grid Headers Listed.
Regards,
Senthil -
Hello,
I am trying to do the below pl/sql block in a single SQL stm, let me know how could we achieve it.
Here i am using SELECT * FROM TEMP_ORDER WHERE DB_NAME = V_DBNAME which runs a cursor for get the distinct data base names.
could this V_DBNAME be avoided ? and everything put into a single SQL ?
(The PL/SQL block does not get execute properly since many rows are returned) I would be interested in the SQL solution.
create table TEMP_ORDER
ORD1 VARCHAR2(25),
ORD2 VARCHAR2(25),
DB_NAME VARCHAR2(25)
INSERT INTO TEMP_ORDER(ORD1,ORD2,DB_NAME) VALUES('A1','FIRST ORDER','DB1');
INSERT INTO TEMP_ORDER(ORD1,ORD2,DB_NAME) VALUES('A2','SECOND ORDER','DB2');
INSERT INTO TEMP_ORDER(ORD1,ORD2,DB_NAME) VALUES('A3','THIRD ORDER','DB1');
create table TEMP_PAYMENT
PAY1 VARCHAR2(25),
PAY2 VARCHAR2(25),
DB_NAME VARCHAR2(25)
INSERT INTO TEMP_PAYMENT(PAY1,PAY2,DB_NAME) VALUES('A1','FIRST PAYMENT','DB1');
INSERT INTO TEMP_PAYMENT(PAY1,PAY2,DB_NAME) VALUES('A2','SECOND PAYMENT','DB2');
INSERT INTO TEMP_PAYMENT(PAY1,PAY2,DB_NAME) VALUES('A3','THIRD PAYMENT','DB1');
create table TEMP_DELIVER
DEL1 VARCHAR2(25),
DEL2 VARCHAR2(25),
DB_NAME VARCHAR2(25)
INSERT INTO TEMP_DELIVER(DEL1,DEL2,DB_NAME) VALUES('A1','FIRST DELIVER','DB1');
INSERT INTO TEMP_DELIVER(DEL1,DEL2,DB_NAME) VALUES('A2','SECOND DELIVER','DB2');
INSERT INTO TEMP_DELIVER(DEL1,DEL2,DB_NAME) VALUES('A3','THIRD DELIVER','DB1');
DECLARE
V_DBNAME TEMP_ORDER.DB_NAME%TYPE;
V_ORDER_NAME TEMP_ORDER.ORD2%TYPE;
V_PAYMENT_NAME TEMP_PAYMENT.PAY2%TYPE;
V_DELIVER_NAME TEMP_DELIVER.DEL2%TYPE;
CURSOR DBCURSOR IS SELECT UNIQUE DB_NAME from TEMP_ORDER;
BEGIN
IF NOT DBCURSOR%ISOPEN THEN
OPEN DBCURSOR;
END IF;
LOOP
FETCH DBCURSOR INTO V_DBNAME;
EXIT WHEN DBCURSOR%NOTFOUND;
SELECT A.ORD2,
B.PAY2,
C.DEL2 INTO V_ORDER_NAME,V_PAYMENT_NAME,V_DELIVER_NAME
FROM
(SELECT * FROM TEMP_ORDER WHERE DB_NAME = V_DBNAME)A,
(SELECT * FROM TEMP_PAYMENT WHERE DB_NAME = V_DBNAME)B,
(SELECT * FROM TEMP_DELIVER WHERE DB_NAME = V_DBNAME)C
WHERE
A.ORD1 = B.PAY1 AND
B.PAY1 = C.DEL1;
DBMS_OUTPUT.put_line(V_ORDER_NAME || ':' || V_PAYMENT_NAME || ':' || V_DELIVER_NAME);
END LOOP;
CLOSE DBCURSOR;
END;Hi,
Thanks for posting the CREATE TABLE and INSERT statements; that's very helpful. Don't forget to post the results you want from that sample data.
I think you want something like this:
SELECT o.*
, p.pay2
, d.del2
FROM temp_order o
JOIN temp_payment p ON o.ord1 = p.pay1
AND o.db_name = p.db_name
JOIN temp_deliver d ON o.ord1 = d.del1
AND o.db_name = d.db_name
WHERE o.db_name = 'DB1'
;Output (with parameter 'DB1', as hard-coded above):
ORD1 ORD2 DB_NAME PAY2 DEL2
A1 FIRST ORDER DB1 FIRST PAYMENT FIRST DELIVER
A3 THIRD ORDER DB1 THIRD PAYMENT THIRD DELIVERWhat if matching data is found in 1 or 2 of the tables, but not all 3? You may need to use outer joins where I used inner joins, above. -
SQ01 DIsplay Problem (Can v write abap code ) Sql Query
Hi
Need help in SQL Query
I generated one sql query which has the following output in general .
Customer name description amount
asrq1 sharekhan Amount payed 10
asrq1 sharekhan Amount Advance 20
asrq1 sharekhan Amount due 30
but i need the output in the following way
Customer name AMount payed Amount Advance Amount Due
asrq1 sharekhan 10 20 30
and iam new this sql query but came to know we can write code ..but iam unable to initiliaze to write
a peace of code as i dont know what are the select-options defined ..i saw in the include but didnt got it
% comes prefix of select-options,and iam unable to get he internal table which is displayed in the query .
can anyone help me in this answers will be awarded points.First, I will suggest to go for ABAP report for this kinda requirement.
If you really want to go for it through SQ01, even then you will have to write some ABAP to display the records in one row. You will need to create three custom fields.
I will give Psudo for one field:
Field Name := ZAmountPayed
Select Amount_Payed into varAmountPayed from Table Where Emp# = '12345'
ZAmountPayed := varAmountPayed
Convert the above into relative ABAP code and create 2 more similar fields, and you should be all set.
You have to know the table names and any other calculations to get the right data. -
Informix / SQL Query to calculate Service Level Met %
Hi,
We have a client running UCCX 7.0 and we are upgrading it to 8.5.
They have a custom .net application that display different stats on IP Phone. I have converted all of them except i am having problem calculating Service Level Met %
Existing SQL query converts boolean into Float but Informix gives error that boolean can't be converted to float or integer.
here is part of existing query (SQl Server) to calculate service level met %
ROUND((SUM(CAST(ssl.metServiceLevel AS FLOAT))/COUNT(CAST(ssl.metServiceLevel AS FLOAT))) * 100,2) AS serviceLevelMet
I will greatly appreciate if anyone can help converting this query into Informix query format.
Thank youHi Sonain
Try this, it won't display a service level until you have received at least one call on the CSQ.
SELECT csqsum.CSQName,loggedInAgents,talkingAgents,availableAgents,workingAgents,reservedAgents,servicelevel
FROM RtCSQsSummary csqSum left outer join
(SELECT csqname, ROUND(sum(100 * (MetSL)/ (case when (MetSL + NotSL = 0) then 1 else (MetSL + NotSL) end)) ) as servicelevel
FROM(
SELECT
trim( csqname) csqname
,sum( case cqd.metServiceLevel when 't' then 1 else 0 end) MetSL
,sum( case cqd.metServiceLevel when 't' then 0 else 1 end) NotSL
FROM ContactServiceQueue csq
inner join contactqueuedetail cqd on cqd.targetID = csq.recordID
inner join contactroutingdetail crd on crd.sessionID = cqd.sessionID
inner join contactcalldetail ccd on crd.sessionID = ccd.sessionID
WHERE Date(current) - Date(crd.StartDateTime ) = 0
GROUP BY csqname
)z
GROUP BY z.csqname
)y
ON y.CSQName = csqsum.CSQName
Please rate helpfull posts.
Graham -
SQL query with Java Server Pages
Hey,
I'm trying to read some information from database with SQL Query. How I can put the parameter that I get from previous *.jsp page to SQL query?
Technologies that I use are WML, JSP and MySQL.
I can get the parameter by method getParameter() and it is correct.
But how to but the requested parameter into sql query and complete the sql query?
Should I read it to some variable before putting it to sql query?
*/ this works fine */
out.println("<p>periodi"+request.getParameter("periodi"+"loppu</p>");
/* this doesn't work */
ResultSet tulokset = lause.executeQuery("select * from kurssi where periodi='+request.getParameter("periodi")+'");
/* this doesn't work */
String periodi=request.getParameter("periodi");
ResultSet tulokset = lause.executeQuery("select * from kurssi where periodi='periodi' '");
Thanks,
RampeHey,
I'm trying to read some information from database
se with SQL Query. How I can put the parameter that I
get from previous *.jsp page to SQL query?
Technologies that I use are WML, JSP and MySQL.
I can get the parameter by method getParameter()
() and it is correct.
But how to but the requested parameter into sql
ql query and complete the sql query?
Should I read it to some variable before putting it
it to sql query?
*/ this works fine */
out.println("<p>periodi"+request.getParameter("periodi"
"loppu</p>");
/* this doesn't work */
ResultSet tulokset = lause.executeQuery("select * from
kurssi where
periodi='+request.getParameter("periodi")+'");
/* this doesn't work */
String periodi=request.getParameter("periodi");
ResultSet tulokset = lause.executeQuery("select *
* from kurssi where periodi='periodi' '");
Thanks,
RampeTry this
ResultSet tulokset = lause.executeQuery("select * from kurssi where periodi=" + "'" +request.getParameter("periodi")+"' " );this should work -
How Can I Change the Where Condition In the First SQL Query?
SELECT IND_SSN, BEG_SVC_DT, END_SVC_DT,
TRUNC(MONTHS_BETWEEN((TO_DATE('19'||END_SVC_DT,'YYYYMMDD')),BEG_SVC_DT)/12),
mod(trunc(months_between((to_date('19'||end_svc_dt,'YYYYMMDD')),BEG_SVC_DT)),12),
DECODE((SUBSTR(END_SVC_DT,5,2) - SUBSTR(BEG_SVC_DT,1,2)+1),-1,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-2,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-3,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-4,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-5,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-6,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-7,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-8,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-9,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-10,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-11,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-12,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-13,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-14,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-15,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-16,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-17,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-18,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-19,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-20,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-21,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-22,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-23,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-24,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-25,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-26,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-27,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-28,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-29,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-30,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
-31,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
30,0,
(SUBSTR(END_SVC_DT,5,2) - SUBSTR(BEG_SVC_DT,1,2)+1))
FROM SVC_OCCURRENCES
WHERE end_svc_dt not in ('PRESENT')
AND SUBSTR(END_SVC_DT,1,1) IN '9'
AND SUBSTR(END_SVC_DT,5,2) NOT IN ('31')
and (SUBSTR(END_SVC_DT,5,2) - SUBSTR(BEG_SVC_DT,1,2)+1) not in ('30')
UNION
SELECT IND_SSN, BEG_SVC_DT, END_SVC_DT, NULL, NULL, NULL
FROM SVC_OCCURRENCES
WHERE SUBSTR(END_SVC_DT,1,1) IN 'P'
The above code works fine and I get the correct numeric values from the SQL
query when the varchar2 end_svc_dt field is numeric however if I have encoded
the word 'PRESENT' in the varchar2 end_svc dt field the SQL query aborts at
the last statement in the WHERE condition. The beg_svc_dt field is a Date field.
and (SUBSTR(END_SVC_DT,5,2) - SUBSTR(BEG_SVC_DT,1,2)+1) not in ('30')
I get the following error message
ERROR ORA-0722 INVALID NUMBER
I encode the word 'PRESENT' in a varchar2 end_svc_dt field on an Oracle form. This is the only word that can be encoded.
Is there some way that I can bypass the last statement in the where condition and
compute the values from the SQL query without having the SQL query abort?
Eventually I want to do this in a report. I know that this sounds strange but can it be done?The above code works fine and I get the correct
numeric values from the SQL
query when the varchar2 end_svc_dt field is numeric
however if I have encoded
the word 'PRESENT' in the varchar2 end_svc dt field
the SQL query aborts at
the last statement in the WHERE condition.Ouch!
Storting dates in VARCHAR2 columns is bad practice, poor design and makes for horrible code.
The beg_svc_dt field is a Date field.
and (SUBSTR(END_SVC_DT,5,2) -
SUBSTR(BEG_SVC_DT,1,2)+1) not in ('30')If it's a date field then why on earth are you trying to SUBSTR it. SUBSTR = sub-string i.e. take a sub section of a string not sub-date.
I get the following error message
ERROR ORA-0722 INVALID NUMBERAnd you're surprised by this?
Is there some way that I can bypass the last
statement in the where condition and
compute the values from the SQL query without having
the SQL query abort?Store your dates properly, use additional flag columns for non-date information and code your SQL properly.
Eventually I want to do this in a report. I know
that this sounds strange but can it be done?Yes, most things are possible. -
SQ01, SQ01 - Sql Query Dislplay problem
Hi
Need help in SQL Query
I generated one sql query which has the following output in general .
Customer name description amount
asrq1 sharekhan Amount payed 10
asrq1 sharekhan Amount Advance 20
asrq1 sharekhan Amount due 30
but i need the output in the following way
Customer name AMount payed Amount Advance Amount Due
asrq1 sharekhan 10 20 30
and iam new this sql query but came to know we can write code ..but iam unable to initiliaze to write
a peace of code as i dont know what are the select-options defined ..i saw in the include but didnt got it
% comes prefix of select-options,and iam unable to get he internal table which is displayed in the query .
can anyone help me in this answers will be awarded points.and transaction FBL5N does not work in your company because ... ???
-
Hi ,
I need some help, pls.
The follwg report runs in SQL Workshop - but gives errors in the sql-query report in HTMLDB:
SQL-Workshop:
select
case
when SUM(S.POTENTIAL_GROWTH)> 1 and SUM(S.POTENTIAL_GROWTH) < 4 then 'Ok'
when SUM(S.POTENTIAL_GROWTH)> 4 and SUM(S.POTENTIAL_GROWTH) < 8 then 'SoSo'
when SUM(S.POTENTIAL_GROWTH)> 8 and SUM(S.POTENTIAL_GROWTH) < 12 then 'Very Good'
else 'too much'
end
from "SEGMENTATION" S
In an HTMLDB SQL-Query Report I added Aliases (as requested for HTML) but still gives the error:
<<Query cannot be parsed, please check the syntax of your query. (ORA-00920: invalid relational operator) >>
the code:
select
case
when SUM(S.POTENTIAL_GROWTH) pot_growth > 1 and SUM(S.POTENTIAL_GROWTH)pot_growth < 4 then 'Ok'
when SUM(S.POTENTIAL_GROWTH)pot_growth > 4 and SUM(S.POTENTIAL_GROWTH)pot_growth < 8 then 'SoSo'
when SUM(S.POTENTIAL_GROWTH)pot_growth > 8 and SUM(S.POTENTIAL_GROWTH)pot_growth < 12 then 'Very Good'
else 'too much'
end
from "SEGMENTATION" S
any halp from the gurus wud be very much appreciated.
TIA
BernhardStill you did not give the alias for the case when column. For that only you should give the alias
select
case
when SUM(S.POTENTIAL_GROWTH) pot_growth > 1 and SUM(S.POTENTIAL_GROWTH)pot_growth < 4 then 'Ok'
when SUM(S.POTENTIAL_GROWTH)pot_growth > 4 and SUM(S.POTENTIAL_GROWTH)pot_growth < 8 then 'SoSo'
when SUM(S.POTENTIAL_GROWTH)pot_growth > 8 and SUM(S.POTENTIAL_GROWTH)pot_growth < 12 then 'Very Good'
else 'too much'
end "GROWTH"
from "SEGMENTATION" S -
ORA-06502 on 'SQL query' report with sort in 'Report Attributes'
Hi All,
We get the next error if we set sorting on a column in a 'Report' based on a 'SQL query'. Removing the sort, error disappeares:
failed to parse SQL query:
ORA-06502: PL/SQL: numeric or value error: NULL index table key value
Any suggestions?
ErikErik,
Thanks, this explains it. By specifying the request as part of your URL you run into the recently uncovered issue. The request you're setting is REMFROMLIST and ADD2LIST. You probably either have links that include those requests or you have branches where you specify them. Either way, in order to get reports sorting to work, you'll have to make sure that the request strings are not part of your URL. This is a work-around and the upcoming HTML DB patch release will solve this issue.
One way of avoiding this is to have computations on the previous pages that set a napplication level or page level item to the REMFROMLIST and ADD2LIST values and then you can use those items for your conditions that are currently evaluating those strings.
Hope this helps and sorry for the inconvenience,
Marc -
Dynamic SQL Query to Find Special Characters in Table columns
Hi,
I am new to OTN FORUMS.
I am trying to find the columnsi of a table which have special characters in them.
I am planning on using this query
select ' select INSTR('||column_name||', chr(0))
from '||table_name||'where INSTR('||column_name||', chr(0)) >0' from user_tab_columns
where table_name='Account'
and spool the output to run as a script.
Is this the right way or do u suggest any modifications to the query?
Thanks in advance.Hi,
I think your basic approach is right. Since you can't hard-code the table- or column names into the query, you'll need dynamic SQL.
Instead SQL-from-SQL (that is, writing a pure SQL query, whose output is SQL code), you could do the whole job in PL/SQL, but I don't see any huge advantage either way.
When you say "Special character<b>s</b>", do you really mean "one given special character" (in this case, CHR(0))?
Will you ever want to search for multiple special characters at once?
What if table foo has a column bar, and in 1000 rows of foo, bar contains CHR (0). Do you want 1000 rows of output, each showing the exact position of the first CHR(0)? If the purpose is to look at theese rows later, shouldn't you include the primary key in the output? What if CHR(0) occurs 2 or more times in the same string?
If you'd rather have one row of output, that simply says that the column foo.bar sometimes contains a CHR(0), then you could do something like this:
SELECT 'foo', 'bar'
FROM dual
WHERE EXISTS (
SELECT NULL
FROM foo
WHERE INSTR ( bar
, CHR (0)
) > 0
); -
SQL query issue, how to improve it?
Hello all, I want to create a query with with result in the following result. Every first person of an department starts with the letter A and goes up like this:
Name department
A Person1 3
B Person2 3
C Person3 3
D Person4 3
E Person10 3
A Person6 10
B Person7 10
C Person8 10
A Person4 13
B Person9 13
It has to be a SQL query, unfortunately no PL/SQL
I was able to create this query, but its lacking. Department_id will be a variable, a person can choose one department or several departments, so the query varies in size.
select chr(64+rownum), name, department_id
from ( select name, department_id
from employees
where department_id = 3
order by id_but, naam
union
select chr(64+rownum), name, department_id
from ( select name, department_id
from employees
where department_id = 10
order by id_but, naam
union
select chr(64+rownum), name, department_id
from ( select name, department_id
from employees
where department_id = 13
order by id_but, naam
order by id_but, naam
The employees table has the following columns:
id, name, department_id
Can anyone help me make this query better? parhaps with the With clause?Use analytic function ROW_NUMBER:
with t as (
select 'A' name,3 department from dual union all
select 'B',3 from dual union all
select 'C',3 from dual union all
select 'D',3 from dual union all
select 'E',3 from dual union all
select 'A',10 from dual union all
select 'B',10 from dual union all
select 'C',10 from dual union all
select 'A',13 from dual union all
select 'B',13 from dual
select name,
'Person' || row_number() over(partition by department order by name) person,
department
from t
order by 3,
3
NAME PERSON DEPARTMENT
A Person1 3
B Person2 3
C Person3 3
D Person4 3
E Person5 3
A Person1 10
B Person2 10
C Person3 10
A Person1 13
B Person2 13
10 rows selected.
SQL> SY. -
SQL query works in SSIS, SSMS/SQL server but fails in deployment?
The SQL query in my execute sql task is correct. It works in SSIS and SSMS also. But, it fails when I deploy my package. The error -
Code: 0xC002F210
Source: MySQLTask Execute SQL Task Description: Executing the query
"UPDATE [MyTable] SET MyCol..."
failed with the following error: "Invalid object name 'MyTable'.".
Possible failure reasons: Problems with the query "ResultSet" property
not set correctly parameters not set correctly or connection not established
correctly.
What could be the reason for this error and how do I fix it ?
Thanks.Does the database have the object [MyTable]? What is the default schema for the user? Is the table (assuming it exists) in the default schema for the user?
Russel Loski, MCT, MCSE Data Platform/Business Intelligence. Twitter: @sqlmovers; blog: www.sqlmovers.com
Yes, the DB has the object [MyTable]. The default schema is dbo, as given by SELECT SCHEMA_NAME()
The table is in the default schema for the user as per -
SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = SCHEMA_NAME()
AND TABLE_NAME = 'MyTable'
Maybe you are looking for
-
Hi, Iam struck up with scenario in rfc to file where , rfc is taken as sender communication channel. what is the way to configure sender communication channel.
-
How do I remove signs indicating space, line shift etc.
I must have done something stupid, for suddenly there are a lot of small devils, that indicate each space, forced line shift etc. How do I get rid of them, before they drive me crazy? Thank you very much
-
Hi! I'm finally starting to dig into our Sound and Vibration toolkit and I love it! Doing sound pressure level, 1/3 octave, everything looks great. Trying to do vibration. I put in a 1g (9.8 m/s^2) 250 HZ standard signal from a vibration calibrator,
-
I can't use photoshop and illustration.
A month ago, I downloaded trial version photoshop and illustration. When the programs had expired, I purchased creative cloud student plan. Unfortunately, I cannot use the programs because they still require putting serial number or buying the p
-
I'll try this again. After upgrading from CS2 to CS4, there are many fonts missing from my system, in particular the Warnock Pro family. How do I get it back?