Using named constants in SQL rather than magic numbers

We are running Oracle 7.3.4. In our system we have a number of
tables that just store static data. For example, we have a table
that stores the different types of statuses that a docket can
have:
Docket_Status: docket_status_id NUMBER(8), description VARCHAR
(100)
It has a small number of records as follows:
docket_status_id description
1 New
2 Issued
3 Completed
4 Finalised
and so on.
When we want to select all of the dockets with a status of
"New", we could do something like:
select d.*
from docket d
where d.docket_status_id = 1
However, this SQL statement is not particularly readable or
maintainable since the "1" is meaningless unless you have
memorised the id fields for the docket.
So we defined constants for each of the static data tables, in a
package of their own:
PACKAGE DOCKET_STATUS_PL IS
New_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 1;
Issued_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 2;
Completed_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 3;
and so on.
Ideally you could directly reference these values in SQL as
follows:
select d.*
from docket d
where d.docket_status_id = Docket_Status_Pl.New_Id
But SQL does not let allow this - an invalid column error is
raised when this is parsed.
So the package must then be changed to have functions pass back
each of the constants.
PACKAGE DOCKET_STATUS_PL IS
FUNCTION New_Id RETURN NUMBER;
PRAGMA RESTRICT_REFERENCES(New_Id, WNDS, WNPS);
FUNCTION Issued_Id RETURN NUMBER;
PRAGMA RESTRICT_REFERENCES(Issued_Id, WNDS, WNPS);
FUNCTION Completed_Id RETURN NUMBER;
PRAGMA RESTRICT_REFERENCES(Completed_Id, WNDS, WNPS);
and so on.
PACKAGE BODY DOCKET_STATUS_PL IS
N_New_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 1;
N_Issued_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 2;
N_Completed_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 3;
FUNCTION New_Id RETURN NUMBER IS
BEGIN
RETURN N_New_Id;
END;
FUNCTION Issued_Id RETURN NUMBER IS
BEGIN
RETURN N_Issued_Id;
END;
and so on.
Once these functions have been defined in the packages, they can
be called in a SQL statement as follows:
select d.*
from docket d
where d.docket_status_id = Docket_Status_Pl.New_Id
This makes the SQL statement a lot more readable, but has the
unfortunate by-product of having the Docket_Status_Pl.New_Id
function called for every row in the docket table. Although it
is very quick to call, once there are thousands of records in
the docket table this can add up to a lot of extra
time/processing.
An alternative is to select the constant from the dual table as
follows:
select d.*
from docket d
where d.docket_status_id = (select Docket_Status_Pl.New_Id from
dual)
This works but is not really an ideal solution, since it
decreases the readability of the SQL statement.
Does anyone know of alternatives to this approach? Ideally
package constants could be referenced from SQL, but this does
not work under our version of Oracle. Do any later versions
support this ability?
Any suggestions would be much appreciated.
null

