Stored procedure to get the Admin users and other users

Hey,.

I am new to stored procedures in Oracle and would really appreciate the help! I have two tables:

_ Of the users
ID USERNAME - PARENT_GROUP - IS_ADMIN
---------------------------------------
1 jsmith - 1-0
brogerson 2-1 - 1
3 jloren - 2-0

Groups
ID - GROUPNAME
-----------------------------------------
1 - ITUsers
2 - AcctUsers

I would like to create a procedure that accepts a users username and returns all users in their group and the user id, or if the user is marked IS_ADMIN, I want that procedure to return all of the users in all groups.

How can I do this? Ideally, I would like the result of the funnel in a DataGridView in c#.

Thank you in advance,

Jeffrey Kevin Pry

Published by: jeffrey.pry on May 10, 2010 10:42

Published by: jeffrey.pry on May 10, 2010 10:43

Hi, Jeffrey.

You can create a view with two copies of the users table: one for the parameter (the original user, you intend to provide run-time) and one for all users in the two
(a) in the same Department, or,
(b) any Department, if the user is an administrator

CREATE OR REPLACE VIEW  p_users
AS
SELECT       u.*
,       g.groupname
,       pu.username   AS p_username
FROM       users          pu
JOIN       groups     g     ON     pu.parent_group     = g.id
                      OR     pu.is_admin     = 1
JOIN       users          u     ON     u.parent_group     = g.id
;

You can use the view like this:

SELECT       *
FROM       p_users
WHERE       p_username     = 'jsmith'
;

The above query returns all users in Group 1, because jsith is in Group 1, but is not an administrator.
Change 'jsmith' to 'brogerson' and you get everybody, because brogerson is an administrator.

This assumes that each user is member of a group.

If you create a namespace SYS_CONTEXT to contain the parameter (the target user name), then you could build the setting in the view:

CREATE OR REPLACE VIEW  p_users
AS
SELECT       u.*
,       g.groupname
,       pu.username   AS p_username
FROM       users          pu
JOIN       groups     g     ON     pu.parent_group     = g.id
                      OR     pu.is_admin     = 1
JOIN       users          u     ON     u.parent_group     = g.id
WHERE       pu.username     = SYS_CONTEXT ('MY_APP_CONTEXT', 'USERNAME')
;

and you wouldn't need a WHERE clause when you query p_users.

Published by: Frank Kulash, 10 May 2010 15:28

Tags: Database

