Function percentile &; percentage in SQL or PL/SQL?
Hi allI was wondering if there is
Percentile or percentage functions in SQL or PL/SQL to calculate ??
I came across percentile_rank , but i didnt find really good example online .... so i wasnt sure if thats right function for calculating percentile
Any example will be great!Thank you very much!!!
Hello
You don't need the functions for that; Just use the / division operator:
SELECT x.*
, TO_NUMBER (value_amt) /
NULLIF (TO_NUMBER (cnt), 0) AS avg_value
FROM x
;
During the validation of the sample output, it is better just to post the actual production, not a table having the same output.
For example:
VAL CN AVG_VALUE
--- -- ---------
100 6 16.67
200 5 40.00
500 10 50.00
700 12 58.33
900 14 64.29
It's actually the output I got from the above query.
Store numbers in a column of string just asking trouble. Use a column to the NUMBER instead; you will avoid the mistakes, and you won't need TO_NUMBER calls in queries like the one above.
If you are certain that the NTC is never 0, then you need not NULLIF. "NULLIF (cnt, 0)" to avoid a division by 0 error by returning NULL rather than 0.
Tags: Database
Similar Questions
-
Any difference between the separate function and aggregation in sql query cost?
Hello
I've run many models sql stmts - such as:
one) using a single table
(b) using the two tables, using simple joins or outer joins
but I didn't notice a difference in sql stmts in cost and implementation plan...
In any case, my colleague insists on only using the aggregate function is less expensive compared to
separate... (something I've not confirmed, that is why I believe that they are exactly the same...)
For the situation described above under 1 sql... We could for example use
select distinct deptno
from empselect count(*), deptno
from emp
group by deptnoselect distinct owner, object_type from all_objects
select count(*), owner, object_type from all_objects
Have you ever found no difference between the two...?
group by owner, object_type
Note: I use Ora DB 10g v2.
Thank you
SIMAlexandre Gelin says:
function separate and aggregation are for different uses and can give the same result, but if you use the aggregate function to get the separate records, it will be expensive...really? I find them almost identical to 11g. Actually GROUP BY is almost always more fast for me in the old days.
article about this askTom Re: any difference between the separate function and aggregation in sql query cost?
This applies mainly to the older oracle versions http://www.oracle.com/technology/products/rdb/pdf/distinct_derivedtables_groupby_sort_tech_article.pdf -
How to create the constructor function for a pl/sql table?
I created a PL/SQL type as table below:
create or replace type typ_tbl_des_text is table of the typ_tof_des_text
OK so far, but I would like to have a constructor function which would be subject to validations and raise_application_error when a validation condition is not met.
How to do this?
The typ_tof_des_text that I created with a constructor function, so that the record-level validation are performed in the constructor. And I think the postings between several records shall be made in a constructor for typ_tbl_des_tex, but cannot figure out how to create such a constructor.
BEDE wrote:
So, if I have understood correctly, to a plsql table type, I can't have a member procedure. Or can I? I mean, just as for a type of failure I can have one or more constructors and possibly several procedures of Member.
For the standard tables in PL/SQL, you will need to create your own API (using procedures and functions) to handle beyond the basics provided by the language. No constructors and methods as it is no o - o.
After thinking a little deeper, I reformulate what I said earlier and actually wants to have a member procedure called add_item, who would be first to check if an item with a key value exists and, if so, it would be up-to-date and so not only extend the plsql table.
Two options.
As we already mentioned, an associative array can be considered - note however that this structure of table has name-value pairs.
Another method is to use a TWG (global temporary table). You define the structure of the once initial table. When a session uses the structure of the table, private copying is instantiated for this session. When the session ends, this copy is destroyed. The table is a temporary structure for this session only.
It can include indexes and so on – which means you can use the constraints of primary keys, unique indexes, secondary indexes and so on.
TWG scales are much better than collections or arrays that require a PGA (expensive private server) memory. In addition, SQL can be used natively against a GTT - unlike the arrays and collections.
-
Convert a MySQL function in Oracle PL/SQL
HelloI'm trying to transfer a MySQL database in Oracle 12 c, there are a number of functions that I need to convert since I am new to Oracle and PL/SQL in particular, I would really appreciate your help for the conversion:
CREATE FUNCTION get_customer_balance()p_customer_id INT p_effective_date DATETIME() RETURNS DECIMAL()5,2( )
DETERMINISTIC
READS SQL DATA
BEGIN
DECLARE v_rentfees decimal PLACES ()5,2) ; #TAXES PAID to RENT VIDEOS INITIALLY
DECLARE v_overfees INTEGER ; #LATE FEES FOR RENTALS PREREQUISITES
DECLARE v_payments decimal PLACES ()5,2) ; #SUM OF PREVIOUSLY MADE PAYMENTS
SELECT IFNULL (SUM(film. rental_rate ),0) INTO v_rentfees
FROM film , inventory , rental
WHERE film . film_id = inventory . film_id
ET inventory . inventory_id = rental . inventory_id
AND rental . rental_date <= p_effective_date
AND rental . Customer_ID = p_customer_id ;
SELECT IFNULL (SUM(IF((TO_DAYS(rental. return_date ) - TO_DAYS(rental. rental_date )) > film. rental_duration ,
((TO_DAYS(rental. return_date ) - TO_DAYS(rental. rental_date )) - film. rental_duration ),0)),0) INTO v_overfees
FROM rental , inventory , film
WHERE film . film_id = inventory . film_id
ET inventory . inventory_id = rental . inventory_id
AND rental . rental_date <= p_effective_date
AND rental . Customer_ID = p_customer_id ;
SELECT IFNULL ()SOMME()paiement. amount ),0) INTO v_payments
FROM payment
OÙ payment . payment_date <= p_effective_date
AND payment . Customer_ID = p_customer_id ;
RETURN v_rentfees + v_overfees – v_payments ;
ENDThis means that rental.return_date and rental.rental_date are declared as a TIMESTAMP. Question is why? Return_date/rental_date store fractions of a second? In any case, assuming rental_duration is in days:
WHEN rental.return_date - rental.rental_date > numtodsinterval (film.rental_duration, 'day')
But the question is return_date and rental_date stores it part time too. I assumed that he didn't, and simply omitted TO_DAYS. If so, then TO_DAYS should be translated to TRUNC:
CREATE OR REPLACE
Get_customer_balance FUNCTION)
p_customer_id INT,
p_effective_date DATE)
RETURN NUMBER
DETERMINISTIC
IS
v_rentfees NUMBER (5.2); PAID #FEES RENT VIDEOS INITIALLY
v_overfees INTEGER. #LATE ADVANCE RENTAL FEES
v_payments NUMBER (5.2); #SUM OF PAYMENTS MADE PREVIOUSLY
BEGIN
SELECT NVL)
Sum (film.rental_rate),
0
)
IN v_rentfees
FROM film,.
inventory,
Rental
WHERE film.film_id = inventory.film_id
AND inventory.inventory_id = rental.inventory_id
AND rental.rental_date<=>=>
AND rental.customer_id = p_customer_id;
SELECT SUM)
CASE
WHEN TRUNC (rental.return_date) - TRUNC (rental.rental_date) > film.rental_duration
THEN (TRUNC (rental.return_date) - TRUNC (rental.rental_date)) - film.rental_duration
0 OTHERWISE
END
)
IN v_overfees
The RENTAL.
inventory,
film
WHERE film.film_id = inventory.film_id
AND inventory.inventory_id = rental.inventory_id
AND rental.rental_date<=>=>
AND rental.customer_id = p_customer_id;
SELECT NVL)
Sum (Payment.amount),
0
)
IN v_payments
PAYMENT
WHERE payment.payment_date<=>=>
AND payment.customer_id = p_customer_id;
RETURN v_rentfees + v_overfees - v_payments;
END;
/
SY.
-
Find the function object DB with SQL Developer
Hello to all, SQL developer 4.0.0.13 on Windows 7 64 bit version. I just started to use the function of object find DB. I type the name of the object in the worksheet, select the name of the object and press ALT + g pane, tab, palette, dialogbox binocular opens and shows me all the objects (and schema name) which are referred to as the selected text in the worksheet. When you click on the name of the object, the object opens twice in the object browser. Maybe I understood something wrong. I tried clicking on it once and twice, twice, I see two viewers object showing the same object. Also the pane, tab, palette, dialogbox binocular remains open after that. Is there a way I can hide/close this as soon as I click on the object. Thank you for your help in advance.
the search panel will remain open until you hide/close it
I'm not able to reproduce the problem of double-open - what type of object happens to, or she to what whether you click on?
In addition, you are on an older version, you can upgrade to 4.0.2 because it could have been corrected in a 2 patch releases as your version debuted.
-
calling a function of R in sql
Hello, can someone help me on this query?
(1) I have a data view called Q_X1_V stored in a database schema, which contains a column called OBS03
(2) I have connected to the schema where the above mentioned notice is defined using sqldeveloper
(3) I created the function of R following and performed in sql developer
Start
sys.rqScriptDrop('xbarr-qcc');
sys.rqScriptCreate ('xbarr-QCC ',' function() {})
Library (Ore)
Ore.Sync (table = Q_X1_V)
Ore.Attach)
DataSet <-ore .pull (Q_X1_V ["OBS03"])
Head (DataSet)
}' ) ;
end;
He created the function successfully.
(4) and I'm trying to run the following sql query in sql developer
Select *.
table (rqEval (NULL, "select 1"OBS03"of the double ',' xbarr-QCC '));
and it results in the following error message
ORA-20000: RQuery error
Error dans.ore.schema (schema): attempt to apply without function
ORA-06512: at "RQSYS. RQEVALIMPL', line 104
ORA-06512: at "RQSYS. RQEVALIMPL', line 101
20000 00000 - '%s '.
* Cause: The stored procedure 'raise_application_error.
We called that causes this error to be generated.
* Action: Fix the problem, as described in the error message or contact
the administrator of the application or the DBA for more information.
Not sure how badly pushing the issue
(5) top of function R mentioned in step: 3 works fine on the command line R
and gives me the following result
OBS03
1 10.872
2 10.818
3 10.802
4 10.622
5 10.708
6 10.658
and how to make the sql command that is mentioned in step: 4 work command-line sqldeveloper.
Any help is appreciated.
Thank you
Pradeep
If you have not already established a database connection by using ore.connect, you will need to include this in your script:
Start
sys.rqScriptDrop('xbarr-qcc');
sys.rqScriptCreate ('xbarr-QCC ',' function() {})
Library (Ore)
Ore.Connect ("user", "sid", "hostname", "password") # use your credentials
Ore.Sync (table = "Q_X1_V") # Note that the table name must be quoted as a string
Ore.Attach)
DataSet<->->
Head (DataSet)
}');
end;
Select *.
table (rqEval)
NULL,
"select 1"OBS03"double."
"xbarr-QCC"));
Or, if a database connection has been established, omit the ore.connect statement in your script and use the optional "ore.connect" parameter in the call to rqEval.
This will call your user credentials to connect to database:
Select *.
table (rqEval)
cursor (select 1 "ore.connect" of the double).
"select 1"OBS03"double."
"xbarr-QCC"));
-
Helps the function 'Running background PL/SQL'
Hello everyone.
I come here for assistance with the service running background PL/SQL within the APEX. Here's a background of what I have to do.
Background:
Currently, I have just a page with a button above and some display boxes. The button calls a process flow Oracle Warehouse Builder (OWB) named RUN_ADJ_VAR and does what he must do. That works fine if my button simply calls the PL/SQL code of
BEGIN
ETQUEW. RUN_ADJ_VAR;
END;
Now that I know that the process flow and the button are working fine, I need to make the page "intelligently" by limiting multiple submissions until the process ends.
What I need:
I need assistance with running background PL/SQL function. My work has been running for a while and I need to run in the background and provide a status of the user, while restricting another presentation by the user. From what I've read here:
Advanced programming techniques
According to me, that this DBMS wrapper function, it's what I use.
What I have so far:
Using the API and example, I made my own attempt at this and it does not work. Here's what I have so far:
[code]
DECLARE
v_sql VARCHAR2 (32767).
BEGIN
v_sql: = '
BEGIN
ETQUEW. RUN_ADJ_VAR;
APEX_PLSQL_JOB. () UPDATE_JOB_STATUS
P_JOB = >: APP_JOB,.
P_STATUS = > "done");
END IF;
END;
';
: P1_JOB: = APEX_PLSQL_JOB. () SUBMIT_PROCESS
p_sql = > v_sql,
p_when = > sysdate,.
p_status = > 'Submit');
: P1_POST_DONE: = 'Y ';
END;
[/ code]
What the code so far:
The code seems to ignore the first part and does work through the underlined only section. The work never appears to run and the button can be clicked several times.
Other Options:
I don't know if the function from PL/SQL background running is the only way to do that. The work is performed for about 15 minutes so I can't use a javascript script wait indicator since that will expire because of the hours of work. I searched all over the internet and forums and I feel I have exhausted all my options. I am very new to the APEX and PL/SQL in general, so your help is very appreciated.
Thank you!!!
Hello Konrad B.!
Try to rewrite the code as shown below:
DECLARE
v_sql VARCHAR2 (32767).
BEGIN
v_sql: = '
BEGIN
ETQUEW. RUN_ADJ_VAR;
END;
';
: P1_JOB: = apex_plsql_job.submit_process (v_sql);
END;
Assume that P1_JOB - question on the page. After submitting the job, this point will be containing number of jobs. The job number,
username (can get APP_USER) and workspace id (can get WORKSPACE_ID) you can check the status
view of working level (field SYSTEM_STATUS) APEX_PLSQL_JOBS:SELECT SYSTEM_STATUS FROM APEX_PLSQL_JOBS WHERE JOB = :P1_JOB AND ANDUSER = :APP_USER AND SECURITY_GROUP_ID = :WORKSPACE_ID
So you can make conditional button, selected example condition "NOT Exists (SQL query returns no rows)" and in the expression type:
Select 1 from apex_plsql_jobs
where employment =: P1_JOB
and end user =: APP_USER
and security_group_id =: WORKSPACE_ID
and system_status in ("in PROGRESS", "SUBMITTED")
If you must run the job for the user, then button will not be returned.
-
PL/SQL function body return query sql, no problem found data
Hi all
We are trying to build a dynamic report based on the selection of the item by the user. We use the SQL query (body of function from PL/SQL returning SQL query). However when a user change the item and submit the page. The following error is displayed.
ORA-01403: no data is found.
our request is simple
declare
l_query varchar2 (30000) default 'select id from chw.
Start
if(:P11_PARA=1) then
l_query: = "select name from chw.
end if;
Return l_query;
end;
any quick help please.Hello
I managed to recreate the error
To remove the error to change the area and choose "use generic Column Names (analysis of query runtime only).
Concerning
Paul
-
[need help] Function body of PL/SQL returning the SQL with BI publisher
Hello
I'm new to BI publisher, back then I used ocj4 for pdf printing, but then we got BI publisher. We want to have a better relationship, since we always used the standard one.
My pl/sql like this look
the question is how can I generate a pdf with this query using BI publisher report, what should I do?DECLARE q varchar2(4000); list_betreuer htmldb_application_global.vc_arr2; list_semester htmldb_application_global.vc_arr2; list_status htmldb_application_global.vc_arr2; BEGIN -- variable to store the list list_betreuer := HTMLDB_UTIL.STRING_TO_TABLE(:P61_BETREUER); list_semester := HTMLDB_UTIL.STRING_TO_TABLE(:P61_SEMESTER); list_status := HTMLDB_UTIL.STRING_TO_TABLE(:P61_STATUS); -- Query begins q:= 'select p1.name, p1.vorname , a1.tel, a2.tel, '; q:= q||'ab.thema, ab.status, ab.typ, s.bezeichnung, p2.name '; q:= q||'from person p1, person p2, adresse a1, adresse a2, '; q:= q||'zuordnungp_a zpa1,zuordnungp_a zpa2, '; q:= q||'abschlussarbeit ab, semester s '; q:= q||'WHERE ab.SEMESTER = s.OBJECTID (+) '; q:= q||'AND ab.STUDENT = p1.OBJECTID (+) '; q:= q||'AND ab.BETREUER = p2.OBJECTID (+) '; q:= q||'and p1.objectid = zpa1.person (+) '; q:= q||'and zpa1.adresse = a1.objectid (+) '; q:= q||'and zpa1.art (+)= ''Privat'' '; q:= q||'and p1.objectid = zpa2.person (+) '; q:= q||'and zpa2.adresse = a2.objectid (+) '; q:= q||'and zpa2.art (+)= ''Geschäft'' '; -- Loop for betreuer list FOR i in 1..list_betreuer.count LOOP IF i = 1 THEN q:= q||'AND (ab.betreuer = '||list_betreuer(i); ELSE q:= q||' OR ab.betreuer = '||list_betreuer(i); END IF; END LOOP; if (list_betreuer.count>0)THEN q:= q||')'; END IF; -- Loop for semester list FOR i in 1..list_semester.count LOOP IF i = 1 THEN q:= q||'AND (ab.semester = '||list_semester(i); ELSE q:= q||'OR ab.semester = '||list_semester(i); END IF; END LOOP; if (list_semester.count>0)THEN q:= q||')'; END IF; -- Loop for status list FOR i in 1..list_status.count LOOP IF i = 1 THEN q:= q||'AND (ab.status = '''||list_status(i)||''''; ELSE q:= q||'OR ab.status = '''||list_status(i)||''''; END IF; END LOOP; if (list_status.count>0)THEN q:= q||')'; END IF; -- htp.p(q); return q; END;
Thanks in advance
DannyCheck this out to see if this helps you. This article talks about passing parameters to the BI publisher of Apex report.
http://tylermuth.WordPress.com/2008/03/31/call-bi-Publisher-Web-services-from-apex/
Thank you!
-
Of course Certified Developer, you can see the left join to include the fields in the SU_EXTENTION_DATA table. Why MAX is used when retrieving these values?
! Wont start-
LEFT JOIN
(SELECT
REF_NO "REF."
MAX (CASE WHEN EXTENSION_FIELD_REF = 500033 THEN VALUE_DATE END) "DOB",.
MAX (CASE WHEN EXTENSION_FIELD_REF = VALUE_STRING END THEN 500034) "E_CONTACT."
MAX (CASE WHEN EXTENSION_FIELD_REF = 500035 THEN VALUE_STRING END) "E_CONT_NO."
MAX (CASE WHEN EXTENSION_FIELD_REF = 500036 THEN VALUE_TEXT END) "MED_HIST."
MAX (CASE WHEN EXTENSION_FIELD_REF = 500037 THEN SELECT_TEXT END) 'PREF_CONTACT '.
OF SU_EXTENSION_DATA
LEFT JOIN SU_SELECT_VALUES ON
SU_EXTENSION_DATA. VALUE_SELECT = SU_SELECT_VALUES. REF
WHERE CORE_ENTITY = 5
REF_NO GROUP) X ON AR_PERSON. REF = X.REF
! End custom-
When you do you must include all the fields that have been selected as criteria for grouping the aggregation OR use false features like MAX (more likely it's easier way when the result field is expression).
-
Function body of pl/sql returning the SQL query
< code >
v_code: = "Code:";
V_calls: = ' calls:';
V_region: =' region:';
v_sql: = ' SELECT "' | v_code | " ' || CODES.NAME | " ' || v_calls | " ' || (select count (t.code) in case where t.code = cases.code group by code) as Total_Calls, "' | V_region | " ' || CASE. Region,
(select count (tt.region) in case t where t.region = cases.region and t.casecode = cases.casecode group by region) as calls
CODES, CASES
where the BUSINESS. CASE CODE = CODES. BRIEFCODE ';
< code >
I have to do a separate on the selection above and I get error when I put as follows.
< code >
v_sql: = ' SELECT distinct "' | v_code | " ' || CODES.NAME | " ' || v_calls | " ' || (select count (t.code) in case where t.code = cases.code group by code) as Total_Calls, "' | V_region | " ' || CASE. Region,
(select count (tt.region) in case t where t.region = cases.region and t.casecode = cases.casecode group by region) as calls
CODES, CASES
where the BUSINESS. CASE CODE = CODES. BRIEFCODE ';
< code >Hello
Try
v_code := 'Code :'; V_calls := 'Calls :'; v_region:='Region:'; v_sql := 'SELECT '''||v_code||'''||CODES.NAME ||'''||v_calls||'''|| (select count(t.code) from cases t where t.code = cases.code group by code ) as Total_Calls, '''||v_region||'''||CASES.REGION Region, (select count(tt.region) from cases t where t.region = cases.region and t.casecode = cases.casecode group by region) as Calls from CODES,CASES where CASES.CASECODE = CODES.BRIEFCODE '; v_sql := 'SELECT DISTINCT * FROM ( ' || v_sql || ')';
Kind regards
Jari -
pl/sql appellant java class member function obtains ora-00932 in 11g.
Call a member function of class of java from a pl/sql script, I get an error ora-00932.
ORA-00932: inconsistent data types: waiting for an IN argument in position 1 which is an instance of an O
convertible to an instance of a user defined class Java got a type of Oracle that could not be converted
The code works fine when the java function is declared static. However, since there could be thousands of users hitting the function at the same time and there is no instance of the object, I wasn't sure if it would be a matter of how oracle manages memory for each user in a session, if it would not be a problem, I can go forward with this approach. However, I have greatly simplified this for an example that reproduces the problem.
Create the oracle type:
CREATE OR REPLACE TYPE MyObject AS OBJECT
(
col1Data VARCHAR2 (10),
MEMBER FUNCTION createData
RETURN VARCHAR2 AS LANGUAGE JAVA
NAME "java.lang.String return MyObject.createData ().
);
Java code:
CREATE OR REPLACE AND FIX JAVA SOURCE NAMED 'MyObject' AS
import java. IO;
public class MyObject
{
private String col1Data;
public void createData)
{
System.out.println ("col1:" + col1Data);
}
}
Java function call vai pl/sql function:
FUNCTION to CREATE or REPLACE fn_myobject
(col1 IN varchar2)
RETURN VARCHAR2
AS
p_rc varchar2 (100);
myObj MyObject;
BEGIN
myObj: = new MyObject (col1);
p_rc: = myObj.createData (); -This line gets an error 00932
RETURN p_rc;
END;
/
And finally, the script from sqlplus to test:
Set serverout
call dbms_java.set_output (50);
Set line 120
declare
VARCHAR2 (64) RC: = ";
R1 varchar2 (64): = 'abc ';
Start
RC: = fn_myobject (r1);
end;
/
I tried all sorts of things without success. Any ideas on this would be most appreciated. It is once again, 11g.
Thank you.
MarkF says:
If you go back to the example code I posted, it is mapping a java class oracle object.
No, it isn't.
Your example simply sets an Oracle object type whose member createData function is implemented in Java.
The fact that the implementing class has the same name does not have a direct mapping between the class and the type of Oracle.
The important part to read and understand in the link I posted is:
A call specification outlines the top level of an Oracle database Java method entry point. So, you can publish only
public
static
methods.However, there is an exception. You can publish instance methods as members of an SQL object type methods.
You are in the first case.
To be in the exceptional cases and be able to publish instance methods, the Java class must implement SQLData.
See the latest example here:
https://docs.Oracle.com/database/121/JJDEV/chsix.htm#JJDEV13273
Adapted to your example:
CREATE OR REPLACE AND compile JAVA SOURCE NAMED "MyObject" AS import java.sql.*; public class MyClass implements SQLData { // Implement the attributes and operations for this type. private String col1Data; public String createData () { System.out.println ("col1: " + col1Data); return col1Data; } // Implement SQLData interface. String sql_type; public String getSQLTypeName() throws SQLException { return sql_type; } public void readSQL(SQLInput stream, String typeName) throws SQLException { sql_type = typeName; col1Data = stream.readString(); } public void writeSQL(SQLOutput stream) throws SQLException { stream.writeString(col1Data); } } /
CREATE OR REPLACE TYPE MyObject AS OBJECT ( col1Data VARCHAR2(10), MEMBER FUNCTION createData RETURN VARCHAR2 AS LANGUAGE JAVA NAME 'MyClass.createData() return java.lang.String' ); /
Test:
SQL> exec dbms_java.set_output(1000) PL/SQL procedure successfully completed. SQL> set serverout on SQL> SQL> select MyObject('ABC').createData() from dual; MYOBJECT('ABC').CREATEDATA() -------------------------------------------------------------------------------- ABC col1: ABC
-
A c from pl/sql function call
Hello
I'm testing a simple case to call a C function from a pl/sql block.
Here's my test case (came to
:)TST.c:
#include < ctype.h >
#include < stdio.h >
int upcase (char * istr, char * ostr)
{
int i = 0;
While (ISTR)
{
OSTR [i] = toupper (istr [i]);
i ++ ;
}
return 0;
}
// compile
gcc -fPIC -c tst.c
// create shared object
ld -shared -o libtest.so tst.o
file libtest.so
libtest.so: ELF 64-bit LSB shared object, AMD x86-64, version 1 (SYSV), not stripped
// wrapper library and function
SQL> create or replace library libtest as '/home/oracle/libtest.so';
/
Library created.create or replace function upcase (instr in varchar2, outstr out varchar2) return directory is
external
libtest library
name 'upcase '.
C language
call the standard C
settings)
string InStr,
outStr string
);
/
Listener.ora:
LISTENER =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(Host = server1) (Port = 1521))
(ADDRESS = (PROTOCOL = ipc) (KEY = EXTPROC))
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = PRD_DGMGRL)
(ORACLE_HOME = home/app/product/11.2.0/jko)
(SID_NAME = PRD)
)
(SID_DESC =
(ORACLE_HOME = home/app/product/11.2.0/jko)
(SID_NAME = PLSExtProc)
(= Extproc PROGRAM)
(ENVS = "EXTPROC_DLLS = ANY")
)
)
LOG_DIRECTORY_LISTENER = / home/app/network/log
CONNECT_TIMEOUT_LISTENER = 10
TRACE_DIRECTORY_LISTENER = / home/app/network/trc
STARTUP_WAIT_TIME_LISTENER = 0
USE_PLUG_AND_PLAY_LISTENER = OFF
ADMIN_RESTRICTIONS_LISTENER = WE
LOG_FILE_LISTENER = listener.log
TRACE_LEVEL_LISTENER = OFF
tnsnames.ora:
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = ipc) (KEY = EXTPROC))
(CONNECT_DATA = (SID = plsextproc))
)
declare
str1 varchar2 (20);
VARCHAR2 (20) str2;
Directory of RC;
Start
str1: = "Hello World";
RC: = upcase (str1, str2);
dbms_output.put_line (' rc ='|) RC: ' instr =' | str1 |' outstr =' | str2);
end;
/
declare
str1 varchar2 (20);
VARCHAR2 (20) str2;
Directory of RC;
Start
str1: = "Hello World";
RC: = upcase (str1, str2);
dbms_output.put_line (' rc ='|) RC: ' instr =' | str1 |' outstr =' | str2);
end;
/
ERROR on line 1:
ORA-28576: interruption of the RPC connection to the external procedure agent
ORA-06512: at "SYS." UPCASE', line 1
ORA-06512: at line 7
How I did wrong?
Thanks a lot for your help
jko
The error means generally that your external procedure (process c in this case), failed or crashed.
The details of the Oracle error:
28576, 00000, "loss of the RPC connection to the external procedure agent."
* Cause: A fatal error occurred either a RPC network connection.
agent extproc or the invoked 3GL after disclosure
was created successfully.
* Action: First check the 3GL code you are calling; the most likely
This error is an abnormal termination of the
called 'C' routine. If this is not the case, look for
network problems. Correct the problem if you find. If all the
components appear normal, but the problem persists, the
problem could be an internal logic error in the transfer of the CPP
code. Contact your customer support representative.Probably the dynamic loader used by the kernel to resolve external dependencies than physical of the executable failed?
Mike Board solves the problem? IMO, it should...
-
Can you pass a SQL function?
I have the following function:
CREATE OR REPLACE PROCEDURE run_query (p_sql IN VARCHAR2) IS
v_v_val VARCHAR2 (4000);
v_n_val NUMBER;
v_d_val DATE;
v_ret NUMBER;
c NUMBER;
d NUMBER;
col_cnt INTEGER.
f BOOLEAN;
rec_tab DBMS_SQL. DESC_TAB;
col_num NUMBER;
v_rowcount NUMBER: = 0;
v_csv VARCHAR2 (32000);
BEGIN
-create a slider
c: = DBMS_SQL. OPEN_CURSOR;
-analyze the SQL statement in the cursor
DBMS_SQL. PARSE (c, p_sql, DBMS_SQL. NATIVE);
-run the cursor
d: = DBMS_SQL. Execute (c);
--
-Describe the columns that are returned by the SQL statement
DBMS_SQL. DESCRIBE_COLUMNS (c, col_cnt, rec_tab);
--
-Local variables Bind to return to the different columns according to their types
1.col_cnt J
LOOP
CASE rec_tab (j) .col_type
WHEN 1 THEN DBMS_SQL. DEFINE_COLUMN (c, j, v_v_val, 2000); -Varchar2
WHEN 2 THEN DBMS_SQL. DEFINE_COLUMN (c, j, v_n_val); -Number
WHEN 12 THEN DBMS_SQL. DEFINE_COLUMN (c, j, v_d_val); -Date
ON THE OTHER
DBMS_SQL. DEFINE_COLUMN (c, j, v_v_val, 2000); -Any other type of return as varchar2
END CASE;
END LOOP;
-This part generates the DATA
LOOP
-Retrieves a row of data using the cursor
v_ret: = DBMS_SQL. FETCH_ROWS (c);
-Output when no more line
WHEN OUTPUT v_ret = 0;
v_rowcount: = v_rowcount + 1;
-Extract the value of each column of the row
1.col_cnt J
LOOP
-Fetch each column to the correct data type according to the description of the column
CASE rec_tab (j) .col_type
WHEN 1 THEN DBMS_SQL. COLUMN_VALUE (c, j, v_v_val);
v_csv: = v_csv | «, » || v_v_val;
WHEN 2 THEN DBMS_SQL. COLUMN_VALUE (c, j, v_n_val);
v_csv: = v_csv | «, » || v_n_val;
WHEN 12 THEN DBMS_SQL. COLUMN_VALUE (c, j, v_d_val);
v_csv: = v_csv | «, » || TO_CHAR (v_d_val, ' DD/MM/YYYY HH24:MI:SS');
ON THE OTHER
DBMS_SQL. COLUMN_VALUE (c, j, v_v_val);
DBMS_OUTPUT. Put_line (v_v_val);
END CASE;
END LOOP;
dbms_output.put_line (substr(v_csv,2));
v_csv: = ";
END LOOP;
DBMS_SQL. CLOSE_CURSOR (c);
END;
/
It allows to feed in an arbitrary query and returned a set of data comma separated. For example:
SQL > run_query exec ('select * from scott.emp where deptno = 10');
7782, CLARK, MANAGER, 7839, 1981/09/06 00:00:00, 2450, 10
7839, KING, PRESIDENT, 17/11/1981-00:00:00, 5000, 10
7934, MILLER, CLERK, 7782, 1982/01/23 00:00:00, 1300, 10
PL/SQL procedure successfully completed.
SQL > exec run_query ("select * from (select * from scott.emp where deptno = 10 order by sal desc) where rownum < 5'");
7839, KING, PRESIDENT, 17/11/1981-00:00:00, 5000, 10
7782, CLARK, MANAGER, 7839, 1981/09/06 00:00:00, 2450, 10
7934, MILLER, CLERK, 7782, 1982/01/23 00:00:00, 1300, 10
(I'm not saying that it is a good practice: on the contrary.) But it is a requirement that was worth and I need to know how to cope, not arguing with it).
My question is: the code works when the application before she includes not single quotes. As soon as he does, he died:
SQL > run_query exec ('select 'Example', sal scott.emp where deptno = 10');
BEGIN run_query ('select 'Example', sal scott.emp where deptno = 10'); END;
*
ERROR on line 1:
ORA-06550: line 1, column 26:
PLS-00103: encountered the symbol "EXAMPLE" when awaits an of the
Next:
), * & = - + <>/ is mod remains not rem = >
< an exponent (*) > <>or! = or ~ = > = < = <>and like2 or
like4 likec in reports between use. Member of type multiset
submultiset
The symbol ", has been inserted before"EXAMPLE"to continue."
I could of course escape quotation marks simple "internal", but the goal is for end-users to feed in their queries, without having to rewrite with delicate escape sequences!
So the question is: is there a way I can allow users to feed their SQL in the procedure without having to worry about the single quotes that might be in the middle of it?
Still, I realize has the risk of SQL injection... but I would like to help on the practicalities of quotes, not managing a risk which I am aware (and dealing with outside the procedural code, that I showed here).
In other words, even if you think it's the worst idea in the world, I still want to know how I could feed 'select 'Example', sal scott.emp where deptno = 10'procedure that it is correctly.
Is there a character that you can be reasonably confident does not appear in the SQL statement? If so, you can probably use the q citing the syntax. For example
SELECT q'{select 'a', 'b', 'c' from dual}' FROM dual
who can get applied to the call to function as well
SQL> exec run_query( q'{select 'a', 'b', 'c' from dual}' ); a b c PL/SQL procedure successfully completed.
If you can be reasonably sure that there is no {or} character (or a number of other pairs), you can just that wrap the SQL statement. Of course, this assumes that there is some bit of code enforcement between the user and the procedure call that can add to the {and}. If this is the case, you could also just double apostrophes that meet you.
Justin
-
Separate function in Advance Sql
Hello
In OBIEE 10 g, I need to write a separate query for an attribute (City) in advance filter SQL.
Please send me the syntax to use the distinct function in the Advanced SQL filter.City (SELECT DISTINCT CITY FROM SUBJECT AREA WHERE CONDITION) - filter advanced
Maybe you are looking for
-
How can I get rid of "ding" when email arrives?
How can I get rid of the notification of "ding" when email arrives in the mail? I already disabled "play a sound for notifications" in System Preferences/Notifications/Mail.
-
Satellite L50 - battery recharge even if it works?
Hello! I'm here because I don't know where else to find an answer. Yesterday, I changed the hinges, the plastic cover and the chassis of a L50. No problem at all.I have reset the motherboard, disconnect the battery and keeping the start button for a
-
J 6480 / Vista Home Premium, HP DV 6928: creation of a unique facility
J 6480 / Vista Home Premium, HP DV 6928, also HP LJ 1020 for printing in b/w normal, which is hard wired for laptop: Finally implemented my 6480 J. Read about some installation issues and a few thoughts on the wire «Wireless and network print transcr
-
Install xp (without cd-rom)
Hello I have x 200 laptop (without cd-rom). I want to format and install a fresh copy of xp pro. How can I make without CD? Best regards GIYORA Moderator Note: subject line adjusted for clarity.
-
The upgrade Options of unique language of Windows 8 for Windows 8 Pro
I use a portable 5 year old that I have upgraded to Windows 8 Pro 32-bit in October 2012, when Windows 8 was launched. I have the product key with me. But now the laptop is proving to be too old and often runs into problems due to old equipment and I