I don't understand why you cannot just select on the description
column if you don't no the id. If speed is a problem create a
unique not null index on the column description. Technically
this should have been done since your id column is a is not
the "REAL" primary key.
Having said that you could also create a view on top of this
table which mimics your package.
CREATE OR REPLACE VIEW name_of_view AS
SELECT DECODE(docket_status_id, 1, 'New_id',
2, 'Issued_Id',
3, 'Completed_Id',
'OTHER') alt_description,
docket_status_id description
FROM name_of_table
then select * from name_of_view
where alt_description = 'New_id'
Geoff Hardy (guest) wrote:
: We are running Oracle 7.3.4. In our system we have a number of
: tables that just store static data. For example, we have a
table
: that stores the different types of statuses that a docket can
: have:
: Docket_Status: docket_status_id NUMBER(8), description VARCHAR
: (100)
: It has a small number of records as follows:
: docket_status_id description
: 1 New
: 2 Issued
: 3 Completed
: 4 Finalised
: and so on.
: When we want to select all of the dockets with a status of
: "New", we could do something like:
: select d.*
: from docket d
: where d.docket_status_id = 1
: However, this SQL statement is not particularly readable or
: maintainable since the "1" is meaningless unless you have
: memorised the id fields for the docket.
: So we defined constants for each of the static data tables, in
a
: package of their own:
: PACKAGE DOCKET_STATUS_PL IS
: New_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 1;
: Issued_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 2;
: Completed_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 3;
: and so on.
: Ideally you could directly reference these values in SQL as
: follows:
: select d.*
: from docket d
: where d.docket_status_id = Docket_Status_Pl.New_Id
: But SQL does not let allow this - an invalid column error is
: raised when this is parsed.
: So the package must then be changed to have functions pass back
: each of the constants.
: PACKAGE DOCKET_STATUS_PL IS
: FUNCTION New_Id RETURN NUMBER;
: PRAGMA RESTRICT_REFERENCES(New_Id, WNDS, WNPS);
: FUNCTION Issued_Id RETURN NUMBER;
: PRAGMA RESTRICT_REFERENCES(Issued_Id, WNDS, WNPS);
: FUNCTION Completed_Id RETURN NUMBER;
: PRAGMA RESTRICT_REFERENCES(Completed_Id, WNDS, WNPS);
: and so on.
: PACKAGE BODY DOCKET_STATUS_PL IS
: N_New_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE :=
1;
: N_Issued_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE :=
2;
: N_Completed_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE :=
3;
: FUNCTION New_Id RETURN NUMBER IS
: BEGIN
: RETURN N_New_Id;
: END;
: FUNCTION Issued_Id RETURN NUMBER IS
: BEGIN
: RETURN N_Issued_Id;
: END;
: and so on.
: Once these functions have been defined in the packages, they
can
: be called in a SQL statement as follows:
: select d.*
: from docket d
: where d.docket_status_id = Docket_Status_Pl.New_Id
: This makes the SQL statement a lot more readable, but has the
: unfortunate by-product of having the Docket_Status_Pl.New_Id
: function called for every row in the docket table. Although it
: is very quick to call, once there are thousands of records in
: the docket table this can add up to a lot of extra
: time/processing.
: An alternative is to select the constant from the dual table as
: follows:
: select d.*
: from docket d
: where d.docket_status_id = (select Docket_Status_Pl.New_Id
from
: dual)
: This works but is not really an ideal solution, since it
: decreases the readability of the SQL statement.
: Does anyone know of alternatives to this approach? Ideally
: package constants could be referenced from SQL, but this does
: not work under our version of Oracle. Do any later versions
: support this ability?
: Any suggestions would be much appreciated.
null

