SQL Anywhere 12 Webservice returns malformed JSON float values
The table column is:
"duration" DOUBLE NULL
The Webservice is defined as:
CREATE SERVICE "myservice" TYPE 'JSON' AUTHORIZATION OFF USER "xyz" URL ELEMENTS AS select [...],duration from mytable [...];
The returned JSON:
"duration": .45
"duration": .37
JSLint (and Ruby) say:
Parse error on line 7:
... "duration": .45 }, {
-----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['
A workaround would be to select string(duration), but that would not work with select *
Is there any option I need to set or is it a bug?
This looks like a bug (the JSON is formatted correctly in version 16). You might want to try more recent patch for version 12 (you didn't state which build number of version 12 you are using) to see if it has already been fixed.
--Jason
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. -
How to use a select list value in a PL/SQL function body returning SQLquery
Hi Friends,
I have a select list P6_TEST with values 'nav' anf 'jyo'. I am trying to create a report using "SQL Query (PL/SQL
function body returning SQL query)". In my report query can i check if P6_TEST='nav' and do something like the
code shown below.How can i do that.
DECLARE
v_sql VARCHAR2(3000);
BEGIN
IF :P6_TEST = 'nav' THEN
v_sql :=
'SELECT
* from department';
........................Thanks,
NavNav:
What you have should work. Give it a go. Post back if you run into issues.
Varad -
Insert float value into ms sql server
Hi.
How do I insert a float value into my ms sql db.
The Code:
select.setFloat( 4, theForm.getVaerdi() );ERROR:
"MakeClapetInsertAction.java": Error #: 300 : method setFloat(int, java.lang.Float) not found in interface java.sql.PreparedStatement at line 89, column 12setFloat takes a float primitive, not a Float object.
select.setFloat( 4, theForm.getVaerdi().floatValue() ); -
SQL query to store float values in french culture.
Here is how my requirement goes..
I have an application where users can store float values into the SQL server. Here float values are period(.) based. I have now started supporting the users who use the french culture where the float values are Comma(,) based. Example: 13.75 is represented
as 13,75. Instead of making changes to my code i.e the way i am inserting/retrieving the date now, is there a way i can handle this requirement based on culture. Like, if I specify the culture, will I be able to insert float inputs as comma(,) based values
without disturbing my existing code?
Any help is appreciated
Thanks,
Chandrahas.
-Chandrahasis there a way i can handle this requirement based on culture.
Hello Chandrahas,
SQL Server don't store any culture info for numeric values; they are plain numeric.
It's part of the frontend to represent / accept values depending on the culture setting of the client.
Olaf Helper
[ Blog] [ Xing] [ MVP] -
PL/SQL Web Services - JAX-RPC returning in JSON format
Hello all,
I have been searching on the web, inclusively on this forum, for a way of returning data in a JSON format from a PL/SQL web service.
The threads that I have found about this issue are still unanswered.
Does anyone know if it is possible to create a JAX-RPC web service which returns in JSON format ?
Regards,
PedroHi,
JAX-RPX services are SOAP services and thus return XML. You want to use REST instead
Frank -
Rounding ist wrong for float value (MS SQL 2005)
Hello
I have a simple report with a command:
select num = convert(float, 4.145)
Field round over "Format Field" or ToText( num, 2) the result is 4.14 -> Wrong
if i use Round(num, 2) result is 4.15 --> OK
In CR 8.5 result is always correct
ThxI know the problematic of the floating values.
My big trouble is the inconsistency in the report!
It can't be that the formula function Round(x,y) show another result than the integrated field-rounding function.
Also in the formula that ToText(x, y) is different to Round(x,y).
Following another stupid difference:
Command.num = 4.145 Result: TRUE
Command.num - 4.145 = 0 Result: FALSE
Mathematical it's the same.
CR8 was consistence, after migration we have different result on our reports! -
ODBC Gateway on Linux error - connects ok with Sybase SQL Anywhere
OS: CentOS 5.8 64-bit
DB: Oracle XE 11gR1 64-bit
Gateway: Oracle Gateway for ODBC 64-bit
Database and gateway reside on same Linux Server.
Connecting to remote Sybase SQL Anywhere 10 server on WindowsXP.
Using SQL Anywhere 11 odbc driver and unixODBC driver manager on Linux server.
isql tool connects without any problems.
One LISTENER, service for db and gateway on same port.
===================================
Via SQL*Plus, the following error occurs....
SQL> select * from dual@dblink;
select * from dual@dblink
ERROR at line 1:
ORA-28513: internal error in heterogeneous remote agent
ORA-02063: preceding line from dblink
===================================
sqlnet.ora
# sqlnet.ora Network Configuration File: /u01/app/oracle/product/11.2.0/xe/network/admin/sqlnet.ora
# Generated by Oracle configuration tools.
NAMES.DIRECTORY_PATH=(TNSNAMES)
ADR_BASE = /u01/app/oracle/product/11.2.0/xe
==================================
tnsnames.ora
# tnsnames.ora Network Configuration File:
XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = mysystem)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
dblink =
(DESCRIPTION =
(ADDRESS =
(PROTOCOL = TCP)(HOST = mysystem)(PORT = 1521)
(CONNECT_DATA =
(SID = dblink))
(HS=OK))
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
=======================
listener.ora
# listener.ora Network Configuration File:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/xe)
(PROGRAM = extproc)
(SID_DESC =
(SID_NAME = dblink)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/gtw)
(PROGRAM = dg4odbc)
(ENVS=LD_LIBRARY_PATH=/opt/sqlanywhere11/lib64:/u01/app/oracle/product/11.2.0/gtw/lib)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
(ADDRESS = (PROTOCOL = TCP)(HOST = mysystem)(PORT = 1521))
DEFAULT_SERVICE_LISTENER = (XE)
========================
initdblink.ora
# This is a sample agent init file that contains the HS parameters that are
# needed for the Database Gateway for ODBC
# HS init parameters
HS_FDS_CONNECT_INFO=dblink
HS_FDS_SHAREABLE_NAME=/usr/lib64/libodbc.so
HS_FDS_TRACE_LEVEL=255
HS_LANGUAGE=american_america.we8iso8859p1
HS_NLS_NCHAR=UTF-8
# ODBC specific environment variables
set ODBCINI=/etc/odbc.ini
========================
Oracle Corporation --- MONDAY OCT 15 2012 17:23:39.915
Heterogeneous Agent Release
11.2.0.1.0
Oracle Corporation --- MONDAY OCT 15 2012 17:23:39.914
Version 11.2.0.1.0
Entered hgogprd
HOSGIP for "HS_FDS_TRACE_LEVEL" returned "255"
Entered hgosdip
setting HS_OPEN_CURSORS to default of 50
setting HS_FDS_RECOVERY_ACCOUNT to default of "RECOVER"
setting HS_FDS_RECOVERY_PWD to default value
setting HS_FDS_TRANSACTION_LOG to default of HS_TRANSACTION_LOG
setting HS_IDLE_TIMEOUT to default of 0
setting HS_FDS_TRANSACTION_ISOLATION to default of "READ_COMMITTED"
HOSGIP returned value of "UTF-8" for HS_NLS_NCHAR
setting HS_FDS_TIMESTAMP_MAPPING to default of "DATE"
setting HS_FDS_DATE_MAPPING to default of "DATE"
setting HS_RPC_FETCH_REBLOCKING to default of "ON"
setting HS_FDS_FETCH_ROWS to default of "100"
setting HS_FDS_RESULTSET_SUPPORT to default of "FALSE"
setting HS_FDS_RSET_RETURN_ROWCOUNT to default of "FALSE"
setting HS_FDS_PROC_IS_FUNC to default of "FALSE"
setting HS_FDS_CHARACTER_SEMANTICS to default of "FALSE"
setting HS_FDS_MAP_NCHAR to default of "TRUE"
setting HS_NLS_DATE_FORMAT to default of "YYYY-MM-DD HH24:MI:SS"
setting HS_FDS_REPORT_REAL_AS_DOUBLE to default of "FALSE"
setting HS_LONG_PIECE_TRANSFER_SIZE to default of "65536"
setting HS_SQL_HANDLE_STMT_REUSE to default of "FALSE"
setting HS_FDS_QUERY_DRIVER to default of "TRUE"
setting HS_FDS_SUPPORT_STATISTICS to default of "FALSE"
Parameter HS_FDS_QUOTE_IDENTIFIER is not set
setting HS_KEEP_REMOTE_COLUMN_SIZE to default of "OFF"
setting HS_FDS_GRAPHIC_TO_MBCS to default of "FALSE"
setting HS_FDS_MBCS_TO_GRAPHIC to default of "FALSE"
Default value of 64 assumed for HS_FDS_SQLLEN_INTERPRETATION
setting HS_CALL_NAME_ISP to "gtw$:SQLTables;gtw$:SQLColumns;gtw$:SQLPrimaryKeys;gtw$:SQLForeignKeys;gtw$:SQLProcedures;gtw$:SQLStatistics;gtw$:SQLGetInfo"
setting HS_FDS_DELAYED_OPEN to default of "TRUE"
setting HS_FDS_WORKAROUNDS to default of "0"
Exiting hgosdip, rc=0
ORACLE_SID is "dblink"
Product-Info:
Port Rls/Upd:1/0 PrdStat:0
Agent:Oracle Database Gateway for ODBC
Facility:hsa
Class:ODBC, ClassVsn:11.2.0.1.0_0008, Instance:dblink
Exiting hgogprd, rc=0
hostmstr: 0: HOA After hoagprd
Invalid HS_NLS_NCHAR value UTF-8 specified
Setting HS_NLS_NCHAR to Server Default 2000
Invalid HS_NLS_NCHAR value UTF-8 specified
Setting HS_NLS_NCHAR to Server Default 2000
hostmstr: 0: HOA Before hoainit
Entered hgoinit
HOCXU_COMP_CSET=1
HOCXU_DRV_CSET=31
HOCXU_DRV_NCHAR=2000
HOCXU_DB_CSET=873
HOCXU_SEM_VER=112000
Exiting hgoinit, rc=28513
hostmstr: 0: HOA After hoainit
RPC Calling nscontrol(0), rc=0
hostmstr: 0: RPC Before Exit Agent
hostmstr: 0: HOA Before hoaexit
Entered hgoexit
HS Gateway: NULL connection context at exit
Exiting hgoexit, rc=0 with error ptr FILE:hgoexit.c LINE:108 FUNCTION:hgoexit() ID:Connection context
hostmstr: 0: HOA After hoaexit
hostmstr: 0: RPC After Exit Agent
=============================
Also, does anyone know how to determine the location (full path) of the unixODBC driver manager ?
Please assist if you can...thx.
Edited by: user601798 on Oct 15, 2012 3:37 PMLet me start with the unixODBC driver:
There's no generic location as it depends which package you've used to install the UnixODBC driver manager or how you compiled it from scratch. I commonly prefer to compile it from scratch as this offers me to install it to any location I like.
If you're not sure where it is located, you could perform a search on your machine looking for libodbc.so. Then cross check it with "file <location>/libodbc.so" to see the lib is a 64bit library.
So let's assume in the /usr/lib64 you found the libodbc.so library, then the setting
HS_FDS_SHAREABLE_NAME=/usr/lib64/libodbc.so
is correct. Else you need to adopt the parameter.
Next step is to check out which unixODBC version is installed. That's commonly done by calling "odbcinst -j".
Looking now ta the gateway init file there's a parameter HS_NLS_NCHAR set to UTF-8. UnixODBC is commonly compiled with UCS2 support, so please change it to HS_NLS_NCHAR=UCS2
Could you also please post the content of the odbc.ini file "more /etc/odbc.ini"?
Thanks,
Klaus -
Region source (PL/SQL function body returning SQL query)
Hi, guys.
Here is what i try to do:
Create a region of type SQL Query (PL/SQL function body returning SQL query). In the source area i tried to put this:
DECLARE
v_new VARCHAR2(10);
v_SQL varchar2(32000);
BEGIN
v_new := :P102_HDN_NEW;
-- htp.p(v_new);
IF v_new = 'N-Set' THEN
v_SQL := 'select ' ||
ELSIF v_new = 'Y-Set' THEN
v_SQL := 'select ' ||
END IF;
RETURN v_SQL;
END;
And here is the reply from APEX:
1 error has occurred
Query cannot be parsed within the Builder. If you believe your query is syntactically correct, check the ''generic columns'' checkbox below the region source to proceed without parsing. The query can not be parsed, the cursor is not yet open or a function returning a SQL query returned without a value.
Now.
1. Variable is set with the right value.
2. Each statement (separately) returns SQL that works with no problems
3. Problem occures if i try to put IF statement around the SQL creation.
4. If i select "Use Generic Column Names (parse query at runtime only)" instead of "Use Query-Specific Column Names and Validate Query" then the script returns SQL properly, however report's column names are set to Col1, Col2,Col3 ......
Thnks in advence
MikeOK. Here is enire statement:
DECLARE
v_new VARCHAR2(10);
v_SQL varchar2(32000);
BEGIN
v_new := :P102_HDN_NEW;
htp.p(v_new);
IF v_new = 'N-Set' THEN
v_SQL := 'select ' ||
'APEX_ITEM.DISPLAY_AND_SAVE(10,c.sdescr) descr, ' ||
'APEX_ITEM.DISPLAY_AND_SAVE(12,DECODE(ld.level,''All'', ''All Categories'',ld.level)) level, ' ||
'apex_item.checkbox(1, ld.opt_in_auto_flag, decode(ld.opt_in_auto_flag,NULL,''disabled'',''Y'',''checked'')) auto_in, ' ||
'apex_item.checkbox(2, ld.opt_in_manual_flag, decode(ld.opt_in_manual_flag,NULL,''disabled'',''Y'',''checked'')) manual_in, ' ||
'apex_item.checkbox(3, ld.opt_out_auto_flag, decode(ld.opt_out_auto_flag,NULL,''disabled'',''Y'',''checked'')) auto_out, ' ||
'apex_item.checkbox(4, ld.opt_out_manual_flag, decode(ld.opt_out_manual_flag,NULL,''disabled'',''Y'',''checked'')) manual_out, ' ||
'DECODE(c.code, ''NMBR'', NULL,''Change to '' || DECODE(ld.level,''All'',''Categories'',''All Categories'')) link_change, ' ||
'APEX_ITEM.DISPLAY_AND_SAVE(11,c.code) code ' ||
'from ' ||
'tbl1 c, ' ||
'tbl2 ld ' ||
'where c.code = ld.code ' ||
'and c.type = ''TYPE1'' ' ||
'and c.active = ''Y'' ' ||
'order by c.sorting ';
ELSIF v_new = 'Y-Set' THEN
v_SQL := 'select ' ||
'APEX_ITEM.DISPLAY_AND_SAVE(10,c.sdescr) descr, ' ||
'APEX_ITEM.DISPLAY_AND_SAVE(12,''All Categories'') level, ' ||
'apex_item.checkbox(1, c.option_1, decode(c.option_1,NULL,''disabled'',''Y'',''checked'')) auto_in, ' ||
'apex_item.checkbox(2, c.option_3, decode(c.option_3,NULL,''disabled'',''Y'',''checked'')) manual_in, ' ||
'apex_item.checkbox(3, c.option_2, decode(c.option_2,NULL,''disabled'',''Y'',''checked'')) auto_out, ' ||
'apex_item.checkbox(4, c.option_4, decode(c.option_4,NULL,''disabled'',''Y'',''checked'')) manual_out, ' ||
'DECODE(c.code, ''AAA'', NULL,''Options by AAA'') link_change, ' ||
'APEX_ITEM.DISPLAY_AND_SAVE(11,c.code) code ' ||
'from ' ||
'tbl1 c ' ||
'where 1 = 1 ' ||
'and c.type = ''TYPE1'' ' ||
'and c.active = ''Y'' ' ||
'order by c.sorting ';
END IF;
RETURN v_SQL;
END;
If i put just this
DECLARE
v_new VARCHAR2(10);
v_SQL varchar2(32000);
BEGIN
v_new := :P102_HDN_NEW;
htp.p(v_new);
v_SQL := 'select ' ||
'APEX_ITEM.DISPLAY_AND_SAVE(10,c.sdescr) descr, ' ||
'APEX_ITEM.DISPLAY_AND_SAVE(12,DECODE(ld.level,''All'', ''All Categories'',ld.level)) level, ' ||
'apex_item.checkbox(1, ld.opt_in_auto_flag, decode(ld.opt_in_auto_flag,NULL,''disabled'',''Y'',''checked'')) auto_in, ' ||
'apex_item.checkbox(2, ld.opt_in_manual_flag, decode(ld.opt_in_manual_flag,NULL,''disabled'',''Y'',''checked'')) manual_in, ' ||
'apex_item.checkbox(3, ld.opt_out_auto_flag, decode(ld.opt_out_auto_flag,NULL,''disabled'',''Y'',''checked'')) auto_out, ' ||
'apex_item.checkbox(4, ld.opt_out_manual_flag, decode(ld.opt_out_manual_flag,NULL,''disabled'',''Y'',''checked'')) manual_out, ' ||
'DECODE(c.code, ''NMBR'', NULL,''Change to '' || DECODE(ld.level,''All'',''Categories'',''All Categories'')) link_change, ' ||
'APEX_ITEM.DISPLAY_AND_SAVE(11,c.code) code ' ||
'from ' ||
'tbl1 c, ' ||
'tbl2 ld ' ||
'where c.code = ld.code ' ||
'and c.type = ''TYPE1'' ' ||
'and c.active = ''Y'' ' ||
'order by c.sorting ';
RETURN v_SQL;
END;
it works fune... -
Multiple Select List looping thru PL/SQL function body returning SQL query
Hi,
I have a Multiple Select List. I want to loop through the values from the Select List and process them in a PL/SQL function body returning a SQL query. Currently, my code only returns the SQL SELECT results of one item in the select list. How do I change my code to make it return the results of all of the items in the select list? (I tested it and it is definitely picking up all the values in the select list).
<b>
DECLARE
selected_items HTMLDB_APPLICATION_GLOBAL.VC_ARR2;
s VARCHAR2(20);
q varchar2(32767);
BEGIN
selected_items := HTMLDB_UTIL.STRING_TO_TABLE(:P50_SELECTED_INSTRUMENTS);
-- htp.p('COUNT: '||selected_items.count);
FOR i in 1..selected_items.count LOOP
s := TO_CHAR(selected_items(i));
-- htp.p('First: '||s);
-- htp.p('Second: '||:s);
-- htp.p('Third: '||TO_CHAR(selected_items(i)));
q:= 'SELECT '||
'SUBSTR(orig_geo_loc_sys,1,INSTR(orig_geo_loc_sys,''-'')-1) AS INSTRUMENT, '||
'SUBSTR(orig_geo_loc_sys,INSTR(orig_geo_loc_sys,''-'')+1, LENGTH'||
' (orig_geo_loc_sys)) AS ORIG_LINENUM, '||
'sum(orig_intrl) orig_intrl, '||
'sum(orig_extrl) orig_extrl, '||
'sum(recv_intrl) recv_intrl, '||
'sum(recv_extrl) recv_extrl '||
'FROM line_usage_sum_view '||
'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''' || s ||'%'' '||
--'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''2213003%'' '||
'AND switch_id = ''' || :P1_SWITCH_ID || ''' ' ||
'AND call_start_date > TO_DATE(''30-NOV-1999'') ' ||
'AND call_clear_time > TO_DATE(''30-NOV-1999'') '||
'AND '||
:SORTFIELD||' BETWEEN '||
'TO_DATE(:STARTDATE,''dd-MON-YYYY HH24:MI'') AND '||
'TO_DATE(:STOPDATE, ''dd-MON-YYYY HH24:MI'') '||
'GROUP BY GROUPING SETS (orig_geo_loc_sys)';
-- htp.p('SQL query: '||q);
RETURN q;
END LOOP;
END;</b>
Thank you,
LauraLaura,
First, I would be careful of introducing SQL Injection possibilities. Any time I see
'Select ... ' || :P123_FOO || ' ... '
I worry about sql injection. In your case you are converting :P50_SELECTED_INSTRUMENTS into selected_items and then selected_items into s. So when I see
'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''' || s ||'%'' '||
I think, "I could use sql Injection and hack this."
So, I would do some validation on :P50_SELECTED_INSTRUMENTS or some other method to avoid this.
I'm not certain I understand your query. Do you really intend to allow the user to select the beginning of a string and then find all rows that start with that string? Or, do you just want to let them find when it matches the string. This is one way if you want to do matching:
DECLARE
selected_items HTMLDB_APPLICATION_GLOBAL.VC_ARR2;
s VARCHAR2(32767);
q varchar2(32767);
BEGIN
-- Change the : separate string to be comma separated with quoted strings
s := '''' || replace(:P50_SELECTED_INSTRUMENTS, ',', ''',''')|| '''' ;
-- htp.p('COUNT: '||selected_items.count);
q:= 'SELECT '||
'SUBSTR(orig_geo_loc_sys,1,INSTR(orig_geo_loc_sys,''-'')-1) AS INSTRUMENT, '||
'SUBSTR(orig_geo_loc_sys,INSTR(orig_geo_loc_sys,''-'')+1, LENGTH'||
' (orig_geo_loc_sys)) AS ORIG_LINENUM, '||
'sum(orig_intrl) orig_intrl, '||
'sum(orig_extrl) orig_extrl, '||
'sum(recv_intrl) recv_intrl, '||
'sum(recv_extrl) recv_extrl '||
'FROM line_usage_sum_view '||
'WHERE TO_CHAR(orig_geo_loc_sys) in (' || s ||' ) '||
--'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''2213003%'' '||
'AND switch_id = ''' || :P1_SWITCH_ID || ''' ' ||
'AND call_start_date > TO_DATE(''30-NOV-1999'') ' ||
'AND call_clear_time > TO_DATE(''30-NOV-1999'') '||
'AND '||
:SORTFIELD||' BETWEEN '||
'TO_DATE(:STARTDATE,''dd-MON-YYYY HH24:MI'') AND '||
'TO_DATE(:STOPDATE, ''dd-MON-YYYY HH24:MI'') '||
'GROUP BY GROUPING SETS (orig_geo_loc_sys)';
-- htp.p('SQL query: '||q);
RETURN q;
END;
If you want to do something more like you originally stated, try this:
DECLARE
selected_items HTMLDB_APPLICATION_GLOBAL.VC_ARR2;
s VARCHAR2(20);
q varchar2(32767);
BEGIN
selected_items := HTMLDB_UTIL.STRING_TO_TABLE(:P50_SELECTED_INSTRUMENTS);
-- htp.p('COUNT: '||selected_items.count);
q:= 'SELECT '||
'SUBSTR(orig_geo_loc_sys,1,INSTR(orig_geo_loc_sys,''-'')-1) AS INSTRUMENT, '||
'SUBSTR(orig_geo_loc_sys,INSTR(orig_geo_loc_sys,''-'')+1, LENGTH'||
' (orig_geo_loc_sys)) AS ORIG_LINENUM, '||
'sum(orig_intrl) orig_intrl, '||
'sum(orig_extrl) orig_extrl, '||
'sum(recv_intrl) recv_intrl, '||
'sum(recv_extrl) recv_extrl '||
'FROM line_usage_sum_view '||
'WHERE 1=1 ';
FOR i in 1..selected_items.count LOOP
s := TO_CHAR(selected_items(i));
q := q || ' and TO_CHAR(orig_geo_loc_sys) LIKE '''|| s ||'%'' ' ;
END LOOP;
q := q || ||'%'' '||
--'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''2213003%'' '||
'AND switch_id = ''' || :P1_SWITCH_ID || ''' ' ||
'AND call_start_date > TO_DATE(''30-NOV-1999'') ' ||
'AND call_clear_time > TO_DATE(''30-NOV-1999'') '||
'AND '||
:SORTFIELD||' BETWEEN '||
'TO_DATE(:STARTDATE,''dd-MON-YYYY HH24:MI'') AND '||
'TO_DATE(:STOPDATE, ''dd-MON-YYYY HH24:MI'') '||
'GROUP BY GROUPING SETS (orig_geo_loc_sys)';
-- htp.p('SQL query: '||q);
RETURN q;
END;
Hope this helps...
Anton -
REP-1401 Fatal PL/SQL error occur ORA-06502 numeric or value error
Hi,
I am getting following error in reports 6i
REP-1401 Fatal PL/SQL error occur ORA-06502 numeric or value error.
I have added a formula column based on other formula column
function CF_1FORMULA0005 return varchar2 is
CF_CREDIT varchar2(38);
begin
:CF_CREDIT:= :D_CARRY_F_CR+:D_HD_SUM_REP_CR;
RETURN (:CF_CREDIT);
end;
Oracle Standard formula coulmn:
function D_CARRY_F_DRFormula return VARCHAR2 is
l_dr VARCHAR2(38);
l_dr_disp VARCHAR2(38);
begin
SRW.REFERENCE(:C_FUNC_CURRENCY);
SRW.REFERENCE(:C_CARRY_F_DR);
if (:C_CARRY_F_DR = 0) THEN
ax_globe_package.g_dr_cf := TRUE;
--l_dr:= '0.00';
l_dr_disp := '0.00';
l_dr := ax_currency_pkg.display_char(:C_FUNC_CURRENCY,l_dr_disp,38);
else
-- return(ax_currency_pkg.display_char(:C_FUNC_CURRENCY,:C_CARRY_F_DR,ax_page_pkg.f_maxlength));
-- Bug2239881. Setting the carried forward totals.
IF (:P_GLOBAL_ATTR_CAT = 'JE.GR.GLXSTBKS.BOOKS' AND ax_globe_package.g_dr_cf = FALSE) THEN
ax_globe_package.g_dr_cf := TRUE;
ax_globe_package.g_dr_total := :C_CARRY_F_DR;
END IF;
srw.message(999,'G_DR_TOTAL = ' || ax_globe_package.g_dr_total );
l_dr := ax_currency_pkg.display_char(:C_FUNC_CURRENCY,to_char(ax_globe_package.g_dr_total),38);
/*select to_number(l_dr, '999G999G999G999G990D00')
into l_dr_disp
from dual;
end if;
srw.message(999,'l_dr = ' || l_dr );
return l_dr;
--return ltrim(to_char(l_dr_disp,'999G999G999G999G990D00','nls_numeric_characters=,.'));
end;
both formula column return types are character.Please help me ASAP.
Thanks,
sriharsha.Hi,
First of all: when you should use concatenation operator (||) instead of plus sign when working with strings. So, instead of
:CF_CREDIT:= :D_CARRY_F_CR+:D_HD_SUM_REP_CR; you should use
:CF_CREDIT:= :D_CARRY_F_CR||:D_HD_SUM_REP_CR; If :D_CARRY_F_CR and :D_HD_SUM_REP_CR are both numbers then consider to use to_char function before you assign value to :CF_CREDIT.
I wonder, why your CF's returns varchar's if they operates on numbers?
regards
kikolus
Edited by: kikolus on 2012-11-30 08:03 -
SQL Query ( PL/SQL function body returning query ) page
Hello Friends,
I have a page with type SQL Query ( PL/SQL function body returning query ).
I have written a pl/sql block that returns a sql query - select statment.
Some times i am getting no data found error - does it got to do with the variable that stores the query .
=======================
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
Error ERR-1101 Unable to process function body returning query.
OK
=====================
When the query is returned with records where exactly the records are stored is it in the variable declared in pl/sql block or with the Oracle Apex implicit cursor.
Here's the pl/sql block ..
The query is generated while the user is navigating through pages ..
====================
declare
l_return_stmt varchar2(32767);
l_select varchar2(32000);
l_from varchar2(32000);
l_where varchar2(32000);
l_order_by varchar2(32000);
l_stmt_recordcount varchar2(32000);
l_recordcount number ;
begin
l_select := 'select '||:P10_VARLIST1||:P10_VARLIST2||:P10_VARLIST3
||:P10_VARLIST4||:P10_VARLIST5;
l_from := ' from '||:P10_RELATION;
if length(:P10_WHERE) > 0 then
l_where := ' where '||:P10_WHERE;
else
l_where := '';
end if;
if length(:P10_ORDER_BY) > 0 then
l_order_by := ' order by '||:P10_ORDER_BY;
else
l_order_by := '';
end if;
l_return_stmt := l_select||l_from||l_where||l_order_by;
:P10_STMT := l_return_stmt;
return l_return_stmt;
end;
=============================
Appreciate your help in this regard.
thanks/kumar
Edited by: kumar73 on Apr 22, 2010 6:38 AMIt looks like the query string you are trying to pass back exceeds the 32K limit for a varchar. Where this is happening is kind of difficult to tell as it could be any number of points, and also depends on what you are passing into the process via page items.
I would first try to establish what combination of page items causes this error to occur. Then, starting from the bottom and working your way backwards, I would start 'switching off' some of the items you use to build your query until it breaks again, thus establishing which part is leading to the error.
Also, I'm not sure what :P10_STMT is doing (are you maybe using this for visiblity of the query created)?
It looks like the query string you are trying to pass back exceeds the 32K limit for a varchar. Where this is happening is kind of difficult to tell as it could be any number of points, and also depends on what you are passing into the process via page items.
I would first try to establish what combination of page items causes this error to occur. then, starting from the bottom and working your way backwards, I would start 'switching off' some of the items you use to build your query until it breaks again, thus establishing which part is leading to the error.
Also, I'm not sure what :P10_STMT is doing (are you maybe using this for visiblity of the query created)? -
Best way to return more than 1 value in a function?
Hi all,
What's the best way to return more than 1 value from a function? returning a cursor? varray? objects? etc? I thought of a cursor first, but i was hesitant since i am not sure if the cursor will be automatically closed when you return a cursor(open cursor no longer used is bad). Example:
BEGIN
OPEN c_temp_cursor;
RETURN c_temp_cursor;
END;
With above example, c_temp_cursor is remained open. Or is it automatically closed once it exits from the function? Need some suggestions and expert advice.
Thanks.
Note: Function is to be used to return and not a procedure (This is a requirement. Can't explain the details on why).
Edited by: dongzky on Jul 3, 2010 4:17 PM
typo: "ir exists" to "it exits" (in bold)First create your pl/sql table type
CREATE OR REPLACE TYPE pmc_tab AS TABLE OF NUMBER;
Then a table:-
CREATE TABLE v_stats_daily(start_date date, field1 number, field2 number, field3 number);
Some insert into the table so we've got test data...
insert into v_stats_daily values('08-OCT-2003',10,20,30);
insert into v_stats_daily values('08-OCT-2003',40,50,60);
insert into v_stats_daily values('08-OCT-2003',70,80,90);
Then create your function:-
CREATE OR REPLACE FUNCTION PMC_STATS
(pStatDate Date) RETURN pmc_tab IS
MyArray pmc_tab;
vstat1 NUMBER;
vstat2 NUMBER;
vstat3 NUMBER;
BEGIN
MyArray := pmc_tab();
select sum(Field1), sum(field2),sum(field3)
into vstat1, vstat2,vstat3
from v_stats_daily
where Start_date = pStatDate;
MyArray.extend;
MyArray(1) := vstat1;
MyArray.extend;
MyArray(2) := vstat2;
MyArray.extend;
MyArray(3) := vstat3;
RETURN MyArray;
END;
In SQL*Plus:-
SQL>set serverout on
Then a lump of PL/SQL to run your function:-
DECLARE
MyDate DATE;
MyArray pmc_tab;
i NUMBER;
numOut NUMBER;
BEGIN
MyArray := pmc_stats('08-OCT-2003');
dbms_output.put_line('Table count: '||to_char(MyArray.count));
for i in 1..MyArray.last LOOP
numOut := MyArray(i);
--if numOut is null then
dbms_output.put_line('Value: '||to_char(numOut));
--end if;
END LOOP;
END;
Your output will look like:-
Table count: 3
Value: 120
Value: 150
Value: 180
Hope this helps, -
Sybase with ase and sql anywhere 16 using ssma
ok this may sound like a very dumb question but how does one connect to sybase central (sql 16 anywhere) using ssma.
In my ase connections when i do test connection it returns successful however when i click on ssma > connect to sybase it returns
ERROR [08001] [SAP][ASE ODBC Driver]Client unable to establish a connection
i have my network server running on sybase using sql anywhere 16 network server.
I also had my firewalls off
any help would be appreciated.Hi Jeff ,
Thank you so much for the reply.
I have used 32 bit PHP.
But now we have resolved above mentioned issue. Now we can connect PHP with SQL Anywhere successfully.
Regards,
Vishal Chikhalikar
PHP Programmer -
Can Function Return more than One Values ??
Hi Experts,
I would like to ask you Can Function Return more than one values. I Used Function with Out and In out parameter and its working Fine..
1. what is harm using Out and In out parameter in function
2. if we can use Out and In out parameter in Function so what is deffernce between procedure and Function.
3. Is there any Other Way Though which we can return more the One values in Function.
Please advice me...
Thanks
Umesh GoelYes/No.
You can return multiple value from function. But, in PL/SQL and not in a SQL.
The following examples demonstrate that -
SQL*Plus: Release 9.2.0.1.0 - Production on Wed Mar 28 17:41:15 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> create or replace package glob
2 as
3 b varchar2(20);
4 c varchar2(20);
5 end;
6 /
Package created.
SQL>
SQL> create or replace function test_mul_out(a in number)
2 return number
3 is
4 cursor c1(eno in number)
5 is
6 select ename,job,sal
7 from emp
8 where empno = eno;
9
10 rec c1%rowtype;
11 d number(10);
12 begin
13 open c1(a);
14 loop
15 fetch c1 into rec;
16 exit when c1%notfound;
17 glob.b:= rec.ename;
18 glob.c:= rec.job;
19 d:= rec.sal;
20 end loop;
21 close c1;
22 return d;
23 end;
24 /
Function created.
SQL> set serveroutput on
SQL>
SQL> declare
2 zz number(10);
3 begin
4 select test_mul_out(7777)
5 into zz
6 from dual;
7
8 dbms_output.put_line('Ename: '||glob.b);
9 dbms_output.put_line('Job: '||glob.c);
10 dbms_output.put_line('Sal: '||zz);
11 end;
12 /
Ename: Avik
Job: CLERK
Sal: 3456
PL/SQL procedure successfully completed.
SQL> Regards.
Satyaki De.
Maybe you are looking for
-
In trying to update my iPhone 3Gs from v. 3.13, it apparently downloaded the upgrade, but got stuck during the backup. It backed up for over an hour, and now the green bar in the Backup window is now colorless and is showing no movement. Any suggest
-
Database adapter returns result different to SQL
Hi, I created Database adapter for master-detail select: SELECT DISTINCT t1.INSTANCE_ID, t1.SERVICE_ID, t0.CONFIGURATION_KEY, t0.CONFIGURATION_VALUE, t0.INSTANCE_ID FROM SRVINSTANCECONF t0, SERVICE_INSTANCE t1 WHERE (((t0.CONFIGURATION_KEY = #key) AN
-
Help setting up Window.location.href to open a file, and 1 other issue
Hey there, I am a student currently working on a school project where I must make a website. I am trying to set up: window.location.href="C:\Users\*PCNAME*\Desktop\*SITE*"; in that fashion to open up a local file on my HDD, so when I click a specific
-
IMac won't boot up after latest update
Hi I'm a newbie to this forum but any help would be greatly appreciated please We've had our iMac for 2yrs now no issues but when I went to do the latest update today it's gone a bit weird! I did the install and relaunch like I always do but when reb
-
Boris Export Stops at 98%
Has this ever happened to you? I made up some titles with Boris 3D. Everything looks good. I put it in an NTSC-anamorphic timeline, added a freeze frame so that the last line of text would hold at the end, then exported it as a QT movie. During the e