Create a procedure which requires displaying information from two tables

What if we want to create a procedure which requires displaying information from two tables. In this situation,
I need to display all the details of an employee from an 'emp' table based on the deptno. and also their salary information which is
stored in "Salgrade" Table. Is the use of "And" the correct way of using it?
Do I need to declare all the attributes before begin or I can just access them directly? Thanks
Create Procedure findDept
( I_deptno IN number
) As
Begin
Select Ename, Job, MGR, Hiredate, Sal, Comm, Dept_no from emp and exp, grade , location from salgrade where dept_no
= I_Deptno;
Exception
When NO_Data_Found then
DBMS_Output.Put_Line(' Department not found"|| I_deptno);
End findDept;

Hi,
Besides Qwerty's remark, you've also got a quoting error:
Change
DBMS_Output.Put_Line(' Department not found"|| I_deptno);
{code}
into
{code}
dbms_output.put_line(' Department not found: '|| i_deptno);
{code}
Which leads to the question:
What do you want to do when a record is found?
Display it?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Display columns from two tables without making join

    Hi,
    I need to perform currency conversion in the report.
    For eg:) Whatever the currency in ar_payment_schedules i want to
    convert it to INR equivalent.
    Following is the query to do this.
    select ps.invoice_currency_code Currency_B,
         decode(ps.invoice_currency_code, 'INR',ps.amount_due_original,
                   round(ps.amount_due_original*
                                  ps.exchange_rate,
                             curr.precision)
         from
              ar_payment_schedules     ps,
              fnd_currencies          curr
         where ps.customer_id          = '111'
         and curr.currency_code      = 'INR'
    When i do this in the Administration tool, the answers modules erroring out saying
    that no joins between ar_payment_schedules and fnd_currencies. But here join is
    not needed becuase fnd_currencies is filtered with INR and will return only
    one row. Without joining two tables how can i get the same results in Answers.
    thanks,
    Prasanna

    If it would return only one row then what is the need for the join (is it just for returning the precision?). Cant you just hard code the precision value instead of getting it from the table? Also you are doing a cartesian join, though the filters would take care of the final output this would result in a bad performance as your data starts scaling out. You need to find a key to join these 2 tables. If you do not have one, then just create a view with the cartesian join alone and then use that in your report.
    Thanks,
    Venkat
    http://oraclebizint.wordpress.com

  • Displaying information from two sources

    I want to display current Citrix-sessions and the following AD-information for the users:
    Name (From AD), streetAddress (From AD), physicalDeliveryOfficeName (From AD), DeviceId (From Citrix), LaunchedViaHostName (From Citrix)
    These lines get me the Citrix session information I need:
    Asnp Citrix.*
    Import-Module ActiveDirectory
    $users = Get-BrokerSession |select -uniq UserUPN, DeviceId, LaunchedViaHostName
    After those commands I have the following information in an array $users:
    Because I now have the UserUPN information available, I should be able to map it to AD accounts to get more information. I try to get the information displayed with these commands:
    foreach ($i in $users) {
    Get-ADUser -LDAPFilter "(userprincipalname=$i.UserUPN)" -properties physicalDeliveryOfficeName, streetAddress | select name, streetAddress, physicalDeliveryOfficeName, $i.DeviceId, $i.LaunchedViaHostName |sort-object physicalDeliveryOfficeName
    But I’ll get an error:
    select : The value of a parameter was null; one of the following types was expected: {System.String, System.Management.
    Automation.ScriptBlock}.
    At line:2 char:113
    + Get-ADUser -LDAPFilter "(userprincipalname=$i.UserUPN)" -properties physicalDeli ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo         
    : InvalidArgument: (:) [Select-Object], NotSupportedException
        + FullyQualifiedErrorId : DictionaryKeyUnknownType,Microsoft.PowerShell.Commands.SelectObjectCommand
    If I use this command, it works, but then I cannot display DeviceId and LaunchedViaHostName information:
    $users.userupn | %{ Get-ADUser -LDAPFilter "(userprincipalname=$_)" -properties physicalDeliveryOfficeName, streetAddress} | select name, streetAddress, physicalDeliveryOfficeName |sort-object physicalDeliveryOfficeName

    In your code change this
    foreach ($i in $users.UserUPN) {
    Get-ADUser -LDAPFilter "(userprincipalname=$i)" -properties physicalDeliveryOfficeName, streetAddress | select name, streetAddress, physicalDeliveryOfficeName, $i.DeviceId, $i.LaunchedViaHostName |sort-object physicalDeliveryOfficeName
    Import-Module ActiveDirectory
    $users = Get-BrokerSession |select -uniq UserUPN, DeviceId, LaunchedViaHostName
    foreach ($i in $users.UserUPN) {
    Get-ADUser -LDAPFilter "(userprincipalname=$i)" -properties physicalDeliveryOfficeName, streetAddress | select name, streetAddress, physicalDeliveryOfficeName, $i.DeviceId, $i.LaunchedViaHostName |sort-object physicalDeliveryOfficeName
    Regards Chen V [MCTS SharePoint 2010]

  • Display records from two tables in a Repeat Region

    I have 2 tables tblNames and tblResults
    tblNames
    NamesID PK
    FirstName
    LastName
    Address1
    Addrees2
    tblResults
    ResultsID PK
    NamesID FK
    ResultsInfo
    ResultsDate
    Results table has a foreign key NamesID containing primary
    key of Names table.
    I am trying to show a repeat region of results, with a column
    showing LastName of tblNames depending on the ResultsID
    I have 2 recordsets, rsNames and rsResults but I'm having
    trouble showing relevant LastName.

    Create a new recodset or modify one of the old ones with this
    sql:
    SELECT LastName, ResultsInfo, ResultsDate
    FROM tblResults INNER JOIN tblNames USING (NamesID)
    ORDER BY LastName
    This will produce a list of LastNames and associated info
    Dave Buchholz
    I-CRE8
    www.i-cre8.co.uk
    Skype ID: I-CRE8
    "Swn-Y-Mor" <[email protected]> wrote in
    message
    news:f1ndo2$cp9$[email protected]..
    >I have 2 tables tblNames and tblResults
    >
    > tblNames
    > --------
    > NamesID PK
    > FirstName
    > LastName
    > Address1
    > Addrees2
    >
    > tblResults
    > ----------
    > ResultsID PK
    > NamesID FK
    > ResultsInfo
    > ResultsDate
    >
    > Results table has a foreign key NamesID containing
    primary key of Names
    > table.
    >
    > I am trying to show a repeat region of results, with a
    column showing
    > LastName
    > of tblNames depending on the ResultsID
    > I have 2 recordsets, rsNames and rsResults but I'm
    having trouble showing
    > relevant LastName.
    >

  • I want to create stored procedure which will give output rows from "values that are passed as one parameter (comma seperated) to store procedure".

    Hello,
    I want to create stored procedure which will give output rows from "values that are passed as one parameter (comma seperated) to store procedure".
    Suppose , 
    Parameter value : person 1,person2,person3 
    table structure : 
    Project Name | officers 1 | officers 2
    here, officers 1 or officers 2 may contain names of multiple people.
    expected OUTPUT : distinct list(rows) of projects where person 1 or person 2 or person 3 is either officer1 or officer 2. 
    please explain or provide solution in detail 
    - Thanks

    Hi Visakh,
    Thanks for reply.
    But the solution you provided giving me right output only if officer 1 or officer 2 contains single value , not with comma seperated value.
    Your solution is working fine for following scenario : 
    Project 
    Officers 1
    Officers 2
    p1
    of11
    off21
    p2
    of12
    off22
    with parameter : of11,off22 : it will give expected output
    And its not working in case of :
    Project 
    Officers 1
    Officers 2
    p1
    of11,of12
    off21,off23
    p2
    of12,of13
    off22,off24
    with parameter : of11,off22 : it will not give any row in output
    I need patten matching not exact match :) 
    ok
    if thats the case use this modified logic
    CREATE PROC GetProjectDetails
    @PersonList varchar(5000)
    AS
    SELECT p.*
    FROM ProjectTable p
    INNER JOIN dbo.ParseValues(@PersonList,',')f
    ON ',' + p.[officers 1] + ',' LIKE '%,' + f.val + ',%'
    OR ',' + p.[officers 2] + ',' LIKE '%,' + f.val + ',%'
    GO
    Keep in mind that what you've done is a wrong design approach
    You should not be storing multiples values like this as comma separated list in a single column. Learn about normalization . This is in violation of 1st Normal Form
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Displaying information from Numbers in iWeb

    Is there a way to display information from Numbers in iWeb? I am trying to create a FSBO site, and I imagine a scenario where I have all the houses from a table in Numbers listed with hyperlinks to their respective web pages.
    If this is not a good possibility, anyone know of another technology to get this done?
    Thanks,
    Phil

    i've got an application, written in C++ which gets some information from oracle database (...) i write some information to xml file and i want to display in my browser using APEX/Application Builder.
    So i wrote application in java that retrieves information from xml file and now i want to display to it in web browser using APEXIf the information you want to display is already in an Oracle database, you can just use Apex to retrieve and display the information.
    Instead of this:
    Oracle database --> C++ program --> XML file --> Java program --> ??? --> web browserJust do this:
    Oracle database --> Apex --> web browser- Morten
    http://ora-00001.blogspot.com

  • Create a procedure which will pass table name as an argument

    Please let me know, I want to create a procedure which will take
    table name as an argument and will display total no. of rows of
    that table.

    Hopefully this code will help u.
    CREATE OR REPLACE PROCEDURE P1(TAB_NAME IN VARCHAR2, ROW_NO
    OUT NUMBER)
    AS
    SQL_STMT VARCHAR2(1000);
    BEGIN
    SQL_STMT := 'SELECT COUNT(*) FROM ' || TAB_NAME;
    EXECUTE IMMEDIATE SQL_STMT INTO ROW_NO;
    END;
    SQL > VAR A NUMBER
    SQL > EXEC P1('EMP',:A);
    SQL > PRINT A
    A
    12
    SQL > SELECT COUNT(*) FROM EMP;
    COUNT(*)
    12

  • How to test a procedure which returns a recordset from pl/sql

    hello,
    Is it possible to test a procedure which returns a recordset from pl/sql?
    Everything I try results in errors like PLS-00382: expression is of wrong type, when I try to open the result cursor
    or PLS-00221: tc is not a procedure or is undefined.
    I created the following procedure:
    CREATE OR REPLACE PACKAGE test AS
    TYPE cursorType is REF CURSOR;
    PROCEDURE test_cursor( tc IN OUT cursorType,
    v_err OUT varchar2,
    v_msg OUT varchar2);
    END;
    CREATE OR REPLACE
    PACKAGE BODY test AS
    PROCEDURE test_cursor
    (tc IN OUT cursorType,
    v_err OUT varchar2,
    v_msg OUT varchar2)
    AS
    BEGIN
    open tc for
    SELECT '1' "number" FROM dual
    union
    select '2' "number" from dual;
    v_msg := 'no errors';
    v_err := 0;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    v_msg := 'no data found';
    v_err := SQLCODE;
    WHEN OTHERS
    THEN
    v_msg := SQLERRM;
    v_err := SQLCODE;
    END;
    END;
    I try to get the output from pl/sql with something like this:
    DECLARE
    TC PROVGRON.TEST.cursorType;
    V_ERR VARCHAR2(200);
    V_MSG VARCHAR2(200);
    BEGIN
    V_ERR := NULL;
    V_MSG := NULL;
    PROVGRON.TEST.TEST_CURSOR ( TC, V_ERR, V_MSG );
    DBMS_OUTPUT.Put_Line('V_ERR = ' || V_ERR);
    DBMS_OUTPUT.Put_Line('V_MSG = ' || V_MSG);
    -- in tc I was hoping to hava a cursor??
    FOR i IN tc
    LOOP
    DBMS_OUTPUT.PUT_LINE (i.number);
    END LOOP;
    END;
    Without the for loop (or open tc) the pl/sql will output:
    V_ERR = 0
    V_MSG = no errors
    PL/SQL procedure successfully completed.
    With anything I try with the cursor I get errors?
    What am I doing wrong?

    http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch5.htm#sthref1122

  • Display data from diferent tables

    My requirement is to display data from diferent tables supose tables likeVBAK and VBAP.it will allow for all entries concept oops abap?.
    how to write code for display data from diferent tables .
    method WDDOINIT.
    data:
    node_sflight type  ref to if_wd_context_node,
    Itab_sflight type standard table of SFLIGHT.
    select * from SFLIGHT into table Itab_sflight.
    node_sflight = wd_context->get_child_node( name = 'SFLIGHT_NODE' ).
    node_sflight->bind_table( itab_sflight ).
    endmethod.
    Thanks,
    Rama

    HI,
    IS IT CORRECT WAY OF DONIG CODING?
    IF I AM WORNG PLEASE SUGEST ME.
    method WDDOINIT.
    data:
    node_sflight type ref to if_wd_context_node,
    final type standard table of vbap.
    types: begin of t_vbak,
    vbeln type vbak-vbeln,
    end of t_vbak.
    endmethod.
    data wa_vbak type t_vbak.
    data i_vbak type standard table of t_vbak.
    types: begin of t_vbap,
    vbeln type vbap-vbeln,
    posnr type vbap-posnr,
    matnr type vbap-matnr,
    end of t_vbap.
    data wa_vbap type t_vbap.
    data i_vbap type standard table of t_vbap.
    select vbeln from vbak into table I_vbak.
    select vbeln posnr matnr from vbap into table I_vbap
    for all entries in I_vbak
    where vbeln = i_vbak-vbeln.
    loop at I_vbak.
    read table i_vbap with key vbeln = I_vbak-vbeln.
    final-vbeln = I_vbap-vbeln.
    final-posnr = I_vbap-posnr .
    final-matnr = I_vbap-matnr .
    append final.
    clear final.
    endloop.
    node_sflight = wd_context->get_child_node( name = 'NODE_VBAP' ).
    node_sflight->bind_table( final ).
    endmethod.
    Thanks,
    rama

  • Creating a external content type for Read and Update data from two tables in sqlserver using sharepoint designer

    Hi
    how to create a external content type for  Read and Update data from two tables in  sqlserver using sharepoint designer 2010
    i created a bcs service using centraladministration site
    i have two tables in sqlserver
    1)Employee
    -empno
    -firstname
    -lastname
    2)EmpDepartment
    -empno
    -deptno
    -location
    i want to just create a list to display employee details from two tables
    empid firstname deptno location
    and same time update  in two tables
    adil

    When I try to create an external content type based on a view (AdventureWorks2012.vSalesPerson) - I can display the data in an external list.  When I attempt to edit it, I get an error:
    External List fails when attached to a SQL view        
    Sorry, something went wrong
    Failed to update a list item for this external list based on the Entity (External Content Type) 'SalesForce' in EntityNamespace 'http://xxxxxxxx'. Details: The query against the database caused an error.
    I can edit the view in SQL Manager, so it seems strange that it fails.
    Any advice would be greatly GREATLY appreciated. 
    Thanks,
    Randy

  • Can we create a BAM data Object from two tables

    Hi ,
    I want to pull the data from two tables and create a BAM data object, Is it possible in BAM?
    Do the needful
    Regards,
    Francis

    The sample way is using AQ on database. You can create a database view to join the tables. And create AQ on the view, create a ems to listen on the queue.

  • When setting up sync how does sync manage information from two computers? Does it merge the information?

    When setting up sync how does sync manage information from two computers? Does it merge the information?

    Hi!
    Yes, the way Sync works is that it puts all the Bookmarks together and pushes them to all your devices. Same with History.
    You will not loose any information in any of your computers.

  • Creating functions from two tables

    So I have these two tables emp and salary. I would like to create a function to accept a grade from salary table
    and return number of employes belonging to that specific.Similarly, I would like to create a function to accept the
    MGR# from the emp table and return number of employees working under that specific manager.
    1.Create function emp_count
    (I_grade in number)
    return number is
    cnt number (2):=0;
    begin
    Select Count (*) into cnt
    from emp, salary e
    where e.grade= I_grade;
    return (cnt);
    end;
    2.Create function mgr_count
    (I_MGR in number)
    return number is
    cnt number (2):=0;
    begin
    Select Count (emp) into cnt
    from emp e
    where e.mgr= I_mgr;
    return (cnt);
    end;
    Thanks

    Joins are same in SQL and PLSQL...
    Additional things you can do in PLSQL..
    1. Select a single row output in PLSQL variable using INTO
    2. Pass a parameter to Select Query
    You can also select multirow output in collection type variable.
    So coming back to your query write a select query joining emp and salary tables on on grade column (I assume this is the common column between 2 tables) and then filter data using grade input parameter.
    Regards
    Arun

  • How to generate report from two tables using DAO design pattern?

    Hi,
    Iam using struts with DAO pattern for my application. According to DAO design im creating model class for each table in my database with getter,setter methods. i have no problem when im generating report from one table. but if have i have to join two tables whatis the better way for doing that? is it good practise to create a new model contains properties from both the tables?
    Please help me
    Thanks in Advance
    Rajesh

    Dear Rajesh,
    As per the pattern you are creating equivalent java objects for every database table under consideration in which each db field will become a private attribute and public getter and setter methods.
    If you have to display data from one table the above approach is sufficient enough.
    But in case your database is normalised ..lets take an example of Bank having Branch and Accounts tables. We dont need to repeat the whole information of the branch for every account in that branch. so we prefer to have a branch id in that table....this approach lot of insertion/deletion/updatation anomlies that may exists with the database...
    now lets come back to our topic....we shall create two java objects 1) Branch 2) Account.....
    When ever u just need to display simple report u can do it staright forward,,,,,now if u want to display branch information along with the account information....the two objects just created are not sufficient
    So i suggest u the following approaches
    1) Create an attribute of type Branch in the Accounts Object......
    This shall serve the purpose of displaying the Btranch information
    2) Create a collection object of type ( Vector or ArrayList) which can have objects of Account in the Branch Object,,,
    Now its upto u how shall u fill up the objects with appropriate sql queries.
    The method that i mentioned is followed by Oracle Toplink and Hibernate ....which provide Object to relation mapping layers.
    Any queries ...revert back to me...
    Mahesh

  • Selecting from two tables and confirming from them despites they not relate

    Please I need a query to select from two tables that are not related to each other.
    I also want to confirm data's as in verify wether what the user has entered is in accordance with what is in the tables
    Examples
    the first table is named "Card" and the second table is named "Student_Details"
    Card table contains a column named "Pin_Number".
    The Student_Details table contains fields such as Exam_Number, Name, Age, Sex.
    The user has to Enter the Pin_Number which has to be confirmed in the Card table and Exam_Number which has to be confirmed in the Student_Details table and verify that both data's are correct.
    Please I need the SQL and PL/SQL queries for this problem.
    Thanks

    Hi,
    I think you need two different queries
    You can write a procedure like:
    create or replace procedure p1 (p_pin_number number, p_exam_number)
    is
      r_card_row            card%rowtype;
      r_student_details     student_details%rowtype;
      cursor c1 is
      select *
        from card
       where pin_number = p_pin_number;
      cursor c2 is
      select *
        from student_details
       where exam_number = p_exam_number;
    begin
      open c1;
        loop
          fetch c1 into  r_card_row;
          exit when c1%notfound;
          ....  do whatever you want..... and the samething you can do with other cursor
        end loop;
      close c1;
    end p1;Hope this helps
    Ghulam

Maybe you are looking for