Using simple functions in JSP

Hi to all,
I would to use simple functions in my jsp page.
I 've created the function with the tags <%! ... %>
My problem is that i don't succed to call there from the page.
How i can to do ?
I've tried also with java beans but i'm not very clever with there also so i don't can to go forward !!!
Please help me. thanks

Hi, a new problem rises now.
the problem is into the method ctr_data().
Under i put the jsp code and the error:
Anyone can see where is the error please?
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import= "java.sql.*,  java.lang.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Progetto Sofia - Registrazione utente</title>
</head>
<%!
public boolean ctr_lunghezza(String s1){
    if (s1.length() == 0) return false;
    return true;
%>
<%!
public boolean isLeapYear(int year) {
       if (year%400 == 0)  return true;
       if ((year%4 == 0) && (year%100 != 0))return true;
       return false;
%>
<%!
public boolean ctr_data (String gg, String mm, String aa){
    int anno = Integer.valueOf(aa).intValue();
    int mese = Integer.valueOf(mm).intValue();
    int giorno = Integer.valueOf(gg).intValue();
    if ((gg.length() == 0) || (mm.length() == 0) || (aa.length() == 0))
        return false;
    if ((anno < 1905) || (anno > 2005))
        return false;
    if (mese == 2){
        if (isLeapYear(anno)){
            if (giorno > 29) return false;
        }else{
            if (giorno > 28) return false;
    if ((mese == 11) || (mese == 4) || (mese == 6) || (mese == 9)){
        if (giorno == 31) return false;
    return true;
%>
<%
int flag = 0;
String risposta = "";
String temp ="";
temp = (request.getParameter("nome_utente")!=null)?request.getParameter("nome_utente") :"";
if (ctr_lunghezza (temp) == false){
   risposta = risposta.concat("Attenzione --- Riempire il campo: Nome\n");
   flag++;
temp = (request.getParameter("cognome_utente")!=null)?request.getParameter("cognome_utente"):"";
if (!ctr_lunghezza (temp)){
    risposta = risposta.concat("Attenzione --- Riempire il campo: Cognome\n");
    flag++;
String gg1 = (request.getParameter("giorno_n_utente")!=null)?request.getParameter("giorno_n_utente"):"0";
String mm1 = (request.getParameter("mese_n_utente")!=null)?request.getParameter("mese_n_utente"):"0";
String aa1 = (request.getParameter("anno_n_utente")!=null)?request.getParameter("anno_n_utente"):"0";
if (!ctr_data(gg1, mm1, aa1)){
    risposta = risposta.concat("Attenzione --- Data di nascita non corretta\n");
    flag++;
temp = (request.getParameter("luogo_n_utente")!=null)?request.getParameter("luogo_n_utente"):"";
if (!ctr_lunghezza (temp)){
    risposta = risposta.concat("Attenzione --- Riempire il campo: Luogo di nascita\n");
    flag++;
temp = (request.getParameter("res_utente")!=null)?request.getParameter("res_utente"):" ";
if (temp == "Seleziona"){
    risposta = risposta.concat("Attenzione --- Selezionare il Comune di Residenza\n");
    flag++;
temp = (request.getParameter("ind_utente")!=null)?request.getParameter("ind_utente"):" ";
if (!ctr_lunghezza(temp)){ 
    risposta = risposta.concat("Attenzione --- Riempire il campo Indirizzo\n");
    flag++;
%>and this is the error msg:
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: For input string: ""
     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.NumberFormatException: For input string: ""
     java.lang.NumberFormatException.forInputString(Unknown Source)
     java.lang.Integer.parseInt(Unknown Source)
     java.lang.Integer.valueOf(Unknown Source)
     org.apache.jsp.progetto.w2.web.Reg_005futente_jsp.ctr_data(org.apache.jsp.progetto.w2.web.Reg_005futente_jsp:27)
     org.apache.jsp.progetto.w2.web.Reg_005futente_jsp._jspService(org.apache.jsp.progetto.w2.web.Reg_005futente_jsp:122)
     org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Similar Messages

  • Authentication failed while using the function from JSP.

    I am facing a issue with the mail functionality with JAVA Mailing.The problem is that when I am running the stand alone program it is working fine but when same function is called from a JSP it gives Authentication failed Exception.I am attaching the code with the case.testMail() Is the function called from the JSP.
    Please Look in to the issue its urgent.
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.*;
    import java.io.*;
    import javax.activation.DataHandler;
    import javax.mail.MessagingException;
    import javax.mail.internet.MimeBodyPart;
    import javax.mail.internet.MimeMessage;
    import javax.mail.internet.MimeMultipart;
    import javax.mail.internet.MimePartDataSource;
    To use this program, change values for the following three constants,
    SMTP_HOST_NAME -- Has your SMTP Host Name
    SMTP_AUTH_USER -- Has your SMTP Authentication UserName
    SMTP_AUTH_PWD -- Has your SMTP Authentication Password
    Next change values for fields
    emailMsgTxt -- Message Text for the Email
    emailSubjectTxt -- Subject for email
    emailFromAddress -- Email Address whose name will appears as "from" address
    Next change value for "emailList".
    This String array has List of all Email Addresses to Email Email needs to be sent to.
    Next to run the program, execute it as follows,
    SendMailUsingAuthentication authProg = new SendMailUsingAuthentication();
    public class SendMailUsingAuthentication
    private static final String SMTP_HOST_NAME = "host";
    private static final String SMTP_AUTH_USER = "username";
    private static final String SMTP_AUTH_PWD = "password";
    private static final String emailMsgTxt = "Test Msg";
    private static final String emailSubjectTxt = "Notification: New User created";
    private static final String emailFromAddress = "[email protected]";
    // Add List of Email address to who email needs to be sent to
    private static final String[] emailList = {"[email protected]"};
    public static void main(String args[]) throws Exception
    SendMailUsingAuthentication smtpMailSender = new SendMailUsingAuthentication();
    smtpMailSender.postMail( emailList, emailSubjectTxt, emailMsgTxt, emailFromAddress);
    System.out.println("Sucessfully Sent mail to All Users");
    public void testMail(String msgBody,String senderEmail)throws MessagingException
    try{
         String mailBody = msgBody;
         String senderEmailAdd = senderEmail;
         SendMailUsingAuthentication smtpMailSender = new SendMailUsingAuthentication();
         smtpMailSender.postMail( emailList, emailSubjectTxt, mailBody , senderEmail);
         catch(MessagingException me) {
                   //System.out.println("Mail not sent");
                   throw me;
    public void postMail( String recipients[ ], String subject,
    String message , String from) throws MessagingException
    try{
         boolean debug = false;
    //Set the host smtp address
    Properties props = System.getProperties();
    props.put("mail.smtp.host", SMTP_HOST_NAME);
    props.put("mail.smtp.auth", "true");
    Authenticator auth = new SMTPAuthenticator();
    Session session = Session.getInstance(props, auth);
    session.setDebug(debug);
    // create a message
    Message msg = new MimeMessage(session);
    // set the from and to address
    InternetAddress addressFrom = new InternetAddress(from);
    msg.setFrom(addressFrom);
    InternetAddress[] addressTo = new InternetAddress[recipients.length];
    for (int i = 0; i < recipients.length; i++)
    addressTo[i] = new InternetAddress(recipients);
    msg.setRecipients(Message.RecipientType.TO, addressTo);
    // Setting the Subject and Content Type
    msg.setSubject(subject);
    msg.setContent(message, "text/plain");
    Transport.send(msg);
         catch(MessagingException me) {
                   //System.out.println("Mail not sent");
                   throw me;
    * SimpleAuthenticator is used to do simple authentication
    * when the SMTP server requires it.
    public static class SMTPAuthenticator extends javax.mail.Authenticator
    public PasswordAuthentication getPasswordAuthentication()
    String username = SMTP_AUTH_USER;
    String password = SMTP_AUTH_PWD;
              return new PasswordAuthentication(username, password);

    Your code doesn't work in stand alone program... just little mistake!
    Miss port property :
    props.put("mail.smtp.port", "25");
    props.put("mail.smtp.starttls.enable", "true"); // tls for gmail
    AddressTo method didn' t compile :
    InternetAddress[] addressTo = new InternetAddress[recipients.length];
    for (int i = 0; i < recipients.length; i++)
         addressTo[i] = new InternetAddress((String) recipients);
    msg.setRecipients(Message.RecipientType.TO, addressTo);
    And see this post for jsp integration :
    http://forum.java.sun.com/thread.jspa?threadID=5184860&tstart=0

  • How to pass servlet parameter using encodeURL function in JSP page

    Hi!!!
    I have a very urgently problem.
    in my JSP I have this:
    <IMG border="0" src='<%=response.encodeURL("/MyImageServlet")%>'>
    In this way, my servlet works fine (and I have in my page my blob-image).
    But I have to pass to my servlet a list of dynamic parameter. I have tried all the possibilities like:
    <IMG border="0" src='<%= (response.encodeURL("/MyImageServlet") + "?Param_name=" + sessionBean.getParamValue() + "&anotherParam" + sessionBean.getAnotherParamValue())%>'
    but nothing....
    In my servlet I use the init function to retrieve the initial parameters(defined in my web.xml file) in this way:
    public void init(ServletConfig config) throws ServletException
    super.init(config);
    myParam = getInitParameter( "name_of_param");
    but I retrieve only the default value (-1).
    How to pass to my servlet the parameters? Please help me!
    Excuse me for my english,
    thank you for your help!

    Hi!
    Thanks for your reply!
    I have tried this solution but it doesn't work!
    When I do getInitParameter in the init function, the servlet take the default values...
    Maybe I have wrote something wrong?
    Excuse me for my english,
    Thanks

  • How to show simple chinese in jsp

    when I use simple chinese in jsp,in the portlet all the char convert into B>B-C&#147;B*B;C.B6B/,but in the servlet,all the simple chinese char it right,I have set the conentType = "text/html;gb2312",but the problem is still.
    somebody can help me!
    thanks!

    You have to set the content type on your response firts.
    eg; response.setContentType("image/gif");

  • How to use session variable in JSP function  & How to use both JSP  Servlet

    Hi,
    I am new to JSP and servlets
    Still I am devloping a website in JSP. I am not mixing JSP with servlets, but I do create Java files for bean, logic and database works.
    I try to keep the hard coding part out of JSP.
    I dont how to use both JSP and Servlets in combination.
    Hence If needed I write some functions in JSP.
    but it gives me error
    +<%! public void abc()+
    +{+
    int intUserId = Integer.valueOf((Integer) session.getAttribute("MySession_UserID"));
    +}+
    +%>+
    Saying cannot find symbol session
    1) So can u please tell how can I access session variables within JSP function
    2) And also give me some links/tutorials about useing both JSP and Servlets in combination.
    Thanks
    Venkat

    The application architecture when you use Servlets and JSP in a standard MVC pattern is explained here (under the heading "Integrating Servlets and JSP Pages") and here ...

  • Equivalent function of JSP:include or @include?

    Could someone please let me know how I can include html pages in a java servlet page? I am looking for similar function as JSP include. A simple example would be must appreciated. Thanks!

    Thanks for you reply. Actually, what I want to do is to import/include a static html page to my java servlet page. I do not want to use JSP because all the pages created were sevlet. I found out a way that using getServletcontext.getResource to read in the html page and print it out from the servlet. Just wondering that if there is a better way to do this?

  • OnBlur() function and JSP

    Hello Everybody!
    I'd like to knwo how can I use onBlur() function to make my SELECT form works without submit...
    Pratically, I need that, when a use "blur" a voice in the firs SELECT form, the second SELECT change without making a submit.
    The problem is that this JSP calls a Servlet that builds a bean, but the solution may be very simple, because I only need (if the user select a particular voice in the first SELECT) to inhibit the second and the third SELECT..
    <form name="nuovo" action="TicketHandler" method="post">
    <table >
    <tr><td>
    <b>Programma</b></td>
    <td><select name="programma">
    <%     dati_bean = bean.Dati_Programma_Ticket();          
         Iterator Idati_bean2 = dati_bean.iterator();
         while (Idati_bean2.hasNext()){
            SQLBean myBean = (SQLBean)Idati_bean2.next();           
              String programma = myBean.getParametro();
              %>
    <option><%=programma%></option>
    <%}
    %>
    </select></td></tr>
    <tr><td>
    <b>Relase</b></td>
    <td><select name="relase">
    <%     dati_bean = bean.Dati_Relase_Ticket();          
         Iterator Idati_bean3 = dati_bean.iterator();
         while (Idati_bean3.hasNext()){
            SQLBean myBean = (SQLBean)Idati_bean3.next();           
              String relase = myBean.getParametro();
              %>
    <option><%=relase%></option>
    <%}%>
    </select></td></tr>
    <tr><td>
    <b>Modulo</b></td>
    <td><select name="modulo">
    <%     dati_bean = bean.Dati_Modulo_Ticket();          
         Iterator Idati_bean = dati_bean.iterator();
         while (Idati_bean.hasNext()){
            SQLBean myBean = (SQLBean)Idati_bean.next();           
              String modulo = myBean.getParametro();
              %>
    <option><%=modulo%></option>
    <%}
    %>

    I know there's a javascript way to build a dynamic drop down list, but I was ooking for a "merged" Javascript+Java JSP recursive example! ( I need 3 different dropdown recursively dependet the second from the first and the third from the second..)
    anyone can helps?

  • Creating Report using EPM Functions with Dynamic Filters

    Hi All,
    I am new to BPC, In BPC 7.5 i seen like we can generate EPM report using EVDRE function very quickly and easy too. Is the same feature is existing in BPC 10.0 ? if no how can we create EPM reports using EPM Functions with Dynamic Filters on the Members of the dimension like in BPC 7.5.
    And i searched in SDN, there is no suitable blogs or documents which are related to generation of Reports using EPM Functions. All are described just in simple syntax way. It is not going to be understand for the beginners.
    Would you please specify in detail step by step.
    Thanks in Advance.
    Siva Nagaraju

    Siva,
    These functions are not used to create reports per se but rather assist in building reports. For ex, you want to make use of certain property to derive any of the dimension members in one of your axes, you will use EPMMemberProperty. Similary, if you want to override members in any axis, you will make use of EPMDimensionOverride.
    Also, EvDRE is not replacement of EPM functions. Rather, you simply create reports using report editor (drag and drop) and then make use of EPM functions to build your report. Forget EvDRE for now.
    You can protect your report to not allow users to have that Edit Report enabled for them.
    As Vadim rightly pointed out, start building some reports and then ask specific questions.
    Hope it clears your doubts.

  • How can I execute program after using F4_Filename function?

    Hi all,
    I'm a new user on the forum. I've been working with ABAP and SAP for a few weeks. I wrote a program for importing data from excel file to SAP using BDC. During searching this forum I found information about F4_Filename function which allows users to browse the disc for a file. I'd like to add this function to my program. I have a parameter for a file name but this is an ordinary static string field. When I added the code which I found in the message on this forum the rest of program doesn't execute.
    This is simple program for example:
    REPORT  Z_TEST8_AB.
    DATA f_name TYPE STRING.
    PARAMETERS p_file like rlgrap-filename DEFAULT 'c:\test.xls'.
    f_name = p_file.
    write:/ f_name.
    This program works correctly. There is a field for parameter. I can change the default name for a file.
    After all, I can run the program (F8) and rest of the code is executed. The field for parameter dissapears from the screen and the file name is displayed. ( command write)
    Now I added a function F4_Filename
    REPORT  Z_TEST8_AB.
    DATA f_name TYPE STRING.
    PARAMETERS p_file like rlgrap-filename DEFAULT 'c:\test.xls'.
    at selection-screen on value-request for p_file.
      call function 'F4_FILENAME'
           exporting
                program_name  = syst-repid
                dynpro_number = syst-dynnr
                field_name    = 'p_file'
           importing
                file_name     = p_file.
    f_name = p_file.
    write:/ f_name.
    I can browse a computer for a file now but after selecting the file I can't run the rest of the code. When I click on the icon or press key F8 the field for parameter doesn't dissapier and the command write is not executed.
    What do I do wrong?
    Could anyone suggest me a solution? How can I executed the code after using this function?
    Thanks in advance.
    Regards,
    Arek.

    Hi arkadiusz,
    1. simple
    2.
    <b>start-of-selection.</b>
    f_name = p_file.
    write:/ f_name.
    regards,
    amit m.

  • How to use mxml in a jsp file?

    I'm trying to use flex in a .jsp file. I followed the
    suggestion that I use the Flex 2 Tag library as suggested by this
    link:
    http://labs.adobe.com/wiki/index.php/Flex_2_Tag_Library_for_JSP#Download_and_Installation
    but I couldn't find it. I also downloaded LiveCycle Data Services
    ES but couldn't find the flex-bootstrap.jar.
    I have a simple example:
    <!--<%@ taglib uri="FlexTagLib" prefix="mm" %>-->
    Use the <mxml> tag to insert a Flex application in an
    existing JSP page. The following example shows the <mxml> tag
    with the source attribute to include an external MXML file:
    <mm:mxml source="CustomerServiceChat.mxml"/>
    Alternatively, you can use the <mxml> tag with inline
    MXML source code, as the following example shows:
    <mm:mxml>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    xmlns="*">
    <mx:Text label="Hello World">
    </mx:Application>
    </mm:mxml>
    I also added the following code in my web.xml:
    <taglib>
    <taglib-uri>FlexTagLib</taglib-uri>
    <taglib-location>/WEB-INF/lib/flex-bootstrap.jar</taglib-location>
    </taglib>
    and obviously I get an error because I don't have the
    flex-bootstrap.jar file. Please let me know how this can be
    corrected. Thanks in advance!

    Adobe Newsbot hopes that the following resources helps you.
    NewsBot is experimental and any feedback (reply to this post) on
    its utility will be appreciated:
    Adobe - Developer Center : Flex quick start guide for PHP
    developers:
    Apr 30, 2007 ... In this example, I changed the result data
    type to XML with E4X support by setting .... In Flex you would
    download a file using this code:
    Link:
    http://www.adobe.com/devnet/flex/articles/php_getstarted.html
    2d. Tutorial - Flex 3 Getting Started - Adobe Learning
    Resources:
    See Calling XML Web Services over the Web Using the Web
    Service References ... For information on integrating PHP and Flex
    using AMF to encode the data,
    Link:
    http://learn.adobe.com/wiki/display/Flex/2d.+Tutorial
    Mike Potter: Flex and PHP - A simple sample:
    I have other example with PHP and MySql and give the same
    error, and a example .... Flex Data Services... I choose None (???)
    because I work with php and
    Link:
    http://blogs.adobe.com/mikepotter/2006/02/flex_and_php_a_1.html
    Adobe - Developer Center : Transmitting data between Flex and
    PHP:
    Sep 4, 2007 ... Now that the user interface is set up and
    ready to go you can add the HTTP services to go ask for the data
    from the PHP code. In Flex you
    Link:
    http://www.adobe.com/devnet/flex/articles/flex_php_json.html
    Integrating Adobe Flex and PHP:
    Mar 1, 2006 ... The first step is to download Flex Builder
    2.0 from the Adobe labs ... For example, you could use this same
    PHP script to pass data to a
    Link:
    http://devzone.zend.com/article/11-Integrating-Adobe-Flex-and-PHP
    Disclaimer: This response is generated automatically by the
    Adobe NewsBot based on Adobe
    Community
    Engine.

  • Why simple functions are not included in iPhone?

    My iPhone is a wonderful piece of equipment I can't leave home without (in addition of my Amex card :-)) But for the life of me, I can't understand why Apple could not include functions which are pretty much standard with all other inferior mobile phones. Simple functions such as bluetooth transfer between phone or just saving important sms from iPhone to computer. Nokia has a great Nokia PCSuite; Motorola has very useful MobileTools which allows full sync between mobile phone and computer. I got to ask the question ... WHY? WHY? WHY? Is there any apps developer out there that can develop an apps similar to Nokia PCSuite or MobileTools. I will be the first one to pay for it.

    Abbafan1972 wrote:
    1. A better camera. For the cost of the phone I would expect at least a 5mp one.
    Read about the megapixel myth. More megapixels does not mean a better camera.
    2. A camera flash.
    Let Apple know - http://apple.com/feedback
    3. The ability to use your own custom message tone.
    I hope not but see answer to number 2. People's ringtones in public can be annoying enough without giving them more choices to be annoying.
    4. The way text messages are organised are a bit ar$e about face, no folder for sent messages, they are just in a continuous thread.
    It's called a conversation.
    5. A quicker way of sending text messages to a group of people.
    Pretty quick after you create the initial group but see my answer to number 2.

  • Using max function in PL/SQL

    VERY URGENT...
    Am new to oracle...
    I've written a package that display gif images in form of histogram/bar chart. using html,
    I need to use max function to display values proportionately.
    please help. i need to complete this assignment by 2/9/00 by 10.00 am at the latest. I've half written a function but I don't know if there's a simpler way fo doing this. html enabled

    First of all Thanks to all gentlemen who replied ..many thanks ...
    Tried the ROW_NUMBER() option but still it is taking time...have given output for the query and tkprof results as well. Even when it doesn't fetch any record ( this is a valid cased because the input header id doesn't have any workflow request submitted & hence no entry in the wf_items table)..then also see the time it has taken.
    Looked at the RANK & DENSE_RANK options which were suggested..but it is still taking time..
    Any further suggestions or ideas as to how this could be resolved..
    SELECT 'Y', 'Y', ITEM_KEY
    FROM
    ( SELECT ITEM_KEY, ROW_NUMBER() OVER(ORDER BY BEGIN_DATE DESC) RN FROM
    WF_ITEMS WHERE ITEM_TYPE = 'xxxxzzzz' AND ROOT_ACTIVITY = 'START_REQUESTS'
    AND SUBSTR(ITEM_KEY,1,INSTR(ITEM_KEY,'-') - 1) = :B1
    ) T WHERE RN <= 1
    call count cpu elapsed disk query current rows
    Parse 0 0.00 0.00 0 0 0 0
    Execute 1 0.00 1.57 0 0 0 0
    Fetch 1 8700.00 544968.73 8180 8185 0 0
    total 2 8700.00 544970.30 8180 8185 0 0
    many thanks

  • Using cursor function in sql statement

    hi all
    can anyone plss explain why and when we will use cursor function in a sql statement like this and what is the difference while executing this sql statement with cursor function in comparison of a simple sql statement----
    select
    department_name,
    cursor (
    select last_name
    from employees e
    where e.department_id = d.department_id
    order by last_name
    ) the_employees
    from departments d
    thnx in advance

    RTFM
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/sqloperations.htm#sthref1452
    Cheers
    Sarma.

  • Using a function in a Cursor Definiftion

    Hi all,
    my problem is to define a curson inside a package, using a function already defined in the function.
    My source code is the folowing:
    PROCEDURE TEST
    IS
    CURSOR cursor_test IS
    SELECT ID_CUSTOMER
    FROM CUSTOMER
    WHERE START_VALIDITY_DATE > GET_DATE(DATE_NEW_CUSTOMER, DATE_EXPIRED);
    BEGIN
    END;
    The function Get_date ( a date,b date) is defined in the same package where it is collocated my procedure "Test". The function called "Get date" return a date.
    When I compile, I have an error and I don't understand why.
    Thank'you in advance

    Hi,
    To illustrate APC's point with some simple examples:
    HR%xe> create or replace package test_pkg
      2  as
      3    procedure public_proc;
      4  end test_pkg; 
      5  /
    Package is aangemaakt.
    HR%xe> create or replace package body test_pkg
      2  as
      3    procedure public_proc
      4    is
      5      function private_func
      6      return date
      7      is
      8      begin
      9       return(sysdate);
    10      end private_func;
    11      --
    12      l_count number := 0;
    13      --
    14    begin
    15      select count(*) into l_count
    16      from   employees
    17      where  employees.hire_date < private_func;
    18      --
    19      dbms_output.put_line(l_count||' employees were counted.');
    20      --
    21    end;
    22  end test_pkg; 
    23  /
    Waarschuwing: package-body is aangemaakt met compilatiefouten.
    HR%xe> sho err
    Fouten voor PACKAGE BODY TEST_PKG:
    LINE/COL ERROR
    12/5     PLS-00103: Encountered the symbol "L_COUNT" when expecting one of
             the following:
             begin function package pragma procedure form
    22/5     PLS-00103: Encountered the symbol "TEST_PKG" when expecting one
             of the following:
    HR%xe> create or replace package test_pkg
      2  as
      3  /* commented out the declaration in the specification this time
      4    function private_func
      5    return date;
      6  */ 
      7    procedure public_proc;
      8  end test_pkg; 
      9  /
    Package is aangemaakt.
    HR%xe> create or replace package body test_pkg
      2  as
      3    function private_func
      4    return date
      5    is
      6    begin
      7     return(sysdate);
      8    end;
      9 
    10    procedure public_proc
    11    is
    12      l_count number := 0;
    13    begin
    14      select count(*) into l_count
    15      from   employees
    16      where  employees.hire_date < private_func;
    17      --
    18      dbms_output.put_line(l_count||' employees were counted.');
    19      --
    20    end;
    21  end test_pkg; 
    22  /
    Waarschuwing: package-body is aangemaakt met compilatiefouten.
    HR%xe> sho err
    Fouten voor PACKAGE BODY TEST_PKG:
    LINE/COL ERROR
    14/5     PL/SQL: SQL Statement ignored
    16/34    PL/SQL: ORA-00904: "PRIVATE_FUNC": invalid identifier
    16/34    PLS-00231: function 'PRIVATE_FUNC' may not be used in SQL
    HR%xe> create or replace package test_pkg
      2  as
      3  
      4    function private_func
      5    return date;
      6   
      7    procedure public_proc;
      8  end test_pkg; 
      9  /
    Package is aangemaakt.
    HR%xe> create or replace package body test_pkg
      2  as
      3    function private_func
      4    return date
      5    is
      6    begin
      7     return(sysdate);
      8    end;
      9 
    10    procedure public_proc
    11    is
    12      l_count number := 0;
    13    begin
    14      select count(*) into l_count
    15      from   employees
    16      where  employees.hire_date < private_func;
    17      --
    18      dbms_output.put_line(l_count||' employees were counted.');
    19      --
    20    end;
    21  end test_pkg; 
    22  /
    Package-body is aangemaakt.
    HR%xe> exec test_pkg.public_proc
    107 employees were counted.
    PL/SQL-procedure is geslaagd.Once you declare your function in your package specification as well, you can use your function in your procedure.
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_packages.htm#sthref823

  • Using Aggregate function in queries

    Hi all,
              Please take a look on this query and suggest me why i'm getting the error..
    This is my simple query using aggregate function in it..
    SELECT T1.NAME, T1.DESCRIPTION, SUM(T2.QUANTITY)
    FROM TABLE1 T1, TABLE2 T2
    WHERE T1.ID=T2.ID
    GROUP BY T1.NAME, T1.DESCRIPTION
    Above query added with a sub-query in the select segment..
    SELECT T1.NAME, T1.DESCRIPTION, SUM(T2.QUANTITY), (SELECT AVG(T3.PRICE) FROM TABLE1 TT1, TABLE3 T3 WHERE TT1.ID=T3.ID AND TT1.ID=T1.ID) AV_PRICE
    FROM TABLE1 T1, TABLE2 T2
    WHERE T1.ID=T2.ID
    GROUP BY T1.NAME, T1.DESCRIPTION
    When i add a sub-query which has aggregate function in it, i'm getting the 'ORA-00979: not a GROUP BY expression' error.

    What is your DB Version. Your query works without any issue in my DB. I used WITH clause to create the sample data. The query highlighted in BLUE is the actual query.
    SQL> select * from v$version where rownum = 1;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
    SQL> with table1
      2  as
      3  (
      4    select 1 id, 'karthick' name, 'user name' description from dual
      5  ),
      6  table2
      7  as
      8  (
      9    select 1 id, 100 quantity from dual
    10  ),
    11  table3
    12  as
    13  (
    14    select 1 id, 10 price from dual
    15  )
    16  select t1.name
    17       , t1.description
    18       , sum(t2.quantity)
    19       , (
    20           select avg(t3.price)
    21             from table1 tt1
    22                , table3 t3
    23            where tt1.id = t3.id
    24              and tt1.id = t1.id
    25         ) av_price
    26    from table1 t1
    27       , table2 t2
    28   where t1.id = t2.id
    29   group
    30      by t1.name
    31       , t1.description;
    NAME     DESCRIPTI SUM(T2.QUANTITY)   AV_PRICE
    karthick user name              100         10
    SQL>

Maybe you are looking for

  • Need help identifying specific model

    I have a Toshiba Satellite Laptop. The model number and serial number have been rubbed off from the back. I'd like to know which model I have. It has L505 on one of the decals on the front of the laptop. I have looked at the specs for each of the L50

  • Does creative have plans to update Nomad Explor

    i think its a great simple piece of software.. except for one thing. its hard to transfer music from your play to the PC. you have to highlite every song in the album then drag and drop them onto your PC, in a folder you have to make yourself. and wh

  • Significance of ResultSet.setFetchSize()

    We are using Oracle 8i as DB Server, WebLogic 6.1 as App Server and IIS 5.0 as Web Server on the different physical m/c. We are using OCI8 Driver. We have a utility that will act as a cache manager. We have to provide a query, it will hold the result

  • Unable to open PDF files in messages since iOS 8.3 update

    i updated my iPhone 6 to the iOS 8.3 update and unable to open PDF files with in the messages app ... I was able to do this prior to the update.  Was the functionality taken away (still able to open jpg and ping files)?

  • Pan Zoom Pro experience

    Anyone had experience with Lyric's Pan Zoom Pro? Good, bad, ugly, otherwise?