Stored pl sql question

Hello, I'm trying to select maximum number of employee in a department using this function:
create or replace function MAXEMPS (maxemp IN varchar2)
return number IS max_p varchar2
begin
select dept.dname, count(*) into max_p from dept join emp where dname=maxemp
on dept.dname = emp.dname
group by dept.dname
having count(*) = (select max(count(*)) from emp group by emp.dname);
return max_p;
end MAXEMPS;
by the way this is the table:
create table dept
DName varchar2(25),
CityLocated number(5),
constraint dept_pk primary key(DName)
create table EMP
EID number(7),
EName varchar2(25),
DName varchar(25),
constraint EMP_pk primary key(EID),
constraint EMP_fk foreign key references DEPT(DName)
unfortunately my function got an error and I have no luck to fix this function
thanks for the help :)

my bad I really should use 'show errors' from the begining...
create or replace function MAXEMPS (max_p dept.dname%TYPE;)
return number IS max_p varchar2
begin
select dept.dname, count(*) into max_p from dept join emp where dname=maxemp
on dept.dname = emp.dname
group by dept.dname
having count(*) = (select max(count(*)) from emp group by emp.dname);
return max_p;
end MAXEMPS;
*based on the above code I've got these error messages:
LINE/COL ERROR
1/40 PLS-00103: Encountered the symbol ";" when expecting one of the f ollowing: := ) , default character The symbol ";" was ignored .
3/1 PLS-00103: Encountered the symbol "BEGIN" when expecting one of t he following: := . ( @ % ; not null range default character T he symbol ";" was substituted for "BEGIN" to continue.
4/55 PLS-00103: Encountered the symbol "EMP" when expecting one of the following: , ; for group having intersect minus order start union where connect The symbol "," was substituted for "EMP" t o continue.
5/1 PLS-00103: Encountered the symbol "ON" when expecting one of the following: . ( * @ % & - + ; / at for mod remainder rem <a n exponent (**)> and or group having intersect minus order sta rt union where connect || multiset The symbol "( was inserted bef ore "ON" to continue.
6/1 PLS-00103: Encountered the symbol "GROUP" when expecting one of t he following: . ( ) , * @ % & - + / at mod remainder rem <an exponent (**)> and or using || multiset The symbol ")" was sub stituted for "GROUP" to continue.
Edited by: [email protected] on Jul 20, 2009 12:00 PM

Similar Messages

  • Calling stored procedure in Access but data stored in SQL

    Our data is stored in SQL, but due to some restriction I need to make stored procedure in Access instead of SQL. I created the relevant link in Access to call the tables in SQL. Whenever I invoke the SQL database in Access, a login screen will appear which ask for password and user. This creates a problem for me when i execute the stored procedure in Access. It will create connection error to SQL database, just because I have no idea of how to write java code to fill in the username and password when the login dialog appears. Does anyone have any idea?

    Well, it still doesn't work. Here is part of the code, have a look please.
    public DisplayQueryResults() {
       String studattUrl = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=D:/StudAtt/StudAtt.mdb";
       String mustbUrl = "jdbc:odbc:mustb";          
       try {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          studattConn = DriverManager.getConnection(studattUrl);
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          mustbConn = DriverManager.getConnection(mustbUrl, "sa", "");               
    private void getTable() {
       try {
          stmtStudAtt = studattConn.createStatement(resultSet.TYPE_SCROLL_SENSITIVE, resultSet.CONCUR_READ_ONLY);
          stmtMustb = mustbConn.createStatement();
          CallableStatement callSP = studattConn.prepareCall("{call mustbFaculty}");
          resultSet = callSP.executeQuery();
          displayResultSet(resultSet);
       }

  • Dynamic parameter selection from infoview not storing the sql password

    We are having the problem of dynamic parameter selection from infoview not storing the sql password as it does for the actual report. We are using Crystal Reports XI Release 2 version 11.5.3.438 (Not sure of SP level, asked in separate thread).
    To be more specific.
    We have created a report that dynamically populates the parameters of the report by pulling the records from the Informix sql database and allowing selection from there.
    In the Central Management Console for the report object we have set as follows:
    Process - Database:
    Use original database logon information from the report - the sql username and pw etc
    Use same database logon as when report is run
    Process - Parameters
    In selecting a default selection there is the option to put in the sql password, however, this does not stick and clears after update.
    As such the end result is that every time this report is run from infoview and a user chooses a parameter (there are 5), crystal goes through some timeout for about a minute or so and then requests the sql password, if a user then selects the next parameter, the same timeout and password dialog appears.
    We need the crystal report to handle to the sql password for fetching the parameters as well as for the database section of running the report, however, the parameters insists on the end user always putting the password in.
    This is 100% replicatable on our system.
    Any way that we can fix this?
    Will an update fix this issue? If so could you please advise which one?
    Thanks

    Hi,
    I am having the exact same problem. Any help?
    And what does "Use same database logon as when report is run" mean? For me that would be that no prompt is needed for getting values in a dynamic parameter...
    Regards
    Magnus

  • Problems displaying images stored in SQL Server as Datatype "image"

    I am trying to display an Image stored in SQL Server as
    datatype
    'image' and it only shows a portion of the image.
    It seems to be tied to the size (kb) of the image since the
    larger the
    image the less of it is shown before it cuts off(sometimes it
    cuts off
    mid line so it's about the file size and not fitting the
    image on the
    screen).
    Here is the code I am using that deals with the image.
    [Bindable]
    public var theImage:ByteArray = new ByteArray;
    private function getScans_result(event:ResultEvent):void{
    var imageByteArray:ByteArray = event.result[0].Image;
    theImage = imageByteArray
    <mx:Image id="theIMG" width="160" height="220"
    source="{theImage}"/>
    Any Thoughts??

    I do that sort of thing using PHP and mySQL the binary part
    of the image is stored in a BLOB field (Binary Large OBject) along
    the rest of the information necessary for the http headers (e.g.
    mime type, file name, file size) being staored in their own fields.
    That info is then used to build the file using PHP. The PHP
    file contains a mySQL query whos result is echoed with the
    appropriate headers. The URL points at the PHP file rather than at
    any saved image.
    Here's the php:
    <?
    # display_imagebank_file.php
    # Note: the ID is passed through the url e.g.
    # this_files_name.php?id=1
    # connect to mysql database
    mysql_connect('HOST', 'USERNAME', 'PASSWORD');
    mysql_select_db('DATABASE');
    # run a query to get the file information
    $query = mysql_query("SELECT FileName, MimeType, FileSize,
    FileContents FROM blobTable WHERE ID='$id'");
    # perform an error check
    if(mysql_num_rows($query)==1){
    $fileName = mysql_result($query,0,0);
    $fileType = mysql_result($query,0,1);
    $fileSize = mysql_result($query,0,2);
    $fileContents = mysql_result($query,0,3);
    header("Content-type: $fileType");
    header("Content-length: $fileSize");
    header("Content-Disposition: inline; filename=$fileName");
    header("Content-Description: from imagebank");
    header("Connection: close");
    echo $fileContents;
    }else{
    $numRows = mysql_num_rows($query);
    echo "File not found <br>";
    echo $numRows;
    echo " is the number of rows returned for id = ";
    echo $ID;
    ?>
    Hope that helps
    Phil

  • Displaying images stored in SQL Server

    Is there someway of displaying images stored within SQL
    Server. Is FDS required? Prefer a method to display images without
    using FDS; Web Service would be okay if that can work

    I do that sort of thing using PHP and mySQL the binary part
    of the image is stored in a BLOB field (Binary Large OBject) along
    the rest of the information necessary for the http headers (e.g.
    mime type, file name, file size) being staored in their own fields.
    That info is then used to build the file using PHP. The PHP
    file contains a mySQL query whos result is echoed with the
    appropriate headers. The URL points at the PHP file rather than at
    any saved image.
    Here's the php:
    <?
    # display_imagebank_file.php
    # Note: the ID is passed through the url e.g.
    # this_files_name.php?id=1
    # connect to mysql database
    mysql_connect('HOST', 'USERNAME', 'PASSWORD');
    mysql_select_db('DATABASE');
    # run a query to get the file information
    $query = mysql_query("SELECT FileName, MimeType, FileSize,
    FileContents FROM blobTable WHERE ID='$id'");
    # perform an error check
    if(mysql_num_rows($query)==1){
    $fileName = mysql_result($query,0,0);
    $fileType = mysql_result($query,0,1);
    $fileSize = mysql_result($query,0,2);
    $fileContents = mysql_result($query,0,3);
    header("Content-type: $fileType");
    header("Content-length: $fileSize");
    header("Content-Disposition: inline; filename=$fileName");
    header("Content-Description: from imagebank");
    header("Connection: close");
    echo $fileContents;
    }else{
    $numRows = mysql_num_rows($query);
    echo "File not found <br>";
    echo $numRows;
    echo " is the number of rows returned for id = ";
    echo $ID;
    ?>
    Hope that helps
    Phil

  • SQL Question Bank and Answers for Practise

    Dear Readers:
    Does any one have any recommendation on SQL question bank and answers where I could practice my SQL.
    I have developed some basic knowledge of SQL thanks to the MS community, but I am looking for some additional Questions or textbook  recommendations which has questions and answers to queries for practice.
    Best Wishes,
    SQL75

    Hi,
    Refer below post.
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/446b2247-5124-49c1-90c9-b7fea0aa4f83/sql-dba-books?forum=sqlgetstarted
    Please mark solved if I've answered your question, vote for it as helpful to help other users find a solution quicker
    Praveen Dsa | MCITP - Database Administrator 2008 |
    My Blog | My Page

  • Sql question : TRUNCATE vs Delete

    hi
    this is sql question, i don't know where i should post it, so here it is.
    i just want to know the best usage of each. both commands delete records in a table, one deletes all, and the other can do the same plus option to delete specified records. if i just want to purge the table. which one is better and why? thanks

    this is crucial to my design, i need to be able to
    rollback if one of the process in the transaction
    failed, the whole transaction should rollback. if
    truncate does not give me this capability, then i have
    to consider Delete.From the Oracle manual (sans the pretty formatting):
    TRUNCATE
    Caution: You cannot roll back a TRUNCATE statement.
    Purpose
    Use the TRUNCATE statement to remove all rows from a table or cluster. By default,
    Oracle also deallocates all space used by the removed rows except that specified by
    the MINEXTENTS storage parameter and sets the NEXT storage parameter to the size
    of the last extent removed from the segment by the truncation process.
    Removing rows with the TRUNCATE statement can be more efficient than dropping
    and re-creating a table. Dropping and re-creating a table invalidates the table?s
    dependent objects, requires you to regrant object privileges on the table, and
    requires you to re-create the table?s indexes, integrity constraints, and triggers and
    respecify its storage parameters. Truncating has none of these effects.
    See Also:
    DELETE on page 16-55 and DROP TABLE on page 17-6 for
    information on other ways to drop table data from the database
    DROP CLUSTER on page 16-67 for information on dropping
    cluster tables
    Prerequisites
    To truncate a table or cluster, the table or cluster must be in your schema or you
    must have DROP ANY TABLE system privilege.

  • Calling stored pl/sql functions

    Hello,
    Any suggestions on calling a stored pl/sql function from a UIX page and returning the output of the function to the same page?
    Thanks,
    -Jeff

    Hi Jaap,
    I followed the instructions on the link you gave me and when I ran my test application I received this error:
    C:\jdev903\jdk\bin\javaw.exe -ojvm -classpath C:\msdapp_jeff\web\WEB-INF\classes;C:\msdapp_jeff\web\WEB-INF\lib\CopyProjectLibs.bat;C:\msdapp_jeff\web\WEB-INF\lib\bc4jmt.jar;C:\msdapp_jeff\web\WEB-INF\lib\bc4jct.jar;C:\msdapp_jeff\web\WEB-INF\lib\bc4jdomorcl.jar;C:\msdapp_jeff\web\WEB-INF\lib\collections.jar;C:\msdapp_jeff\web\WEB-INF\lib\bc4jdatum.jar;C:\msdapp_jeff\web\WEB-INF\lib\classes12.jar;C:\msdapp_jeff\web\WEB-INF\lib\nls_charset12.jar;C:\msdapp_jeff\web\WEB-INF\lib\xmlparserv2.jar;C:\msdapp_jeff\web\WEB-INF\lib\uix2-dbg.jar;C:\msdapp_jeff\web\WEB-INF\lib\share-dbg.jar;C:\msdapp_jeff\web\WEB-INF\lib\regexp.jar;C:\msdapp_jeff\web\WEB-INF\lib\cle.jar;C:\msdapp_jeff\web\WEB-INF\lib\jhsruntime.jar;C:\jdev903\BC4J\lib\bc4jmt.jar;C:\jdev903\BC4J\lib\collections.jar;C:\jdev903\BC4J\lib\bc4jct.jar;C:\jdev903\lib\xmlparserv2.jar;C:\jdev903\jlib\jdev-cm.jar;C:\jdev903\j2ee\home\lib\jndi.jar;C:\jdev903\BC4J\lib\bc4jdomorcl.jar;C:\jdev903\BC4J\jlib\bc4jdatum.jar;C:\jdev903\jdbc\lib\classes12.jar;C:\jdev903\jdbc\lib\nls_charset12.jar;C:\jdev903\jlib\jdev-cm.jar;C:\jdev903\jdev\lib\jdev-rt.jar;C:\jdev903\BC4J\jlib\bc4jtester.jar;C:\jdev903\jlib\jdev-cm.jar;C:\jdev903\lib\xmlparserv2.jar;C:\jdev903\jlib\help4-nls.jar;C:\jdev903\jlib\help4.jar;C:\jdev903\jlib\share.jar;C:\jdev903\jlib\jewt4-nls.jar;C:\jdev903\jlib\jewt4.jar;C:\jdev903\jlib\oracle_ice5.jar;C:\msdapp_jeff\web\WEB-INF\lib\bc4jct.jar;C:\msdapp_jeff\web\WEB-INF\lib\bc4jdatum.jar;C:\msdapp_jeff\web\WEB-INF\lib\bc4jdomorcl.jar;C:\msdapp_jeff\web\WEB-INF\lib\bc4jmt.jar;C:\msdapp_jeff\web\WEB-INF\lib\classes12.jar;C:\msdapp_jeff\web\WEB-INF\lib\cle.jar;C:\msdapp_jeff\web\WEB-INF\lib\collections.jar;C:\msdapp_jeff\web\WEB-INF\lib\jhsruntime.jar;C:\msdapp_jeff\web\WEB-INF\lib\nls_charset12.jar;C:\msdapp_jeff\web\WEB-INF\lib\regexp.jar;C:\msdapp_jeff\web\WEB-INF\lib\share-dbg.jar;C:\msdapp_jeff\web\WEB-INF\lib\uix2-dbg.jar;C:\msdapp_jeff\web\WEB-INF\lib\xmlparserv2.jar;C:\jdev903\lib\xmlparserv2.jar;C:\jdev903\jlib\regexp.jar;C:\jdev903\jlib\share.jar;C:\jdev903\jlib\uix2.jar;C:\jdev903\j2ee\home\lib\ojsp.jar;C:\jdev903\j2ee\home\jsp\lib\taglib\ojsputil.jar;C:\jdev903\j2ee\home\oc4j.jar;C:\jdev903\j2ee\home\lib\servlet.jar;C:\jdev903\jdev\lib\ojc.jar;C:\jdev903\BC4J\lib\bc4jhtml.jar;C:\jdev903\BC4J\lib\datatags.jar;C:\jdev903\BC4J\lib\bc4juixtags.jar;C:\jdev903\BC4J\lib\bc4j_jclient_common.jar -Djbo.project=empdep0 -Dhttp.proxyHost=http -Dhttp.proxyPort=80 -Dhttp.nonProxyHosts=*.oasas.state.ny.us test.test
    oracle.jbo.JboException: STRINGMANAGER: StringManager oracle.jbo.common.CommonMessageBundle (33001) exception oracle.jbo.NoXMLFileException: JBO-26001: XML File not found for the Container empdep0.jpx
         void oracle.jbo.client.Configuration.loadFromClassPath(java.lang.String)
              Configuration.java:301
         oracle.jbo.ApplicationModule oracle.jbo.client.Configuration.createRootApplicationModule(java.lang.String, java.lang.String, oracle.jbo.common.ampool.EnvInfoProvider)
              Configuration.java:1090
         oracle.jbo.ApplicationModule oracle.jbo.client.Configuration.createRootApplicationModule(java.lang.String, java.lang.String)
              Configuration.java:1073
         void test.test.main(java.lang.String[])
    I'm pretty clueless on this one. What do you think?
    -Jeff

  • Urgent SQL question : how to flip vertical row values to horizontal ?

    Hello, Oracle people !
    I have an urgent SQL question : (simple for you)
    using SELECT statement, how to convert vertical row values to horizontal ?
    For example :
    (Given result-set)
    MANAGER COLUMN1 COLUMN2 COLUMN3
    K. Smith ......1
    K. Smith ...............1
    K. Smith ........................1
    (Needed result-set)
    MANAGER COLUMN1 COLUMN2 COLUMN3
    K. Smith ......1 .......1 .......1
    I know you can, just don't remeber how and can't find exactly answer I'm looking for. Probably using some analytic SQL function (CAST OVER, PARTITION BY, etc.)
    Please Help !!!
    Thanx !
    Steve.

    scott@ORA92> column vice_president format a30
    scott@ORA92> SELECT f.VICE_PRESIDENT, A.DAYS_5, B.DAYS_10, C.DAYS_20, D.DAYS_30, E.DAYS_40
      2  FROM   (select t2.*,
      3                row_number () over
      4                  (partition by vice_president
      5                   order by days_5, days_10, days_20, days_30, days_40) rn
      6            from   t2) f,
      7           (SELECT T2.*,
      8                row_number () over (partition by vice_president order by days_5) RN
      9            FROM   T2 WHERE DAYS_5 IS NOT NULL) A,
    10           (SELECT T2.*,
    11                row_number () over (partition by vice_president order by days_10) RN
    12            FROM   T2 WHERE DAYS_10 IS NOT NULL) B,
    13           (SELECT T2.*,
    14                row_number () over (partition by vice_president order by days_20) RN
    15            FROM   T2 WHERE DAYS_20 IS NOT NULL) C,
    16           (SELECT T2.*,
    17                row_number () over (partition by vice_president order by days_30) RN
    18            FROM   T2 WHERE DAYS_30 IS NOT NULL) D,
    19           (SELECT T2.*,
    20                row_number () over (partition by vice_president order by days_40) RN
    21            FROM   T2 WHERE DAYS_40 IS NOT NULL) E
    22  WHERE  f.VICE_PRESIDENT = A.VICE_PRESIDENT (+)
    23  AND    f.VICE_PRESIDENT = B.VICE_PRESIDENT (+)
    24  AND    f.VICE_PRESIDENT = C.VICE_PRESIDENT (+)
    25  AND    f.VICE_PRESIDENT = D.VICE_PRESIDENT (+)
    26  AND    f.VICE_PRESIDENT = E.VICE_PRESIDENT (+)
    27  AND    f.RN = A.RN (+)
    28  AND    f.RN = B.RN (+)
    29  AND    f.RN = C.RN (+)
    30  AND    f.RN = D.RN (+)
    31  AND    f.RN = E.RN (+)
    32  and    (a.days_5 is not null
    33            or b.days_10 is not null
    34            or c.days_20 is not null
    35            or d.days_30 is not null
    36            or e.days_40 is not null)
    37  /
    VICE_PRESIDENT                     DAYS_5    DAYS_10    DAYS_20    DAYS_30    DAYS_40
    Fedele Mark                                                          35473      35209
    Fedele Mark                                                          35479      35258
    Schultz Christine                              35700
    South John                                                                      35253
    Stack Kevin                                    35701      35604      35402      35115
    Stack Kevin                                    35705      35635      35415      35156
    Stack Kevin                                    35706      35642      35472      35295
    Stack Kevin                                    35707      35666      35477
    Stack Kevin                                               35667      35480
    Stack Kevin                                               35686
    Unknown                             35817      35698      35596      35363      35006
    Unknown                                        35702      35597      35365      35149
    Unknown                                        35724      35599      35370      35155
    Unknown                                                   35600      35413      35344
    Unknown                                                   35601      35451      35345
    Unknown                                                   35602      35467
    Unknown                                                   35603      35468
    Unknown                                                   35607      35475
    Unknown                                                   35643      35508
    Unknown                                                   35644
    Unknown                                                   35669
    Unknown                                                   35684
    Walmsley Brian                                 35725      35598
    23 rows selected.

  • Stored PL/SQL procedure

    Hi,
    we have a concurrent job (request) which is a stored PL/SQL procedure ? How can I see/edit a stored PL/SQL procedure ?
    Many thanks.

    View them with your favorite SQL tool like SQL Developer, PLSQL Developer, T.O.A.D., SQL Navigator, DBConsole, Grid Control, etc.
    SQL Developer is free, but you need to apply a filter to view apps code or it takes forever to load all of the apps packages.

  • Where is the physical device name of a backup stored in SQL?

    Hi, 
    If I look at the backup/restore report in SQL2008R2 I can see the backup file a database was backed up to and/or a device id if it was taken by VM tools.  Can anyone tell me where this physical device name is stored in SQL? 
    Thanks 
    e.g. 

    Hi,
    This is just a device drive location you have while executing backup and it would be stored in
    msdb.dbo.backupmediafamily has logical_device_name,  
    msdb.dbo.backupmediafamily has physical_device_name
    There are also logical Backup devices you can create in SQL Server
    Please read below
    https://msdn.microsoft.com/en-us/library/ms179313.aspx?f=255&MSPPError=-2147217396
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it
    My Technet Wiki Article
    MVP

  • Abap SQL question

    Hi,
    I need to select the set of records only in Table A, but not in Table B. I think that the correct SQL is:
    select k~vbeln
    into data
    from vbak as k
    inner join vbfa as f on kvbeln = fvbelv
    where f~vbelv is null.
    But the following message appears: u201CNo fields from the right-hand table of a LEFT OUTER JOIN may appear in the WHERE condition: u201CF~VBELBu201Du201D.
    Thanks in advance,
    Ricard.

    Hi Oscar & William,
    first of all: The database meaning of NULL is that for the field in question no value is stored for an existing record.
    In SAP tables we rarely have any NULL values. Only if you extend an existing table, i.e. append a new field, the database will expand the structure but not store INITIAL values for the new field in all records.
    Second, just a hint: although the SAP example uses the mystifying ALIAS (AS) addition for joins, it does not help except reducing the code transparency:
    SELECT vbak~vbeln
           INTO lw_data
           FROM vbak
           INNER JOIN vbfa ON vbak~vbeln = vbfa~vbelv
           WHERE vbfa~vbelv IS NULL.
        <you can do your process here>
    ENDSELECT.
    Is 100 % the same. Nevertheless it will never retrieve a single record because vbelv is never stored as a NULL value.
    I think this can be solved using a subquery
    DATA : lt_data TYPE table of vbak-vbeln.
    SELECT vbeln
           INTO  lt_data  
           FROM vbak
           WHERE NOT EXISTS
              ( SELECT * FROM vbfa WHERE vbelv = vbak~vbeln ).
        <you can do your process here>
    ENDSELECT.
    To be honest: I did not try the code, never played with subqueries though I should do so.
    Regards,
    Clemens

  • Stored Proc Migration question

    In sql server I have what is basically a select statement (multiple records) that is returned from a stored proc and as I understand it Oracle doesn't allow you do this in the same fashion.
    Instead a cursor has to be used (from what i understand?, although I am not 100% sure)
    so my question is this; Use of cursors in MS SQL Sever / Sybase can be resource intensive and slow. - my understanding of cursors in SQL server\ sybase is that you should really use them unless you have to.
    Is this the case in Oracle, or is it totally different?
    should I be looking at a different way of reproducing the data - i.e. using a procedure to create that data into a table then using a view to return the records.
    many thanks

    Any SQL statement that returns records is a cursor, whether in Oracle od SQL Server or Sybase. There may be a larger difference in SQL Server performance between explicit cursors (i.e. those formally declared) and implicit cursors (i.e. just select) than there is in Oracle, but they are all still cursors.
    The only way to retunr a result set to a calling program from a stored proc in Oracle is to use a cursor. Cursors, in themselves, are not any more resource intensive than the underlying sql statement. What tends to be resource intensive in Oracle is the row by row processing that people usually do with th cursors they fetch.
    In Oracle, you would generally do something like this to return a cursor to another program.
    PROCEDURE p (p_id IN NUMBER, p_cur OUT SYS_REFCURSOR)
    BEGIN
       OPEN p_cur FOR SELECT * FROM t WHERE id = p_id;
    END;Then call it like:
    DECLARE
       l_cur SYS_REFCURSOR;
       variables or a record to receive the fields
    BEGIN
       p(1, l_cur);
       LOOP
          FETCH l_cur INTO variables or record
          EXIT WHEN l_cur%NOTFOUND;
          <processing>
       END LOOP;
    END;The exact syntax to declare the cursor and call the stored proc will depend on the language of the calling program.
    You could also do P as a function returning a sys_refcursor.
    HTH
    John

  • Basic PL/SQL Question about running context

    We are trying to create some generalized tools with PL/SQL procedures that would be used by a number of different Oracle Users/Schema. The idea was to store them in an administrative schema (call it ADMIN), create public synonyms for them, and grant execute to public. Then we could run them from the user schema (call it USER) to do the work.
    It was my assumption, that while the procedures were stored in ADMIN, when they were run by USER they would run in the USER context. EG, a table (call it MYTABLE) that was referenced in the procedure without a schema reference (SELECT * FROM MYTABLE) would expect to find MYTABLE in the context of the schema which called the procedure. In other words, call the procedure from USER, I expected the procedure to look for MYTABLE in USER. However, we are getting errors that indicate that even though the procedure is called from USER, it is looking for the table in ADMIN (the procedures creation context), no in USER (the running context).
    QUESTIONS: How is PL/SQL supposed to operate in this situation? Are there any options/parameters that can be set so the procedure will use the runtime context for table lookup, or do we have to write dynamic SQL which will fully qualify the table with the owner schema?
    Thanks for your help
    John Conroy

    Hy,
    from the manual:
    The AUTHID clause is allowed only in the header of a stand-alone subprogram, a
    package spec, or an object type spec. The header syntax is
    -- stand-alone function
    CREATE [OR REPLACE] FUNCTION [schema_name.]function_name
    [(parameter_list)] RETURN datatype
    [AUTHID {CURRENT_USER | DEFINER}] {IS | AS}
    -- stand-alone procedure
    CREATE [OR REPLACE] PROCEDURE [schema_name.]procedure_name
    [(parameter_list)]
    [AUTHID {CURRENT_USER | DEFINER}] {IS | AS}
    -- package spec
    CREATE [OR REPLACE] PACKAGE [schema_name.]package_name
    [AUTHID {CURRENT_USER | DEFINER}] {IS | AS}
    -- object type spec
    CREATE [OR REPLACE] TYPE [schema_name.]object_type_name
    [AUTHID {CURRENT_USER | DEFINER}] {IS | AS} OBJECT
    where DEFINER is the default option. In a package or object type, the AUTHID
    clause applies to all routines.
    Note: Most supplied PL/SQL packages (such as DBMS_LOB, DBMS_PIPE, DBMS_
    ROWID, DBMS_SQL, and UTL_REF) are invoker-rights packages.

  • Editing Stored Procedures (SQL Server?)

    This may seem like a dumb question but I just finished my project for our Oracle data warehouse and now I need to move on to SQL Server to upgrade those procedures... does SQL Developer not support the editing of SPs for SQL Server? Are the SPs for SQL Server read-only?
    Using SQL Developer Version 1.5.0.53.58
    on Win XP box...
    Thanks!
    Tim

    Hello,
    Please try the following ones:
    http://msdn.microsoft.com/en-us/library/ms190669.aspx
    http://www.sql-server-performance.com/2003/stored-procedures-basics/
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

Maybe you are looking for

  • How to apply clock to a ADC from NI ELVIS II+ board

    How to apply a clock to a ADC for ADC conversion from NI ELVIS II+. The input signal to ADC for conversion is 50 Hz applied from the function generator, now how to apply a CLOCK to this ADC for working. Please help....

  • Where do I see the price of my book?

    As the title says, how do I see the price of the book I've created? Is it the price that is showed when I choose the layout? But why is the price for extra pages showed? What happens if I press the Buy button? Do I get to see the price before I confi

  • CRUD Ruby on Rails Oracle database

    A Create-Read-Update-Delete application may be developed with Ruby on Rails and Oracle database. http://www.regdeveloper.co.uk/2006/07/03/ruby_rails_part1/ http://www.regdeveloper.co.uk/2006/07/17/ruby_rails_part2/

  • Export wizard creates views in alphabetical versus dependency order

    Oracle SQL Developer 3.1.07 on Windows 7 SP1 64-bit Oracle Database Oracle EE 11gR1 64-bit on OEL 5.4 64-bit ==================================== Export tool (Tools-> Database Export) generates DDL for views in alphabetical order instead of dependenc

  • Batch Processing to Rename Files

    I use batch processing to rename file in Photoshop Elements 5.0. I renamed my files with the MRW extension and the extension was changed to PSD. I also tried batch processing to turn the MRW file into RAW files. I was able to do that but then Photosh