Similar Questions

  • How can I get the history, SID and other details of the accounts of users deleted in Windows XP, 7 and 8?

    Original title: deleted user accounts.

    Hi guys,.

    I want to know the activities of a user whose account has been deleted. How can I get the history, SID and other details of the accounts of users deleted in Windows XP, 7 and 8?

    Hello

    Thanks for posting in the Microsoft Community.

    There is no newspaper available for the activities of the user. There are just a few activities of windows and the error logs is stored in Windows.

    Hope this information helps.

    If you need help to resolve any issues related to Windows, please reply and we will be happy to help you.

  • Last year, I bought my laptop and I tried to create a second user account but I placed it somehow this account as the Admin user. I don't remember the password and my file vault is of course.

    Last year, I bought my laptop and I tried to create a second user account but I placed it somehow this account as the Admin user. I don't remember the password and my file vault is of course.

    What password? You can change a password for the account, but if you do not know the FileVault password, you are in a bind. You need to call Apple directly if you their sent an emergency password when configuring the FV.

    For a user account:

    You forgot your password

    Lion or later version

    Reset a password in Mac OS X 10.7 Lion

    OS X Lion mountain - reset a login password,

    OS X Mavericks-solve password problems,.

    OS X Lion-Apple ID can be used to reset your password for the user account.

  • Get the LDAP user running a DBMS_JOB

    Hello!

    I am building an Application at the APEX 3.2 and the authentication scheme is a type of 'See the Page and use LDAP Directory IDs'.
    It all works very well.

    In this application, I give the possibility to download files and sometimes they are really big, so this download is executed by a job (DBMS_JOB. SUBMIT).
    Also works very well.

    My problem comes when I need to know what the user downloads the file!
    If I run it normally, not with a JOB, I can get the user using the package wwv_flow_custom_auth_std.get_username () and returns exactly what I want.
    But if I use this package inside employment it returns nothing.

    Is there a way to get the Apex user that triggered the work, when running it?

    I need this because I have a journal table, with the history of the records that have been updated / deleted and which update/remove the.

    Thank you

    Vania

    Vanya:

    You can do the following in the stored procedure

    Dbms_application_info package to set up "client_info" for the user name passed to the procedure

    dbms_application_info.set_client_info(p_user);
    

    The stored value can then be retrieved in the current session to help

    select sys_context('USERENV','CLIENT_INFO') into aud_user from dual;
    

    CITY

  • Fail to connect to Citrix with limited user, but succeeds with the Admin user

    On one of the facilities of our clients located on a Citrix server, users cannot connect to the database when they are limited to users. But if the same user is promoted to the administrator, it can connect.

    The Application uses ODP.Net to connect. In the installation of the other tools that use what ODBC works for limited users.

    The OracleConnection.Open method throws an exception without error message.
    The stack trace is:
    at Oracle.DataAccess.Client.OracleException.HandleErrorHelper (Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx * pOpoSqlValCtx, ByVal src, string procedure)
    at Oracle.DataAccess.Client.OracleException.HandleError (Int32 errCode, OracleConnection conn, IntPtr, Object src opsErrCtx)
    at Oracle.DataAccess.Client.OracleConnection.Open)
    ---

    We have installed the Oracle Client 10.2.0.1 where the provider .net is also installed on the server (otherwise it wouldn't work for the admin user either).

    Anyone have any idea on why this strange behavior happening?

    / Nils

    This is a known issue in 10201 and should be solved by patching the customer until 10204. You do this by applying the patch of the database to the client, and you can get the patch of 10204 database on Metalink.

    See you soon,.
    Greg

  • How can I get the admin if the Admin is under a guest account?

    I have a laptop Windows 8 and I don't know how to change it so that I can become an administrator under my account. The Admin is assigned to a guest to the site account.

    I tried to connect it to my account of comments and to the administrator of my personal account, but it does not take effect.

    Because this does not work, I made a 3rd account through my personal account to test it (because the guarded guest account says I need internet connection for that) to try to get the Admin for the account of the 3rd. Still does not work. Now, I can't even delete the account of the 3rd.

    I did these steps:

    Control Panel > user accounts > change account Type > switch from Standard to administrator and then click on "change the account type. Then, it comes to the previous screen and no change has been made.

    I had tried this step through the guest account (Administrator) and also my personal account and nothing works.

    Another thing, I tried going under the guest account and system restore, but it refused access. I ALSO tried to refresh PC, delete all and restore windows... .and still access denied.

    If there is no administrator account on the system, you can start safe mode to access the built-in Administrator account.  This integrated security account, you can force-reset security level of your own account.

    1. Press + I to display the menu of charm.
    2. Click the Power Options icon, and then hold down the SHIFT key while you click the Restart option. Keep now shift until the screen shows it restarts.
    3. On the first screen that appears, select troubleshooting, and then select Advanced Options. Finally, choose the boot settings and click Restart.
    4. On the next screen, press the number 4 to choose Safe Mode.

    Now that you are in safe mode, you can use the backup Administrator account built for perform you a necessary recovery. Built in Administrator account should not be used for any other purpose, or it is not available in such situations when you need it.

    1. On the login screen, click on the arrow icon, and then select the administrator account.
    2. After the Safe Mode boot, press on + W and open the control panel / user accounts.
    3. Select manage another account, and then select the account you want to switch to an administrator account.

    When finished, restart the computer normally.

  • Database connection - error of creation of the admin user Setup. No route to host

    During step 2: configuration of the database connection we select the "internal database".
    After a short delay, we get a message saying "error of creation of the admin user. No route to the host.
    I have been more before DNS records and back and everything seems in good condition.
    Can someone point me in the right direction to solve this error?
    HW-Error.jpg

    This is an SSL certificate error. Have you changed the default self-signed SSL certificates?

  • The ADMIN user has not created in my Apex 4.1 installation

    No matter how many times I run apxchpwd.sql, I can't my admin login page to tell me anything except "Invalid credentials." When I checked APEX_040100.wwv_flow_fnd_user, I found that the table was empty. There is no line for ADMIN at all, so there is nothing to apxchpwd.sql update. What can I do to add the user? I use HTTP Server and modplsql, not Apex listener. Thank you.

    Near the top of your Setup log file is show "Procedure with a new installation." or "Do an upgrade installation."?

    If it is an upgrade installation, it does not create the ADMIN user. Maybe delete all versions of the TOP before installing the new version, as a previous version was perhaps not setup correctly.

  • Hello everyone, I just bought a Thunderbolt Apple display to use with my 2012 15 "27" Macbook Pro, Win10/Bootcamp. Is anyone know the procedure to get the display to work with Bootcamp Windows 10?  I have connected screen but no picture. TY

    Hi all

    I just bought a Thunderbolt Apple display to use with my 2012 15 "27" Macbook Pro Win10/Boot Camp running. Is anyone know the procedure to get the display to work with Bootcamp/Windows 10? Is there a setting in the training Camp that must be turned on to make it work? I have connected screen but could not get a desktop display.  Any help would be really appreciated! TY

    The monitor should have a TB and adapter power connector. The monitor works on both OSX. ? If so, shut down of windows, connect monitor and start Windows. Your TB 2012 monitor is not plug-and-play with Windows.

    Please see ports Thunderbolt and views: frequently asked questions (FAQ) - Apple Support .

    1. the "hot pluggable" Thunderbolt devices using Windows with Boot Camp?

    Thunderbolt hot plugging is supported under Windows 8 or 8.1 on all Macs from 2014 and later.

    For all other Mac computers, Windows 7, 8 and 8.1 scans and active them Thunderbolt devices connected to ports Thunderbolt during the Windows startup process. If your device has been plugged in not at startup, Windows detects not without a reboot.

  • HP G72: How to disable the Admin password and turn on Pasword

    Hi, I have a HP G72 laptop, while playing in the BIOS, I put the Admin password and turn on the password.

    I do not know the password but it would disable instead so I don't have to enter it every time I turn it on.

    I entered the wrong code 3 volumes to get the system to disable the code where it is the only way to disable them.

    Code: 94011656.

    Thanks for your help.

    @-Lateralus-

    Enter 21979298

  • my password does not work on windows vista. I get the message user profile service has no logon

    My password does not work. I get the message user profile service has no logon. Help please.

    Hello

    You can try the following.

    Shut down the laptop.  Tap away at f8 that you start the laptop to enter the Windows Recovery Console.  Use the arrow keys to select Safe mode and press ENTER.  If windows will load in this mode, on the Start Menu, click principally made programs, click Accessories, click System Tools and run the system restore.  Choose a restore point at least 24 hours prior to the issue of logon and then proceed to the restoration.  When you are finished, Windows will restart as normal in order to check if you can now connect correctly.

    Another option if the above does not help is as follows.

    Shut down the laptop.  Tap away at f8 that you start the laptop to enter the Windows Recovery Console.  Use the arrow keys to select "Start using last good known Configuration" and press ENTER.

    Kind regards

    DP - K

  • Use the stored procedure to create the data model for the bi publisher report

    Hi all

    Can we use stored procedure to create the data model for BI Publisher reports? I did find an example by using the stored procedure to complete the data model in the bi publisher report.

    Thank you

    Virat

    Check out these links

    BI publisher to use the stored procedure
    Re: Stored procedures and dynamic columns
    Re: Is it possible to use stored procedures in BI Publisher GUI?
    Re: PL/SQL stored w / model XML?

    If brand pls help

  • How to get the outline color and size of the rectangle?

    Hi all

    I'm developing an extension for CS5 and higher (including the CC version). I want to get the outline color and size of a rectangle. I was able to do in CS5. But I noticed that in the version of the CC, there are two ways in which the user can apply to a stroke. One is by applying the effect in the layer Style, and the other through the properties panel. I am able to get the values of time in my script, if it is applied through layer Style, but I can't do it in the other scenario.

    How are these two different traits and how do I get the outline color and size if it is applied via the properties panel using script?

    Thank you!

    Here's what I have so far. It takes more work, but I don't think that's never very accurate.

    function toggleOtherLayersVisibility() {
        var desc = new ActionDescriptor();
            var list = new ActionList();
                var ref = new ActionReference();
                ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
            list.putReference( ref );
        desc.putList( charIDToTypeID('null'), list );
        desc.putBoolean( charIDToTypeID('TglO'), true );
        executeAction( charIDToTypeID('Shw '), desc, DialogModes.NO );
    };
    function liveShapeFillEnabled( enable ) {// boolean
        var desc = new ActionDescriptor();
            var ref = new ActionReference();
            ref.putEnumerated( stringIDToTypeID('contentLayer'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
        desc.putReference( charIDToTypeID('null'), ref );
            var shapeDesc = new ActionDescriptor();
                var styleDesc = new ActionDescriptor();
                styleDesc.putInteger( stringIDToTypeID('strokeStyleVersion'), 2 );
                styleDesc.putBoolean( stringIDToTypeID('fillEnabled'), enable );
            shapeDesc.putObject( stringIDToTypeID('strokeStyle'), stringIDToTypeID('strokeStyle'), styleDesc );
        desc.putObject( charIDToTypeID('T   '), stringIDToTypeID('shapeStyle'), shapeDesc );
        executeAction( charIDToTypeID('setd'), desc, DialogModes.NO );
    };
    function dupeVisibleMerged() {
        var desc = new ActionDescriptor();
        desc.putBoolean( charIDToTypeID('Dplc'), true );
        executeAction( charIDToTypeID('MrgV'), desc, DialogModes.NO );
    };
    function loadTransparency(){
        var desc = new ActionDescriptor();
            var ref = new ActionReference();
            ref.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
        desc.putReference( charIDToTypeID( "null" ), ref );
            var ref1 = new ActionReference();
            ref1.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Trsp" ) );
        desc.putReference( charIDToTypeID( "T   " ), ref1 );
        executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );
    };
    function getLiveShapeStrokeInfo(){
        var doc = app.activeDocument;
        var lyr = doc.activeLayer;
        liveShapeFillEnabled( false );
        toggleOtherLayersVisibility();
        doc.artLayers.add();
        dupeVisibleMerged();
        var bounds = doc.activeLayer.bounds;
        var horzCenter = (bounds[2]-bounds[0])/2;
        var vertCenter = (bounds[3]-bounds[1])/2;
        lyr.visible = false;
        var sampler = doc.colorSamplers.add([bounds[0]+UnitValue(.5,'px'),bounds[1]+vertCenter]);
        sizeObject.color = sampler.color;
        loadTransparency();
        doc.selection.select([
                                [bounds[0],bounds[1]+vertCenter],
                                [bounds[0]+horzCenter,bounds[1]+vertCenter],
                                 [bounds[0]+horzCenter,bounds[1]+vertCenter+UnitValue(1,'px')],
                                 [bounds[0]+UnitValue(1,'px'),bounds[1]+vertCenter+UnitValue(1,'px')]],SelectionType.INTERSECT);
    
        sizeObject.size = doc.selection.bounds[2]-doc.selection.bounds[0];
    };
    var sizeObject = {};
    app.activeDocument.suspendHistory('Get Live stroke info','getLiveShapeStrokeInfo()');
    executeAction( charIDToTypeID('undo'), undefined, DialogModes.NO );
    sizeObject.size;
    
  • I can't get the number 5 and 6 of my key Board that is

    I can't get the number 5 and 6 on my key Board that happen about two hours ago please help me on fixing the problem

    Hello bigarthur, this is what is happening in the different programs that you use on your computer or just in firefox?

  • should I get the 32 gig and increase storage icloud or get the 128 gig?

    Should I get the 32 gig and increase storage icloud or get the 128 gig?

    iCloud can't complete really the iPads of storage on board. You can't have apps to run from iCloud, you can't the films played to iCloud, etc...

    If you plan to use more than the 32GBs go for bigger sizes.

Maybe you are looking for