Similar Messages

  • I created a website with iWeb but use GoDady for hosting it rather than MobileMe. The images on my Gallery page do not show at all on the external domain but they DO show when seen on MobileMe. Has anyone encountered this problem before? Many thanks!

    Hello al!
    I created a website with iWeb but use GoDady for hosting it rather than MobileMe. The images on my Gallery page do not show at all on the external domain but they DO show when seen on MobileMe. Has anyone encountered this problem before? Many thanks!

    Just create a new page (or use the existing photo page) on your external site and use html to add an iframe sized to the page and link it to the mobilme gallery page. Works for me just fine when showing my gallery from a yahoo site.
    like this
    <iframe scrolling="off" allowTransparency="true" frameborder="0" scrolling="yes" style="width:100%;height:100%;border:none" src="http://gallery.me.com/your_account_name"></iframe>

  • How can I get the App store to use money in my account rather than a credit card when I want to buy something?

    How can I get the App store to use money in my account rather than a credit card when I want to buy something?

    The iTunes/Mac App Stores use credit on an account first. You are asked to supply an additional payment method when the cash credit doesn't cover the complete cost of the purchase.

  • I heard some promote use of "Terminal Services(RDS)", rather than App-V application with SCCM 2012 even if you have SCCM licens.

    Hi,
    I heard some promote use of "Terminal Services(RDS)", rather than App-V application with SCCM 2012 even if you have SCCM licens. The reason you dont need to repackage\test the application on an client OS...
    I don't agree and I have not Heard this Before, just that you use TS for some scenario.
    Or is it more likely that "Terminal Services(RDS)", take over the applikation administration?
    /SaiTech

    Surely this all depends on your environment. There's nothing wrong with creating RemoteApps to push to client devices. Maybe you have an environment where RDS is widely used. 
    Why not leverage both solutions and target App-V's at RDS servers and then create App-V based RemoteApps that users can run at home as part of a home working solution via RDWeb.
    Creating apps via RDS will be an admin overhead yes but then so is creating App-V packages in SCCM.
    I don't agree with the arguement re: 'you dont need to repackage\test the application on an client OS...' as
    App-V allows you to run on multple O/S types. 
    To be honest both technologies have their pros and cons. 
    Cheers
    Paul | sccmentor.wordpress.com

  • DataTrigger : can it be used for other pl/sql code than before and after?

    Hi,
    I was wondering whether the <dataTrigger ...../> can also be used for other PL/SQL code than just using it for the beforeReport, afterReport and stuf.
    Just now I placed a call to it in the datastructure, as last entry in a group (for headers f.i.), called it AfterHeaderTrigger, and called a function in a package.
    It didn't fail, but I dont think it excecuted it though.
    So, can you do that?
    thanks
    Ronny

    thanks, that's what I thought.
    It's a shame, it would have been so cool.
    thanks
    Ronny

  • How can I use the database default time rather than Java supplied time

    I've searched over and over and nobody seems to have this issue so maybe its just me!
    When inserting a record I would like the a create_date column to automatically use the database time rather than a supplied time via JPA. That was all times a relative to the database which makes sense.
    The trouble is I cant figure out how to do this in a sensible manor.
    If I specify an column like :
         @Temporal(TemporalType.TIMESTAMP)
         @Column(name = "CREATE_DATE")
         private Date createDate;
    and IDL
    CREATE_DATE TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_DATE NOT NULL
    If I leave createDate null I get an exception. If modify the column to allow Nullable then column is set as Null.
    If I leave the column out of the entity bean and then and create a row then the database current time is inserted. The trouble then is that if I want to read the date I'm going to have to create a copy of the bean but with the CREATE_DATE in it, and this doesn't make sense.

    I should also mention that TopLink has always supported the ability to retrieve the current time from the database for use in optimistic locking. The TimestampLockingPolicy offers the ability to configure the next value being retrieved from the database instead of using the local time from the JVM. Our extended optimistic locking configuration does not currently support setting this option but it could be done using a descriptor customizer which can be configured in your persistence unit properties.
    Using optimistic locking may be a good solution for the last modified date since it will also ensure that you do not corrupt the database if someone else has incremented this value since your last read.
    Doug

  • How to make web shortcuts use icon provided by website rather than default

    I'm a new Mac user, and I find it hard to use web shortcuts on my desktop and dock, because when I drag them from my browser to there, they all get the at sign on a spring icon, rather than the default icon provided by the website, which shows up next to the URL in the browser. Is there some setting that will allow it to use and keep that icon when I drag shortcuts?

    rjo98 wrote:
    That's a shame. It's so easy when I use my PC with Internet Explorer, I just drag from IE to the desktop, and it uses that icon by default.
    I guess it could be interpreted as a shame that you can not get the favicon to stick to the desktop, different anyway. As Thomas A Reed suggested above, the link itself can receive a custom icon.
    The advantage of creating a folder is other associated +files, receipts and links+ can be included in the stack with the link itself.
    It is a shame the PC with IE cannot add this functionality, for my purpose anyway.

  • I would like to be able to enter my own page sizes to use in the Book Module, rather than choosing defaults from the drop-down. Is it possible to do this?

    I would like to be able to enter my own page sizes to use in the Book Module (to export to 3rd party printers), rather than choosing defaults from the drop-down. Is it possible to do this?

    No. You are limited to the choices within the Lightroom Book module.

  • I have iCloud setup within outlook. If I change a calendar event in oulook it is sending updates to invitees using my iCloud email address rather than my outlook work email address.

    My outlook on my windows PC has mail setup already using my work email address. I have added iCloud now so my outlook calendar is always synced with my iphone. My iCloud username is my personal email address not my work email address. Problem is I just updated a meeting time in my calendar on outlook and it sent an update to my invitees using my personal email address regisetered with iCloud rather than my outlook work email address. I dont understand this as if I check my outlook sent items, I can clearly see that my updated meeting request was sent from my work email in outlook. Does iCloud automatically send updates to invitees using your iCloud username?

    Same here.. My girlfriend imported her calendar in iCloud from work and iCloud has send everyone in her appointments an email. Not funny....
    I'm afraid that if she is deleting her iCloud calendar everyone will get a mail that the meeting is canceled. By the way she exported her work calendar to an .ICS file which she imported in Outlook at home. Then she copied the calender (no other way) to iCloud.
    Apple I love your stuff but please do not mess around with this stuff or warn people better.. You can not send everyone in someone's calendar an email without let the user decide wether she wants that or not....
    Will Google further for solutions...

  • Why use Protected Overide Sub OnPaint rather than the standard Paint_Event ?

    I notice many good programmers use this following method rather than the usual Paint_Event when painting to the form.
    Protected Overrides Sub OnPaint(e As PaintEventArgs)
    Dim g As Graphics = e.Graphics
    g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
    g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
    MyBase.OnPaint(e)
    End Sub
    Can anybody share the reasons why? Thanks 
    Top Tip: Toothache? Cut paper towel to 2"square. Smear with olive oil. Sprinkle on Cayenne Pepper. Fold over few times to form small wad. Tuck in between wall of mouth and gum. Leave 1 - 2 hrs. You will thank me!

    OK Crazypennie, maybe you are right. I tend to rant on a bit sometimes.
    Also, maybe the jumpy graphics is made worse because the animation output is not synced with the video hardware refresh rate. We can get around that slightly by using a very high fps. 
    Hi Leon,
    I tried modifying your code using a GraphicsFrame class that I wrote a little while back, the class utilizes the bufferedcontext/bufferedgraphics, instead of using the forms graphics directly. In theory, all objects should be rendered to the buffer before
    the forms graphics object. Is this less glitchy/faster on your pc? It seemed less glitchy/faster on mine..., and previous benchmarks show that using buffered graphics in this manner improved render time.
    You can read the discussion on
    this thread.
    Option Strict On
    Option Explicit On
    Option Infer Off
    Public Class Form11 ' drawing Code by Paul Ishak Apr 2015 A spinning pie chart. My timing code.
    Private Angle As Single = 100
    Private NextIncrement As Single = 1
    Private Randomizer As New Random(Now.Millisecond)
    Private SliceColors As New List(Of Color)
    Private SlicesOnWheel As Integer = 24
    Private Velocity As Single = 0
    Private WheelRadius As Integer = 300
    Private WheelLocation As New Point(50, 50)
    Private SW As New Stopwatch
    Private SFlag As Boolean ' wheel is currently spinning
    Private CntMS As Integer ' count the milliseconds
    Protected Overrides Sub OnPaint(e As PaintEventArgs)
    Dim gFrame As New GraphicsFrame(e.Graphics, Me.ClientRectangle.Size)
    Dim g As Graphics = gFrame.Graphics
    g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
    g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
    g.Clear(Me.BackColor)
    Dim sliceAngle As Single = CSng(360 / SlicesOnWheel)
    Dim rect As New Rectangle(WheelLocation, New Size(WheelRadius, WheelRadius))
    Dim curveWidth As Integer = CInt(WheelRadius - (WheelRadius / (2.0! * 0.9)))
    Dim rect2 As New Rectangle(rect.Left + curveWidth, rect.Top + curveWidth, rect.Width - curveWidth * 2, rect.Height - curveWidth * 2)
    Dim inc As UInteger = UInteger.MaxValue \ 360
    For I As Single = 0 To 359 Step sliceAngle
    g.FillPie(New SolidBrush(SliceColors(CInt(I / sliceAngle))), rect, I + NormalizeAngle(Angle), sliceAngle)
    g.DrawPie(Pens.White, rect, I + NormalizeAngle(Angle), sliceAngle)
    Next
    g.FillEllipse(Brushes.Black, rect2)
    g.DrawEllipse(Pens.White, rect2)
    g.DrawEllipse(Pens.White, rect)
    MyBase.OnPaint(e)
    If SFlag Then
    If Me.Text = " " Then Me.Text = "" Else Me.Text = " "
    End If
    gFrame.Render()
    gFrame.Dispose()
    MyBase.OnPaint(e)
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnSpin.Click
    If Not SFlag Then
    Velocity = Randomizer.Next(3, 5)
    NextIncrement = Velocity
    SFlag = True
    CntMS = 0 : SW.Reset() : SW.Start()
    If Me.Text = " " Then Me.Text = "" Else Me.Text = " "
    End If
    End Sub
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.DoubleBuffered = True
    SliceColors.Add(Color.Black)
    SliceColors.Add(Color.LightBlue)
    SliceColors.Add(Color.SeaGreen)
    SliceColors.Add(Color.Yellow)
    SliceColors.Add(Color.Red)
    SliceColors.Add(Color.LightBlue)
    SliceColors.Add(Color.Orange)
    SliceColors.Add(Color.Violet)
    SliceColors.Add(Color.Yellow)
    SliceColors.Add(Color.Black)
    SliceColors.Add(Color.Green)
    SliceColors.Add(Color.Black)
    SliceColors.Add(Color.Green)
    SliceColors.Add(Color.Red)
    SliceColors.Add(Color.Blue)
    SliceColors.Add(Color.SeaGreen)
    SliceColors.Add(Color.Pink)
    SliceColors.Add(Color.Black)
    SliceColors.Add(Color.Purple)
    SliceColors.Add(Color.SkyBlue)
    SliceColors.Add(Color.Aqua)
    SliceColors.Add(Color.White)
    SliceColors.Add(Color.Red)
    SliceColors.Add(Color.Blue)
    SliceColors.Add(Color.Pink)
    SliceColors.Add(Color.SeaGreen)
    SliceColors.Add(Color.Orange)
    ClientSize = New Size(375, 375)
    Me.Show()
    btnSpin.Refresh()
    End Sub
    Public Function NormalizeAngle(value As Single) As Single
    Return value Mod 360.0!
    End Function
    Private Sub Form11_TextChanged(sender As Object, e As EventArgs) Handles Me.TextChanged
    If Not SFlag Then Exit Sub
    Angle = NormalizeAngle(Angle + NextIncrement)
    NextIncrement = CSng(NextIncrement - 0.0033)
    If NextIncrement <= 0.0033 Then
    SFlag = False : SW.Stop() : Exit Sub
    End If
    Invalidate()
    CntMS += 5 ' <<< set timer interval here <<<
    Do Until SW.ElapsedMilliseconds > CntMS
    Loop
    End Sub
    End Class
    Public Class GraphicsFrame
    Implements IDisposable
    Private disposedValue As Boolean
    Private BackBuffer As System.Drawing.BufferedGraphics = Nothing
    Public ReadOnly Property Graphics() As System.Drawing.Graphics
    Get
    Return Me.BackBuffer.Graphics
    End Get
    End Property
    Public Sub New(ByVal canvas As System.Windows.Forms.Control)
    BufferedGraphicsManager.Current.MaximumBuffer = New Size(canvas.ClientRectangle.Width + 1, canvas.ClientRectangle.Height + 1)
    Me.BackBuffer = BufferedGraphicsManager.Current.Allocate(canvas.CreateGraphics, New Rectangle(0, 0, canvas.ClientRectangle.Width, canvas.ClientRectangle.Height))
    End Sub
    Public Sub New(ByVal canvasGraphics As Graphics, maximumBuffer As Size)
    BufferedGraphicsManager.Current.MaximumBuffer = New Size(maximumBuffer.Width + 1, maximumBuffer.Height + 1)
    Me.BackBuffer = BufferedGraphicsManager.Current.Allocate(canvasGraphics, New Rectangle(0, 0, maximumBuffer.Width, maximumBuffer.Height))
    End Sub
    Public Sub New(ByVal handle As IntPtr, maximumBuffer As Size)
    BufferedGraphicsManager.Current.MaximumBuffer = New Size(maximumBuffer.Width + 1, maximumBuffer.Height + 1)
    Me.BackBuffer = BufferedGraphicsManager.Current.Allocate(Graphics.FromHwnd(handle), New Rectangle(0, 0, maximumBuffer.Width, maximumBuffer.Height))
    End Sub
    Public Sub New(ByVal canvas As Image)
    BufferedGraphicsManager.Current.MaximumBuffer = New Size(canvas.Width + 1, canvas.Height + 1)
    Me.BackBuffer = BufferedGraphicsManager.Current.Allocate(Graphics.FromImage(canvas), New Rectangle(0, 0, canvas.Width, canvas.Height))
    End Sub
    Public Sub New(ByVal canvas As Bitmap)
    BufferedGraphicsManager.Current.MaximumBuffer = New Size(canvas.Size.Width + 1, canvas.Size.Height + 1)
    Me.BackBuffer = BufferedGraphicsManager.Current.Allocate(Graphics.FromImage(canvas), New Rectangle(0, 0, canvas.Width, canvas.Height))
    End Sub
    Public Sub Render()
    If Not BackBuffer Is Nothing Then BackBuffer.Render()
    End Sub
    Protected Overridable Sub Dispose(disposing As Boolean)
    If Not Me.disposedValue Then
    If disposing Then
    Me.BackBuffer = Nothing
    GC.Collect()
    End If
    End If
    Me.disposedValue = True
    End Sub
    Public Sub Dispose() Implements IDisposable.Dispose
    Dispose(True)
    GC.SuppressFinalize(Me)
    End Sub
    End Class
    Don't forget to vote for Helpful Posts and
    Mark Answers!
    *This post does not reflect the opinion of Microsoft, or its employees.

  • Concatenate using SQL rather than Oracle functions Oracle 8i

    Is it possible to concatenate field values using SQL alone and not an Oracle function
    For the following dataset I would like the results to be the following
    1 User_lastname1 2,7
    2 User_lastname2 2,7
    3 User_lastname3 2
    4 User_lastname4 7
    CREATE TABLE users
    ( user_id NUMBER(10)
    , user_lastname VARCHAR2 (50)
    , workgroup NUMBER(10)
    INSERT ALL
    INTO users(user_id, user_lastname, workgroup) VALUES (1, User_lastname1, 2)
    INTO users(user_id, user_lastname, workgroup) VALUES (1, User_lastname1, 7)
    INTO users(user_id, user_lastname, workgroup) VALUES (2, User_lastname2, 2)
    INTO users(user_id, user_lastname, workgroup) VALUES (2, User_lastname2, 7)
    INTO users(user_id, user_lastname, workgroup) VALUES (3, User_lastname3, 2)
    INTO users(user_id, user_lastname, workgroup) VALUES (4, User_lastname4, 7)

    Maybe (provided a user is not a member of more than six workgroups)
    select user_id,
           user_lastname,
           max(decode(rno,1,workgroup,null)) || max(decode(rno,2,','||workgroup,null)) ||
                                                max(decode(rno,3,','||workgroup,null)) ||
                                                max(decode(rno,4,','||workgroup,null)) ||
                                                max(decode(rno,5,','||workgroup,null)) ||
                                                max(decode(rno,6,','||workgroup,null)) string
      from (select user_id,
                   user_lastname,
                   workgroup,
                   row_number() over (partition by user_id,user_lastname order by workgroup) rno
              from users
    group by user_id,
              user_lastname
    order by user_id,
              user_lastnameor (provided a user is not a member of more than five workgroups)
    select user_id,
           user_lastname,
           string
      from (select user_id,
                   user_lastname,
                   row_number() over (partition by user_id,user_lastname order by workgroup) rno,
                   workgroup || lead(','||workgroup,1) over (partition by user_id,user_lastname order by workgroup) ||
                                lead(','||workgroup,2) over (partition by user_id,user_lastname order by workgroup) ||
                                lead(','||workgroup,3) over (partition by user_id,user_lastname order by workgroup) ||
                                lead(','||workgroup,4) over (partition by user_id,user_lastname order by workgroup) string
              from users
    where rno = 1
    order by user_id,
              user_lastnameRegards
    Etbin

  • Why would you use a managed service account rather than a virtual account in SQL Server 2012?

    In SQL Server 2012, service accounts are created as
    virtual accounts (VAs), as described
    here, as opposed to
    managed service accounts (MSAs).
    The important differences I can see for these, based on the descriptions:
    MSAs are domain accounts, VAs are local accounts
    MSAs use automagic password management handled by AD, VAs have no passwords
    in a Kerberos context, MSAs register SPNs automatically, VAs do not
    Are there any other differences? If Kerberos is not in use, why would a DBA ever prefer an MSA?
    UPDATE:
    Another user has noted a
    possible contradiction in the MS docs concerning VAs:
    The virtual account is auto-managed, and the virtual account can access the network
    in a domain environment.
    versus
    Virtual accounts cannot be authenticated to a remote location. All virtual accounts
    use the permission of machine account. Provision the machine account in the format
    <domain_name>\<computer_name>$.
    What is the "machine account"? How/when/why does it get "provisioned"? What is the difference between "accessing the network in a domain environment" and "authenticating to a remote location [in a domain environment]"?

    Hi,
    “Virtual accounts cannot be authenticated to a remote location. All virtual accounts use the permission of machine account. Provision the machine account in the format <domain_name>\<computer_name>$.”
    “The virtual account is auto-managed, and the virtual account can access the network in a domain environment. If the default value is used for the service accounts during SQL Server setup on Windows Server 2008 R2 or Windows 7, a virtual account
    using the instance name as the service name is used, in the format NT SERVICE\<SERVICENAME>”
    Per the above description, they are two concepts and not conflict with each other.
    As you understand, virtual account access network resources by using the credentials of the computer account. Generally, computer account will not be granted permission unless giving the computer account permission on the shared folder manually.
    Thanks.
    Tracy Cai
    TechNet Community Support

  • Can one build a data warehouse using SQL rather than Warehouse Builder?

    I would like to build a data warehouse purely using SQL statements. Where can I find the data warehouse extension of SQL statements?

    I am exploring the internal workings of Warehouse Builder.
    I have written a SQL script to generate sample data to be inserted into tables, then write SQL script to do Extraction, Transformation and Loading using MERGE,, GROUP BY CUBE, DECODE, etc.
    If anyone has any experience of just using SQL to perform ETL, would you share your expeience here? Thanks.

  • Using package constant in SQL

    I am trying to use a package constant in a query as follows:
    SELECT field1 FROM table t WHERE CEIL(sysdate - t.field2) > schema.package.constant
    field1 is a name
    field2 is a timestamp
    constant is an integer indicating the expiration time in days
    basically I am trying to find all expired items.
    I get the error "ORA-06553: PLS-221: 'constant' is not a procedure or is undefined" on this query.
    I use this same query as a cursor in the package itself with no errors.

    Unfortunately you cannot directly use package global variables in select statements like this.
    One workaround is to use bind variables for that:
    <p>
    SQL> CREATE OR REPLACE PACKAGE pkg
    AS
       myconstant   VARCHAR (20) := 'This is my constant';
    END pkg;
    Package created.
    SQL> VAR myconstant  VARCHAR2 (20)
    SQL> EXEC :myconstant :=  pkg.myconstant
    PL/SQL procedure successfully completed.
    SQL> SELECT :myconstant
      FROM DUAL
    :MYCONSTANT                                                                    
    This is my constant                                                            

  • Using PDF files for items rather than .png.

    Hi there
    We have been looking into improving iBook production. We have a few books that feature elements that are comprise of a background image with text over the top. As the text isn't in an iPad-friendly font (I.e. not in iOS) and it doesn't have to be searchable. Previously, the items have been produced individually either in Illustrator or Photoshop. The main 'problem' with this is the plethora of file it creates, and the huge amount to time taken to apply style changes across all the separate items, save, re-import into iBA, and re-apply all the iBA-specific attributes.
    In an effort to speed up production somewhat, we have been trying to create these items in InDesign, using style sheets etc to give standardised appearance across all the items, and then drag and drop into iBA. The advantage is that all the separate items are in one document, and all style changes can be instantly applied to all items instantaneously, saving time, space, and effort.
    It places them as PDFs, and after unzipping the .iba file, the PDFs look fine, with pin-sharp text (as you'd expect, as PDF text would be vector data. Similarly, when you zoom in to the items in iBA, the text is still pin-sharp.
    However, once the iBA is previewed on a iPad, the text goes a little blurry. As one of the fonts is a dot-matrix-type font, the effect is noticeable - all the dots blur together into a line.
    Does anyone have any idea as to what is happening to the PDF between iBA and the iPad? Does it rasterise it at some point?

    Hi Ken
    'What leads me think it would?', well the fact that it worked, and looks ok. The iBook previews fine and works fine on the iPad.
    We initially came up with the idea when we 'unzipped' an .iba file (you know, changing the .iba extension to .zip, then unarchiving the contents), and found that iBA itself had created .pdf files for the full-screen photos which appeared rotated and shadowed on the iPad page, but were viewed as straight, unshadowed, images. (the rotated version was the iBA-created PDF file, the full-screen was the original .jpg we pulled into iBA). Naturally, we were surprised. So we started mucking about, and found that drag/drop from ID worked, and looked OK.
    As an update to my original post, it appears that the difference in quality was due to the fonts used. Once we opened the .PDFs within the .iba file, we converted the text to outlines, resaved the .pdfs, changed the unzipped folder back to an .iba file, and the font now looks great.
    BTW, Is it me, or were you being snippy?

Maybe you are looking for

  • Problems with LR4.4

    I downloaded LR 4.4 today and since then many of my catalogue previews have an exclamation mark and say "There was an error working with this photo".  What is this all about and how do I fix it?

  • Customer Account Group with Output Procedure assignment

    Hi Gurus, Is there any assignment is possible between Customer Account Group & Output Procedure? What is the function of Output procedure DB0001, I mean how its works. How in Customer Master Output box will get open. Please give details as much as po

  • Clear customer items w. special G/L ind. A ; VAT - relating

    Dear all, I have below issue: When I post incoming payment, clear customer item with Special G/L Ind. A, the system posts a document which have the same VAT used in the original special G/L customer item, but this VAT doesn't have to be posted in the

  • KM Search API for "Date" Property

    Hi, I've a problem with the following code. SearchQueryBuilder searchQueryBuilder = new SearchQueryBuilder(); Calendar c = new GregorianCalendar(); c.set(2005, 05, 30); searchProperty = new SearchPropertyFormat(); searchProperty.setName("myProp"); se

  • Calling package from java using JNDI properties

    Hi there, I have created an interface to transfer data from oracle to JMS XML Queue. It is inside a package and have generated a scenario. The scenario works well when executed from the ODI designer. When I execute it from java it throws an error. Th