Complicated PL/SQL questions that involves function with in type parameter
Hello,
I have a question about functions with in-parameters. In the HR schema, I need to get the minimum salary of the job_id that is mentioned as an in-parameter.
this is what I am thinking but I dont know if it's correct or not or what should I do next!
create or replace function get_min_salary (i_job_id in varchar2)
return number
as
min_sal jobs.min_salary%type;
begin
SELECT min_salary INTO min_sal
FROM jobs
where job_id = i_job_id;
RETURN min_sal;
end get_min_salary;if the i_job_id which is the in type parameter does not have a minimum salary then use the following function to register an error:
create or replace procedure insert_error (i_error_code in number,
i_error_message in varchar2)
as
begin
insert into error_table (error_user, error_date, error_code, error_message)
values (user,sysdate,i_error_code,i_error_message);
end insert_error;This function is basically to say that an error has occured and to register that error, at the same time I need to print out the error using the dbms_out.put_line.
Any ideas of how to do that?
Thanks in advance
>
minimum salary of the job_id
>
may be
SELECT min(min_salary) INTO min_sal
FROM jobs
where job_id = i_job_id;
if the i_job_id which is the in type parameter does not have a minimum salary then use the following function to register an error:why error?
This function is basically to say that an error has occured and to register that error, at the same time I need to print out the error using the dbms_out.put_line.
create or replace procedure insert_error (i_error_code in number,
i_error_message in varchar2)
as
begin
insert into error_table (error_user, error_date, error_code, error_message)
values (user,sysdate,i_error_code,i_error_message);
-- this
dbms_out.put_line('this');
end insert_error;
Similar Messages
-
How to define a function with table type parameter
Hello All,
Here is the requirement ..
cursor c is select first_name, last_name , ssn from employee ;
TYPE employee_type IS TABLE OF c%rowtype;
tbl_employee_type employee_type;
I want to pass the parameter to a function the ssn -: tbl_employee_type(1).ssn
how the formal parameter should be declared
===========================
function chk_notnull_blank ( ? ) return boolean is
BEGIN
if ( colname is NOT NULL and colname in ( -8E14, -7E14, -6E14, -5E14, -4E14, -3E14, -2E14, -1E14, -1E9 )) then
RETURN TRUE ;
else
RETURN FALSE ;
end if;
END chk_notnull_blank;
======================
pls advice
thanks/kumarYou cannot define a generic argument in a function,
but you can overload several funtions with the same name and different types of arguments in a package,
in this way (not tested):
create table employees as
select employee_id ssn, first_name, last_name from hr.employees;
create or replace
PACKAGE chk
IS
cursor c is select first_name, last_name , ssn from employees ;
TYPE employee_type IS TABLE OF c%rowtype;
TYPE employee_ssn_type IS TABLE OF employees.ssn%TYPE;
TYPE employee_num_type IS TABLE OF number;
FUNCTION chk_notnull_blank ( colname employees.ssn%TYPE) RETURN boolean;
FUNCTION chk_notnull_blank ( colnames employee_type) RETURN boolean;
FUNCTION chk_notnull_blank ( colnames employee_ssn_type) RETURN boolean;
FUNCTION chk_notnull_blank ( colnames employee_num_type) RETURN boolean;
END chk;
create or replace
PACKAGE BODY chk
IS
FUNCTION chk_notnull_blank ( colname employees.ssn%TYPE) RETURN boolean IS
BEGIN
if ( colname is NOT NULL and colname in ( -8E14, -7E14, -6E14, -5E14, -4E14, -3E14, -2E14, -1E14, -1E9 )) then
RETURN TRUE ;
else
RETURN FALSE ;
END IF;
END chk_notnull_blank;
FUNCTION chk_notnull_blank ( colnames employee_type) RETURN boolean IS
BEGIN
FOR i IN colnames.FIRST .. colnames.LAST LOOP
IF NOT chk_notnull_blank( colnames( i ).ssn )
THEN
RETURN FALSE;
END IF;
END LOOP;
RETURN true;
END chk_notnull_blank;
FUNCTION chk_notnull_blank ( colnames employee_ssn_type) RETURN boolean
IS
BEGIN
FOR i IN colnames.FIRST .. colnames.LAST LOOP
IF NOT chk_notnull_blank( colnames( i ) )
THEN
RETURN FALSE;
END IF;
END LOOP;
RETURN TRUE;
END chk_notnull_blank;
FUNCTION chk_notnull_blank ( colnames employee_num_type) RETURN boolean
IS
BEGIN
FOR i IN colnames.FIRST .. colnames.LAST LOOP
IF NOT chk_notnull_blank( colnames( i ) )
THEN
RETURN FALSE;
END IF;
END LOOP;
RETURN TRUE;
END chk_notnull_blank;
END chk;I assumed in this example that if the argument of the function chk_notnull_blank is of the table (collection) type,
then the function returns true if all table elements pass the check, otherwise it returns false. -
Facebook (FB) recently restructured their website. After logging on to my FB homepage, some of the graphics are garbled and I am no longer able to post status updates, comment on friend's status updates or pictures, or post pictures using Firefox version 2.0.0.20. I would like to know if there is a newer version of Firefox that will function with a Mac G3 Blue and White desktop running OS 10.3.9 which will be compatible with the new FB? I would upgrade my computer, but have 22+ years of business and tax records that will not function with the newer Mac OS.
Other browsers that you can look at:
* Camino: http://caminobrowser.org/download/releases/
* [http://en.wikipedia.org/wiki/ICab iCab]: http://www.icab.de/dl.php
* SeaMonkey: http://www.seamonkey-project.org/releases/seamonkey1.1.19 -
Is it pssible to acquire a version of PAGES that will function with osx 10.6.8 ???
You will have to buy the retail box from a third party such as Amazon.com or on eBay.
-
i forgot my iCloud password and the questions that were associated with the account is there any way to resolve this
No one here can help you.
Contact Apple. -
Function with return type boolean
I have created a function with return type boolean as:
CREATE OR REPLACE FUNCTION fn RETURN BOOLEAN
AS
exp EXCEPTION;
BEGIN
return TRUE;
EXCEPTION
when OTHERS then RAISE exp;
END;
FUNCTION fn compiledThen I was trying to call this function into dbms_output.put_line procedure, I got this error:
EXECUTE DBMS_OUTPUT.PUT_LINE(fn);
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'Can someone please help me understand, why this happened?
Is this because of boolean return type?952040 wrote:
I have created a function with return type boolean as:
Then I was trying to call this function into dbms_output.put_line procedure, I got this error:
EXECUTE DBMS_OUTPUT.PUT_LINE(fn);
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'
What is the parameter signature for DBMS_OUTPUT.put_line() ?
Is is string - as detailed in Oracle® Database PL/SQL Packages and Types Reference guide.
So how can you pass a boolean data type as parameter value, when the parameter's data type is string?
PL/SQL supports implicit data conversion. So you can for example pass a number or date value to DBMS_OUTPUT.put_line() - and the PL/SQL engine automatically (and implicitly) converts that (using the TO_CHAR() functions) to a string.
However, the TO_CHAR() parameter signature supports number and date - not boolean. It cannot convert a boolean value into a string.
So passing a boolean value means the implicit conversion fails - and results in the above error.
To make it work, you need to perform an explicit conversion. As as a data type conversion function from boolean to string is not available, you need to write a user defined function. E.g.
SQL> create or replace function BoolToChar( b boolean ) return varchar2 is
2 begin
3 case
4 when b then return( 'TRUE' );
5 when not b then return( 'FALSE' );
6 else
7 return( null );
8 end case;
9 end;
10 /
Function created.
SQL>
SQL> exec DBMS_OUTPUT.put_line( 'Flag is '||BoolToChar(true) );
Flag is TRUE
PL/SQL procedure successfully completed -
How can I Create function with an out Parameter
how all
how can I Create function with an out Parameter
I try to create it it sucess but how can I CALL it , it give me error
please I want A simple example
thanks3rd post on same question by same user :
Re: how can I Create function with an out Parameter
how can I Create function with an out Parameter -
How to create a function with ref_cursor as parameter in OWB 10.1
Hi,
Can any one help me how to create a function with ref_cursor as parameter in OWB 10.1.?
Its urgent. Please help me.
Thanks,
SivHi David,
Thanks for your reply.
Before going for this function, I need to create a package in transformation node in owb module.
My package is as follows,
Create or replace package 123
type xxx is RECORD ( parameters);
type yyy is RECORD (parameters);
type aaa is table of yyy;
type bbb is REF CURSOR return xxx;
type ccc is record (parameters);
type ddd is ref cursor return eee;
END;
How can I create the above kind of package manually in OWB 10.1 (Should not to import the package)
Please help me its urgent.
Thanks,
Siv -
After install Lightroom 5.3 we cannot resized a pict in export function with "bord etroit" parameter. It's good with "bord large"!...
Regards
JacquesDanCarr wrote:
I'm sure this was working in the previous version......
Yep - new bug in Lr5.3 (presumably will be fixed in Lr5.4).
More info here:
http://feedback.photoshop.com/photoshop_family/topics/publish_service_harddisk_ignores_ima ge_sizing_resize_to_fit_short_edge_setting_when_source_image_is_a_dng_on_lightroom -
Using PL/SQL Function with CLOB types and a Java Source
Hi people.
I have some problems trying to use a function in pl/sql with a CLOB parameter to a java source function.
Here is the problem: I have to read a TXT file and return a CLOB with the data of the file. The reading is done with a java source function.
The problem is how to read the file without messing the content and return it to the pl/sql function?
Another problem: If I pass a CLOB as a parameter to a pl/sql function and have to write the content to a file, how to do it without screwing the EOL chars and so?
My code is:
/******** PLSQL FUNCTIONS ********/
function fn_gravaconteudoarquivo( pv_caminho in varchar2
, pv_nomearquivo in varchar2
, pc_conteudo in clob ) return varchar2 as language java
name 'Importacao.gravaConteudoArquivo(java.lang.String, java.lang.String, oracle.sql.CLOB) return varchar2';
function fn_lerconteudoarquivoclob( pv_caminho in varchar2
, pv_nomearquivo in varchar2 ) return clob as language java
name 'Importacao.lerArquivoClob(java.lang.String, java.lang.String) return clob';
/******** JAVA SOURCE FUNCTIONS *********/
public static String gravaConteudoArquivo(String caminho, String nomeArquivo, CLOB conteudo) {
File file = new File(caminho, nomeArquivo);
PrintWriter pwFile;
String mensagem = "";
StringBuffer sb = new StringBuffer();
try {
pwFile = new PrintWriter(new BufferedWriter(new FileWriter(file,true)));
for (int i=0;i<=(conteudo.length()/32000);i++) {
sb.append(conteudo.getSubString(conteudo.getLength()+1,32000));
pwFile.println(sb.substring(0));
pwFile.close();
} catch (Exception ex) {
mensagem = "Erro: "+ex;
return mensagem;
public static CLOB lerArquivoClob(String caminho, String nomeArquivo) throws SQLException {
File file = new File(caminho, nomeArquivo);
Connection conn;
CLOB clob = null;
String lineSep = System.getProperty("line.separator");
StringBuffer sb = new StringBuffer();
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:csdesv", "csestoque", "liberada");
clob = CLOB.createTemporary(conn, true, CLOB.DURATION_SESSION);
BufferedReader brFile = new BufferedReader(new FileReader(file.getPath()));
while (brFile.ready()) {
sb.append(brFile.readLine());
sb.append(lineSep);
clob.open(CLOB.MODE_READWRITE);
clob.setString(clob.getLength()+1, sb.toString());
clob.close();
} catch (Exception ex) {
ex.printStackTrace();
return clob;
Ah, just remembered... This will work as a JOB.... >.< ... So the connection aparently is at localhost.
Thanks.No one? I really need this....
-
Xdk: calling java function with a CharSequence parameter
When using xdk version 10.1.0.2.0_production, you can not call a javamethod with a CharSequence parameter.
Sun documentation:
Interface CharSequence
All Known Implementing Classes:
CharBuffer, String, StringBuffer
This prevents us from calling a method like
java.util.regex.Pattern.matches(String, CharSequence)
Converting the parameter to a normal string would solve the problem.
Example to illustrate the issue:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes" xmlns:Pattern="http://www.oracle.com/XSL/Transform/java/java.util.regex.Pattern">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:if test="Pattern:matches('...','123')">
<xsl:text>MATCH</xsl:text>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
results in the following stacktrace:
oracle.xml.parser.v2.XPathException: Extension function error: Error invoking 'matches':'java.lang.NullPointerException'
at oracle.xml.parser.v2.XSLExtFunctions.callStaticMethod(XSLExtFunctions.java:113)
at oracle.xml.parser.v2.XPathExtFunction.evaluateMethod(XPathExtFunction.java:296)
at oracle.xml.parser.v2.XPathExtFunction.evaluate(XPathExtFunction.java:223)
at oracle.xml.parser.v2.XSLCondition.testCondition(XSLCondition.java:185)
at oracle.xml.parser.v2.XSLCondition.processAction(XSLCondition.java:165)
at oracle.xml.parser.v2.XSLNode.processChildren(XSLNode.java:403)
at oracle.xml.parser.v2.XSLTemplate.processAction(XSLTemplate.java:191)
at oracle.xml.parser.v2.XSLStylesheet.execute(XSLStylesheet.java:507)
at oracle.xml.parser.v2.XSLStylesheet.execute(XSLStylesheet.java:484)
at oracle.xml.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:256)
at oracle.xml.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:146)
at oracle.xml.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:218)
at XSLSample.main(XSLSample.java:75)
Message was edited by:
user449717Hi Grarup,
I took a stab at getting this to run and compile and this is what I came up with. Let me know if this helps at all.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
class Program
static void Main(string[] args)
Console.WriteLine("\"True\" or \"False\"?");
bool boolVal = bool.Parse(Console.ReadLine());
Functions f = new Functions();
TestStruct t = new TestStruct() { Value = boolVal };
f.Flip(ref t);
Console.WriteLine(string.Format("Flipped value = {0}: ", t.Value));
Console.ReadLine();
public struct TestStruct
public bool Value;
public class Functions
public void Flip(ref TestStruct testStruct)
testStruct.Value = !testStruct.Value;
Best of luck. -
Is it possible to call dll-functions with records/types as arguments?
or must I use the fixed preselection of types
LabVIEW must call DLLs with data types it is compatible. Therefore, you must use the types available through LabVIEW.
I have two pieces of advice on this matter:
First, contact NI and get their advice on how to call your data type. They may be able to offer a very quick solution.
Second, if you cannot call these data types, and you have a compiler, I would suggest "wrapping" the DLL inside another, and 'translate' the data type from something LabVIEW can handle, to the type needed by your DLL in this 'wrapper' DLL. -
HTTPS Receiver Adapter POST with FILE TYPE parameter
Hello,
I need to do a POST to a URL service that validates content of a file. It receives user and password as string parameters and a FILE as a mime type parameter.
I'll appreciate any help.
Regards,
Diego.Hi.
Using Http Receiver Adapter , you can try out this.
This blog may give some idea-
/people/amol.joshi2/blog/2006/06/28/must-fire-a-http-get-from-xi---try-this
Otherwise, try out with callinng this service via SOAP Adapter i.e webservice.
Rgds,
moorthy -
Coul anyone help me with a sql query that involves a jcombobox?
HI all
i'm writing this program in wich i want to query a table in a ms access db. My os is win2000 and i use access2000.
so i have a list of categories in a jcombobox.When one of the categories is selected i have to display the corresponding product for that category in a jtext area.
I wrote the code.But i keep getting an erro at run time when i selct an item from the combobox wich is :
SQL Error: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]Invalid descriptor index 20 S1002
here's my code:
boxcategories.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox cb = (JComboBox)e.getSource();
String mySelection = (String)cb.getSelectedItem();
//connecting to the data base
Connection connec;
String data = "jdbc:odbc:MyDB";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connec = DriverManager.getConnection(
data , "", "");
PreparedStatement ps = connec.prepareStatement(" SELECT Category from products"+
" WHERE Category =?");
ps.setString(1,mySelection );
ResultSet rs = ps.executeQuery();
if (rs.next() ) {
products.append(rs.getString(1)+"\t"+
rs.getString(2)+"\t\t"+
"$" rs.getString(4) "\t ");
} catch (SQLException s) {
System.out.println("SQL Error: " + s.toString() + " "
+ s.getErrorCode() + " " + s.getSQLState());
} catch (Exception x) {
System.out.println("Error: " + x.toString()
+ x.getMessage());
so what do u think i should do
Franckhi
i'm having a problem with this query.When i select a categoryfrom
the combobox,i only get one corresponding product displayed in the jtextarea
I tryed everythin but i cant get this code to work correctly.
i want that when i select a category from the combobox that the corresponding product of wich the in stock quantity is >20 to be displayed
in one jtext area and thos who's in stock quantity is < in another jtext area
What should i do?
here's my code
boxcategories.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox cb = (JComboBox)e.getSource();
String mySelection = (String)cb.getSelectedItem();
//connecting to the data base
Connection connec;
String data = "jdbc:odbc:MyDB";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connec = DriverManager.getConnection(
data , "", "");
PreparedStatement ps = connec.prepareStatement(" SELECT Category from products"+
" WHERE Category =?");
ps.setString(1,mySelection );
ResultSet rs = ps.executeQuery();
if (rs.next() ) {
products.setText((rs.getInt(1)+"\t"+
rs.getString(2)+"\t\t"+
"$" rs.getFloat(4) "\t " rs.getInt(5) "\n" );
if(rs.getInt(5) < 20)
products1.setText(rs.getInt(1)+"\t"+
rs.getString(2)+"\t\t"+
"$" rs.getFloat(4) "\t " + rs.getInt(5) +"\n" );
else
produitdescription.setText("");produitdescription1.setText("");
} catch (SQLException s) {
System.out.println("SQL Error: " + s.toString() + " "
+ s.getErrorCode() + " " + s.getSQLState());
} catch (Exception x) {
System.out.println("Error: " + x.toString()
+ x.getMessage());
when i selct a category i get this runtime error at the same time the product is displayed
SQL Error: java.sql.SQLException: No data found 0 null
what should i do
FRanck -
SQL question that's always bugged me
SQL> select * from customer where customer_id = 4;
no rows selected
SQL> select max(customer_id) from customer where customer_id = 4;
MAX(CUSTOMER_ID)
SQL>
WHY!!!!!
This has been driving me nuts, for the past hour or so trying to hunt down a bug in some code, it turned out that due to the max() a function wasn't raising a NO_DATA_FOUND exception and failing elsewhere with an obscure error because of it. after a "select max() into" clause, we have to add an additional check to see if the value it selected into is null or not..... how dumb is that?
ok, I've calmed down now.Michael:
Both seem quite reasonable to me. Conceptually. ignoring the GROUP BY bit, a COUNT works like:
DECLARE
l_cnt NUMBER :=0;
BEGIN
FOR r IN (<query>) LOOP
l_cnt := l_cnt + 1;
END LOOP;
RETURN l_cnt;
END;While a MAX or MIN works like:
DECLARE
l_max VARCHAR2(4000) := NULL;
FOR r IN (<query>) LOOP
IF r.max_col > l_max THEN
l_max := r.max_col;
END IF;
END LOOP;
RETURN l_max;
END;I'm sure that Oracle has more efficient algorithms, but the point is that the aggregate functions iterate over a result set to generate the result The fact that the result set is empty in some cases doesn't really matter.
Think about what it would mean if some aggregates, like COUNT or SUM, never threw NO_DATA_FOUND, but others like MAX OR MIN did if there were no rows matching the criteria.
In both of your example cases. grouping does take place:
SQL> SELECT COUNT(*) FROM employees;
COUNT(*)
107
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=1)
1 0 SORT (AGGREGATE)
2 1 INDEX (FULL SCAN) OF 'EMP_EMAIL_UK' (UNIQUE) (Cost=1 Card=107)It is just that the group is all of the records.
John
Message was edited by:
John Spencer
Added the grouping comments.
Maybe you are looking for
-
Mavericks 10.9.5 -- Brother MFC-7320 does not work.
Hi apple folks, Mavericks 10.9.5 --> Brother MFC-7320 does not work. I just have downloaded the driver form http://support.brother.com/g/b/downloadhowto.aspx?c=gb&lang=en&prod=mfc7320_eu&o s=132&dlid=dlf005077_000&flang=4&type3=20 Despite the fact th
-
Hi We created 2 variables on 0CALDAY in a report. Var1: MTD (month to date) Var2: YTD (Year to date) We have written code in CMOD and is working fine. We transported this code to production and in PRd we can see this code. We transported few queries
-
Can Oracle 11g RAC and 10g RAC co-exists on same host
Can somebody tell me if it is possible to have Oracle 11g and 10g RAC installed and configured on same host. Thanks, -Zubair
-
Hi I had a BB curve9630 was locked for Vodafone and I unlocked it and I'm using another Provider , my main problem, I subscribed to BB services ( mail and internet) , the problem that everything is ok, I received the registration message, I can use F
-
Is there a way (any way) to get a simplified oracle driver?
I'm a newbie on a Oracle DB world and I need to give users a Oracle driver to access Oracle 8.1.7 database by windows ODBC. It said that one must install oracle client (a 220M big guy). I would like to know is there a way, (any way) to give users (wh